From 324016494904ce3d53bbfb63a76f67e220e0685c Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 11 Dec 2018 12:09:32 +0100 Subject: 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. --- nitrocli/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'nitrocli/src/main.rs') 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 = result::Result; 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) } -- cgit v1.2.1