diff --git a/card-backend/src/lib.rs b/card-backend/src/lib.rs index dc90499..c0851a0 100644 --- a/card-backend/src/lib.rs +++ b/card-backend/src/lib.rs @@ -65,6 +65,11 @@ pub trait CardTransaction { pin: PinType, card_caps: &Option, ) -> Result, 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. diff --git a/openpgp-card/src/openpgp.rs b/openpgp-card/src/openpgp.rs index b656d4e..f2e14b7 100644 --- a/openpgp-card/src/openpgp.rs +++ b/openpgp-card/src/openpgp.rs @@ -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 }) } } diff --git a/pcsc/src/lib.rs b/pcsc/src/lib.rs index ace040a..49bac15 100644 --- a/pcsc/src/lib.rs +++ b/pcsc/src/lib.rs @@ -49,6 +49,7 @@ impl From for Box { pub struct PcscTransaction<'b> { tx: pcsc::Transaction<'b>, reader_caps: HashMap, // 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 { diff --git a/scdc/src/lib.rs b/scdc/src/lib.rs index f728213..4d9fbd0 100644 --- a/scdc/src/lib.rs +++ b/scdc/src/lib.rs @@ -309,4 +309,9 @@ impl CardTransaction for ScdTransaction<'_> { ) -> Result, SmartcardError> { unimplemented!() } + + /// Not implemented here + fn was_reset(&self) -> bool { + false + } }