card-backend: Add CardTransaction::was_reset()

This can signal to consumers that state on the card may have been reset (e.g. PIN verification state)
This commit is contained in:
Heiko Schaefer 2023-08-28 17:13:01 +02:00
parent 84ee2a64f1
commit f4cc72c37b
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D
4 changed files with 27 additions and 1 deletions

View file

@ -65,6 +65,11 @@ pub trait CardTransaction {
pin: PinType,
card_caps: &Option<CardCaps>,
) -> Result<Vec<u8>, SmartcardError>;
/// Has a reset been detected while starting this transaction?
///
/// (Backends may choose to always return false)
fn was_reset(&self) -> bool;
}
/// Information about the capabilities of a card.

View file

@ -124,6 +124,11 @@ impl OpenPgp {
let card_caps = &mut self.card_caps;
let tx = self.card.transaction(Some(OP_APP))?;
if tx.was_reset() {
// FIXME
// Signal state invalidation? (PIN verification, ...)
}
Ok(OpenPgpTransaction { tx, card_caps })
}
}

View file

@ -49,6 +49,7 @@ impl From<PcscBackend> for Box<dyn CardBackend + Sync + Send> {
pub struct PcscTransaction<'b> {
tx: pcsc::Transaction<'b>,
reader_caps: HashMap<u8, Tlv>, // FIXME: gets manually cloned
was_reset: bool,
}
impl<'b> PcscTransaction<'b> {
@ -74,11 +75,17 @@ impl<'b> PcscTransaction<'b> {
Ok(tx) => {
// A pcsc transaction has been successfully started
let mut pt = Self { tx, reader_caps };
let mut pt = Self {
tx,
reader_caps,
was_reset: false,
};
if was_reset {
log::trace!("Card was reset");
pt.was_reset = true;
// If the caller expects that an application on the
// card has been selected, re-select the application
// here.
@ -401,6 +408,10 @@ impl CardTransaction for PcscTransaction<'_> {
Ok(res.to_vec())
}
fn was_reset(&self) -> bool {
self.was_reset
}
}
impl PcscBackend {

View file

@ -309,4 +309,9 @@ impl CardTransaction for ScdTransaction<'_> {
) -> Result<Vec<u8>, SmartcardError> {
unimplemented!()
}
/// Not implemented here
fn was_reset(&self) -> bool {
false
}
}