From fcdd2a2d3db5dd5d833ae4fd710d8b64f5b056cf Mon Sep 17 00:00:00 2001 From: shimun Date: Wed, 29 Apr 2020 18:55:25 +0200 Subject: [PATCH] add option to specify keyslot --- src/cli.rs | 5 ++++- src/luks.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 40ba728..98bb020 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -76,6 +76,9 @@ pub struct AuthenticatorParameters { pub struct LuksParameters { #[structopt(env = "FIDO2LUKS_DEVICE")] device: PathBuf, + + #[structopt(long = "slot", env = "FIDO2LUKS_DEVICE_SLOT")] + slot_hint: Option, } #[derive(Debug, StructOpt, Clone)] @@ -461,7 +464,7 @@ pub fn run_cli() -> Fido2LuksResult<()> { &salt("Password", false)?, authenticator.await_time, ) - .and_then(|secret| luks::open_container(&luks.device, &name, &secret)) + .and_then(|secret| luks::open_container(&luks.device, &name, &secret, luks.slot_hint)) { Err(e) => { match e { diff --git a/src/luks.rs b/src/luks.rs index 2b1f7ac..c767d4f 100644 --- a/src/luks.rs +++ b/src/luks.rs @@ -18,11 +18,11 @@ fn load_device_handle>(path: P) -> Fido2LuksResult { Ok(device) } -pub fn open_container>(path: P, name: &str, secret: &[u8]) -> Fido2LuksResult<()> { +pub fn open_container>(path: P, name: &str, secret: &[u8], slot_hint: Option) -> Fido2LuksResult<()> { let mut device = load_device_handle(path)?; device .activate_handle() - .activate_by_passphrase(Some(name), None, secret, CryptActivateFlags::empty()) + .activate_by_passphrase(Some(name), slot_hint, secret, CryptActivateFlags::empty()) .map(|_slot| ()) .map_err(|_e| Fido2LuksError::WrongSecret) }