diff options
| -rw-r--r-- | nitrocli/src/main.rs | 5 | ||||
| -rw-r--r-- | nitrocli/src/pinentry.rs | 8 | 
2 files changed, 8 insertions, 5 deletions
| diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs index 3ec3243..0ba232f 100644 --- a/nitrocli/src/main.rs +++ b/nitrocli/src/main.rs @@ -253,8 +253,9 @@ fn open() -> Result<()> {    nitrokey_do(&|handle| {      let mut retry = 3; +    let mut error_msg: Option<&str> = None;      loop { -      let passphrase = pinentry::inquire_passphrase()?; +      let passphrase = pinentry::inquire_passphrase(error_msg)?;        let payload = nitrokey::EnableEncryptedVolumeCommand::new(&passphrase);        let report = nitrokey::Report::from(payload); @@ -267,7 +268,7 @@ fn open() -> Result<()> {          retry -= 1;          if retry > 0 { -          println!("Wrong password, please reenter"); +          error_msg = Some("Wrong password, please reenter");            continue;          }          let error = "Opening encrypted volume failed: Wrong password"; diff --git a/nitrocli/src/pinentry.rs b/nitrocli/src/pinentry.rs index 028550f..6cf3093 100644 --- a/nitrocli/src/pinentry.rs +++ b/nitrocli/src/pinentry.rs @@ -49,12 +49,14 @@ fn parse_pinentry_passphrase(response: Vec<u8>) -> Result<Vec<u8>, Error> {  } -pub fn inquire_passphrase() -> Result<Vec<u8>, Error> { -  const PINENTRY_ERROR_MSG: &str = "+"; +pub fn inquire_passphrase(error_msg: Option<&str>) -> Result<Vec<u8>, Error> { +  const PINENTRY_ERROR_MSG_EMPTY: &str = "+";    const PINENTRY_PROMPT: &str = "PIN";    const PINENTRY_DESCR: &str = "Please+enter+user+PIN"; -  let args = vec![CACHE_ID, PINENTRY_ERROR_MSG, PINENTRY_PROMPT, PINENTRY_DESCR].join(" "); +  let error_msg = error_msg.map(|msg| msg.replace(" ", "+")) +    .unwrap_or(PINENTRY_ERROR_MSG_EMPTY.to_string()); +  let args = vec![CACHE_ID, &error_msg, PINENTRY_PROMPT, PINENTRY_DESCR].join(" ");    let command = "GET_PASSPHRASE --data ".to_string() + &args;    // We could also use the --data parameter here to have a more direct    // representation of the passphrase but the resulting response was | 
