3 Commits
0.2.4 ... 0.2.5

Author SHA1 Message Date
27211f8b7e update deps
Some checks failed
continuous-integration/drone/tag Build is failing
2020-04-05 18:23:26 +02:00
96f64fff11 always check timeout condition
Some checks reported errors
continuous-integration/drone/push Build was killed
2020-04-04 15:33:18 +02:00
70d66f6a74 added debug flag
Some checks failed
continuous-integration/drone/tag Build is failing
2020-04-04 15:26:49 +02:00
4 changed files with 128 additions and 7 deletions

View File

@@ -6,14 +6,14 @@ steps:
image: rust:1.41.0 image: rust:1.41.0
commands: commands:
- apt update && apt install -y libpam-dev - apt update && apt install -y libpam-dev
- cargo test --release - cargo test --debug
- name: build_relase - name: build_relase
image: rust:1.41.0 image: rust:1.41.0
commands: commands:
- apt update && apt install -y libpam-dev - apt update && apt install -y libpam-dev
- cargo build --release - cargo build --debug
- mkdir -p bin lib - mkdir -p bin lib
- bash -c 'cp $${CARGO_TARGET_DIR:-target}/release/pam_fido2-cli bin/; cp $${CARGO_TARGET_DIR:-target}/release/libpam_fido2.so lib/' - bash -c 'cp $${CARGO_TARGET_DIR:-target}/debug/pam_fido2-cli bin/; cp $${CARGO_TARGET_DIR:-target}/debug/libpam_fido2.so lib/'
- strip bin/* - strip bin/*
- tar cvzf pam_fido2.tar.gz bin lib src Cargo.* - tar cvzf pam_fido2.tar.gz bin lib src Cargo.*
when: when:

6
Cargo.lock generated
View File

@@ -191,7 +191,7 @@ dependencies = [
[[package]] [[package]]
name = "ctap_hmac" name = "ctap_hmac"
version = "0.4.0" version = "0.4.0"
source = "git+https://git.shimun.net/shimun/ctap?rev=cc48719cfa1375909877265905264fad875d1fa3#cc48719cfa1375909877265905264fad875d1fa3" source = "git+https://git.shimun.net/shimun/ctap?rev=0.4.0#cc48719cfa1375909877265905264fad875d1fa3"
dependencies = [ dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cbor-codec 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "cbor-codec 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -405,7 +405,7 @@ dependencies = [
name = "pam_fido2" name = "pam_fido2"
version = "0.2.4" version = "0.2.4"
dependencies = [ dependencies = [
"ctap_hmac 0.4.0 (git+https://git.shimun.net/shimun/ctap?rev=cc48719cfa1375909877265905264fad875d1fa3)", "ctap_hmac 0.4.0 (git+https://git.shimun.net/shimun/ctap?rev=0.4.0)",
"ctrlc 3.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "ctrlc 3.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -888,7 +888,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" "checksum crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db"
"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" "checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
"checksum csv-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" "checksum csv-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
"checksum ctap_hmac 0.4.0 (git+https://git.shimun.net/shimun/ctap?rev=cc48719cfa1375909877265905264fad875d1fa3)" = "<none>" "checksum ctap_hmac 0.4.0 (git+https://git.shimun.net/shimun/ctap?rev=0.4.0)" = "<none>"
"checksum ctrlc 3.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7a4ba686dff9fa4c1c9636ce1010b0cf98ceb421361b0bb3d6faeec43bd217a7" "checksum ctrlc 3.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7a4ba686dff9fa4c1c9636ce1010b0cf98ceb421361b0bb3d6faeec43bd217a7"
"checksum darling 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" "checksum darling 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858"
"checksum darling_core 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" "checksum darling_core 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b"

View File

@@ -19,7 +19,7 @@ path = "src/main.rs"
opt-level = 0 opt-level = 0
[dependencies] [dependencies]
ctap_hmac = { git = "https://git.shimun.net/shimun/ctap", rev = "cc48719cfa1375909877265905264fad875d1fa3", features = ["request_multiple"] } ctap_hmac = { git = "https://git.shimun.net/shimun/ctap", rev = "0.4.0", features = ["request_multiple"] }
pamsm = { version = "0.3.3", features = ["libpam"] } pamsm = { version = "0.3.3", features = ["libpam"] }
regex = "1.3.1" regex = "1.3.1"
rand = "0.7.2" rand = "0.7.2"

121
src/.lib.rs.rustfmt Normal file
View File

@@ -0,0 +1,121 @@
#[macro_use]
extern crate pamsm;
extern crate ctap_hmac as ctap;
use pamsm::{Pam, PamError, PamFlag, PamServiceModule};
use rand::Rng;
use regex::Regex;
use std::fs::File;
use std::io::{self, prelude::*, BufReader};
use std::time::{Duration, SystemTime};
struct PamFido2;
struct Settings {
pub device_timeout: Duration,
pub user_credentials: Vec<(String, String)>,
}
impl Default for Settings {
fn default() -> Self {
Settings {
device_timeout: Duration::from_secs(15),
user_credentials: vec![("091566e43802c5a29971c1e08d7865d959af862cc28af22dacf413ac26b90f6dea7d1ac491d9d3712c63f7b8d6cfadf86d057d099d382246dbe9c87f133ed167881b65030000".into(),".*".into())],
}
}
}
impl Settings {
/*pub fn load(file: impl Read) -> io::Result<Settings> {
}*/
pub fn load() -> Settings {
let mut creds = Vec::new();
for path in &["/etc/pam_fido2.conf"] {
let file = match File::open(&path) {
Ok(file) => file,
_ => continue,
};
let reader = BufReader::new(file);
for line in reader.lines() {
let line = line.unwrap();
let mut parts = line.split(":");
let user = parts.by_ref().next().unwrap();
creds.push((
(&parts.collect::<Vec<_>>()[..].join(":")).to_string(),
user.to_string(),
));
}
}
Settings {
user_credentials: creds,
..Default::default()
}
}
pub fn get_credential(&self, user: &str) -> Option<ctap::FidoCredential> {
for (cred, pattern) in self.user_credentials.iter() {
let re = Regex::new(&pattern).expect(&["Invalid regex pattern:", &pattern].join(" "));
if re.is_match(user) {
let mut parts = cred.split(":");
//TODO: use expect
let id = parts.by_ref().next().unwrap();
let key = parts.by_ref().next().unwrap();
return Some(ctap::FidoCredential {
id: hex::decode(id).unwrap(),
public_key: hex::decode(key).unwrap(),
rp_id: "pam".into(),
});
}
}
None
}
}
impl PamFido2 {
fn settings(&self) -> Settings {
Settings::load()
}
}
impl PamServiceModule for PamFido2 {
fn authenticate(self: &Self, pamh: Pam, _: PamFlag, _args: Vec<String>) -> PamError {
let settings = self.settings();
let begin = SystemTime::now();
let mut device = loop {
if let Ok(mut devices) = ctap::get_devices() {
if let Some(dev) = devices.next() {
break ctap::FidoDevice::new(&dev).unwrap();
}
}
if begin.elapsed().unwrap() > settings.device_timeout {
return PamError::AUTH_ERR;
}
};
let challenge = rand::thread_rng().gen::<[u8; 32]>();
let credential = match settings
.get_credential(
&pamh
.get_cached_user()
.ok()
.map(|name| name.unwrap().to_str().unwrap().to_string())
.expect("Faied to get username"),
) { Some(cred) => cred, _ => return PamError::CRED_UNAVAIL };
match device.get_assertion(&credential, &challenge) {
Ok(true) => PamError::SUCCESS,
_ => PamError::AUTH_ERR,
}
}
}
pamsm_init!(Box::new(PamFido2));
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}