Skip to content

Commit

Permalink
Clear cached PIN entry as part of pin set command
Browse files Browse the repository at this point in the history
When a PIN is changed using the pin set command, the last action is to
confirm the operation with the previously used PIN. This step will cause
this PIN, which is now stale and no longer valid, to be cached, which in
turn can cause follow up command using the same PIN type to use this
wrong cached entry for authentication.
To fix this problem, this change explicitly clear the PIN entry from the
cache after the PIN has been changed.
  • Loading branch information
d-e-s-o committed Jun 1, 2019
1 parent a57449d commit 7c88069
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions nitrocli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Unreleased
- Check the status of a PWS slot before accessing it in `pws get`
- Added `NITROCLI_NO_CACHE` environment variable to bypass caching of
secrets
- Clear cached PIN entry as part of `pin set` command to prevent
spurious authentication failures
- Bumped `libc` dependency to `0.2.55`
- Bumped `cc` dependency to `1.0.37`

Expand Down
7 changes: 6 additions & 1 deletion nitrocli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,12 @@ pub fn pin_set(ctx: &mut args::ExecCtx<'_>, pin_type: pinentry::PinType) -> Resu
pinentry::PinType::Admin => device.change_admin_pin(&current_pin, &new_pin),
pinentry::PinType::User => device.change_user_pin(&current_pin, &new_pin),
},
)
)?;

// We just changed the PIN but confirmed the action with the old PIN,
// which may have caused it to be cached. Since it no longer applies,
// make sure to evict the corresponding entry from the cache.
pinentry::clear(&pin_entry)
}

/// Unblock and reset the user PIN.
Expand Down
2 changes: 1 addition & 1 deletion nitrocli/src/tests/otp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn status(device: nitrokey::DeviceWrapper) -> crate::Result<()> {

let mut ncli = Nitrocli::with_dev(device);
// Make sure that we have at least something to display by ensuring
// that there are there is one slot programmed.
// that there is one slot programmed.
let _ = ncli.handle(&["otp", "set", "0", "the-name", "123456"])?;

let out = ncli.handle(&["otp", "status"])?;
Expand Down

0 comments on commit 7c88069

Please sign in to comment.