diff options
author | Robin Krahl <me@robin-krahl.de> | 2018-12-11 12:09:32 +0100 |
---|---|---|
committer | Daniel Müller <d-e-s-o@users.noreply.github.com> | 2018-12-11 17:34:18 -0800 |
commit | 324016494904ce3d53bbfb63a76f67e220e0685c (patch) | |
tree | 8af8d53a97dc9439834de9322ddbbdbe6a071bbc /nitrocli/src/main.rs | |
parent | c67ecea7e22b890a3014a884585d801a2fcc3293 (diff) | |
download | nitrocli-324016494904ce3d53bbfb63a76f67e220e0685c.tar.gz nitrocli-324016494904ce3d53bbfb63a76f67e220e0685c.tar.bz2 |
Add support for multiple PIN types
Currently, the pinentry module only supports querying the user PIN. The
Nitrokey devices also have an admin PIN. This patch adds support for
querying multiple PIN types to the pinentry module. While this is
currently not used, it will be needed to add support for administrative
commands like unlocking the device or changeing the user PIN.
Diffstat (limited to 'nitrocli/src/main.rs')
-rw-r--r-- | nitrocli/src/main.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs index 0ba232f..ebc0589 100644 --- a/nitrocli/src/main.rs +++ b/nitrocli/src/main.rs @@ -42,6 +42,7 @@ type Result<T> = result::Result<T, Error>; type NitroFunc = Fn(&mut libhid::Handle) -> Result<()>; +const PIN_TYPE: pinentry::PinType = pinentry::PinType::User; const SEND_TRY_COUNT: i8 = 3; const RECV_TRY_COUNT: i8 = 40; const SEND_RECV_DELAY_MS: u64 = 200; @@ -255,7 +256,7 @@ fn open() -> Result<()> { let mut retry = 3; let mut error_msg: Option<&str> = None; loop { - let passphrase = pinentry::inquire_passphrase(error_msg)?; + let passphrase = pinentry::inquire_passphrase(PIN_TYPE, error_msg)?; let payload = nitrokey::EnableEncryptedVolumeCommand::new(&passphrase); let report = nitrokey::Report::from(payload); @@ -264,7 +265,7 @@ fn open() -> Result<()> { let mut status = response.data.storage_status; if status == nitrokey::StorageStatus::WrongPassword { - pinentry::clear_passphrase()?; + pinentry::clear_passphrase(PIN_TYPE)?; retry -= 1; if retry > 0 { @@ -328,7 +329,7 @@ fn close() -> Result<()> { /// Clear the PIN stored when opening the nitrokey's encrypted volume. fn clear() -> Result<()> { - pinentry::clear_passphrase() + pinentry::clear_passphrase(PIN_TYPE) } |