Disconnect without resetting YubiKeys if it is safe to do so
This enables the PIN caches to be preserved across age-plugin-yubikey processes, allowing PIN policies of "once" to become meaningful.
This commit is contained in:
+24
@@ -236,6 +236,23 @@ pub(crate) fn open(serial: Option<Serial>) -> Result<YubiKey, Error> {
|
||||
Ok(yubikey)
|
||||
}
|
||||
|
||||
/// Disconnect from the YubiKey without resetting it.
|
||||
///
|
||||
/// This can be used to preserve the YubiKey's PIN and touch caches. There are two cases
|
||||
/// where we want to do this:
|
||||
///
|
||||
/// - We connected to this YubiKey in a read-only context, so we have not made any changes
|
||||
/// to the YubiKey's state. However, we might have asked an agent to release the YubiKey
|
||||
/// in `key::open_connection`, and we want to allow any state it may have left behind
|
||||
/// (such as cached PINs or touches) to persist beyond our execution, for usability.
|
||||
/// - We opened this connection in a decryption context, so the only changes to the
|
||||
/// YubiKey's state were to potentially cache the PIN and/or touch (depending on the
|
||||
/// policies of the slot). We want to allow these to persist beyond our execution, for
|
||||
/// usability.
|
||||
pub(crate) fn disconnect_without_reset(yubikey: YubiKey) {
|
||||
let _ = yubikey.disconnect(pcsc::Disposition::LeaveCard);
|
||||
}
|
||||
|
||||
pub(crate) fn manage(yubikey: &mut YubiKey) -> Result<(), Error> {
|
||||
const DEFAULT_PIN: &str = "123456";
|
||||
const DEFAULT_PUK: &str = "12345678";
|
||||
@@ -674,6 +691,13 @@ impl Connection {
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Close this connection without resetting the YubiKey.
|
||||
///
|
||||
/// This can be used to preserve the YubiKey's PIN and touch caches.
|
||||
pub(crate) fn disconnect_without_reset(self) {
|
||||
disconnect_without_reset(self.yubikey);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user