Skip to content

Commit

Permalink
Fix cache ID for pinentry calls
Browse files Browse the repository at this point in the history
Since nitrokey-rs v0.8.0 added support for the Librem Key, the Display
implementation for nitrokey::Model may include a space, for example
"Nitrokey Pro" (instead of "Pro"). I missed that we used this string
representation to generate the pinentry cache ID, leading to an
additional space in the GnuPG GET_PASSPHRASE call. This messed up the
error message, prompt and description arguments that come after the
cache ID.

With this patch, we use a hard-coded string for the cache IDs instead of
nitrokey::Model's Display implementation.
  • Loading branch information
robinkrahl authored and d-e-s-o committed Apr 11, 2021
1 parent 3a12546 commit 537d29a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Unreleased
----------
- Enabled usage of empty PWS slot fields
- Allowed entering of `base32` encoded strings containing spaces
- Fixed pinentry dialog highlighting some messages incorrectly as errors
- Bumped `nitrokey` dependency to `0.9.0`


Expand Down
11 changes: 8 additions & 3 deletions src/pinentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ impl PinEntry {

impl SecretEntry for PinEntry {
fn cache_id(&self) -> Option<CowStr> {
let model = self.model.to_string().to_lowercase();
let model = match self.model {
nitrokey::Model::Librem => "librem",
nitrokey::Model::Pro => "pro",
nitrokey::Model::Storage => "storage",
_ => "unknown",
};
let suffix = format!("{}:{}", model, self.serial);
let cache_id = match self.pin_type {
args::PinType::Admin => format!("nitrocli:admin:{}", suffix),
Expand All @@ -77,7 +82,7 @@ impl SecretEntry for PinEntry {

fn description(&self, mode: Mode) -> CowStr {
format!(
"{} for\r {} {}",
"{} for\r{} {}",
match self.pin_type {
args::PinType::Admin => match mode {
Mode::Choose => "Please enter a new admin PIN",
Expand Down Expand Up @@ -135,7 +140,7 @@ impl SecretEntry for PwdEntry {

fn description(&self, mode: Mode) -> CowStr {
format!(
"{} for\r {} {}",
"{} for\r{} {}",
match mode {
Mode::Choose => "Please enter a new hidden volume password",
Mode::Confirm => "Please confirm the new hidden volume password",
Expand Down

0 comments on commit 537d29a

Please sign in to comment.