openpgp-card-sequoia: adjust to card-backend refactor
Note that a `open_by_ident` fn was added here: the backend now doesn't have knowledge of applications (like OpenPGP) anymore, so it can't select a card by OpenPGP card ident anymore.
This commit is contained in:
parent
4fda5d800a
commit
15646bc50b
3 changed files with 54 additions and 34 deletions
|
@ -5,13 +5,14 @@
|
||||||
name = "openpgp-card-sequoia"
|
name = "openpgp-card-sequoia"
|
||||||
description = "Wrapper of openpgp-card for use with Sequoia PGP"
|
description = "Wrapper of openpgp-card for use with Sequoia PGP"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
version = "0.1.5"
|
version = "0.2.0-pre"
|
||||||
authors = ["Heiko Schaefer <heiko@schaefer.name>"]
|
authors = ["Heiko Schaefer <heiko@schaefer.name>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
repository = "https://gitlab.com/openpgp-card/openpgp-card"
|
repository = "https://gitlab.com/openpgp-card/openpgp-card"
|
||||||
documentation = "https://docs.rs/crate/openpgp-card-sequoia"
|
documentation = "https://docs.rs/crate/openpgp-card-sequoia"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
card-backend = { path = "../card-backend", version = "0.1" }
|
||||||
sequoia-openpgp = { version = "1.4", default-features = false }
|
sequoia-openpgp = { version = "1.4", default-features = false }
|
||||||
openpgp-card = { path = "../openpgp-card", version = "0.4" }
|
openpgp-card = { path = "../openpgp-card", version = "0.4" }
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
@ -21,8 +22,8 @@ log = "0.4"
|
||||||
rsa = "0.8.1"
|
rsa = "0.8.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
openpgp-card-pcsc = { path = "../pcsc", version = "0.3" }
|
card-backend-pcsc = { path = "../pcsc", version = "0.4" }
|
||||||
#openpgp-card-scdc = { path = "../scdc", version = "0.3" }
|
#card-backend-scdc = { path = "../scdc", version = "0.4" }
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
testresult = "0.3.0"
|
testresult = "0.3.0"
|
||||||
|
|
||||||
|
|
|
@ -16,17 +16,17 @@
|
||||||
//! # Backends
|
//! # Backends
|
||||||
//!
|
//!
|
||||||
//! To make use of this crate, you need to use a backend for communication
|
//! To make use of this crate, you need to use a backend for communication
|
||||||
//! with cards. The suggested default backend is `openpgp-card-pcsc`.
|
//! with cards. The suggested default backend is `card-backend-pcsc`.
|
||||||
//!
|
//!
|
||||||
//! With `openpgp-card-pcsc` you can either open all available cards:
|
//! With `card-backend-pcsc` you can either open all available cards:
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use openpgp_card_pcsc::PcscBackend;
|
//! use card_backend_pcsc::PcscBackend;
|
||||||
//! use openpgp_card_sequoia::{state::Open, Card};
|
//! use openpgp_card_sequoia::{state::Open, Card};
|
||||||
//!
|
//!
|
||||||
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//! for backend in PcscBackend::cards(None)? {
|
//! for backend in PcscBackend::cards(None)? {
|
||||||
//! let mut card: Card<Open> = backend.into();
|
//! let mut card = Card::<Open>::new(backend?)?;
|
||||||
//! let mut transaction = card.transaction()?;
|
//! let mut transaction = card.transaction()?;
|
||||||
//! println!(
|
//! println!(
|
||||||
//! "Found OpenPGP card with ident '{}'",
|
//! "Found OpenPGP card with ident '{}'",
|
||||||
|
@ -40,12 +40,12 @@
|
||||||
//! Or you can open one particular card, by ident:
|
//! Or you can open one particular card, by ident:
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use openpgp_card_pcsc::PcscBackend;
|
//! use card_backend_pcsc::PcscBackend;
|
||||||
//! use openpgp_card_sequoia::{state::Open, Card};
|
//! use openpgp_card_sequoia::{state::Open, Card};
|
||||||
//!
|
//!
|
||||||
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//! let backend = PcscBackend::open_by_ident("abcd:01234567", None)?;
|
//! let cards = PcscBackend::card_backends(None)?;
|
||||||
//! let mut card: Card<Open> = backend.into();
|
//! let mut card = Card::<Open>::open_by_ident(cards, "abcd:01234567")?;
|
||||||
//! let mut transaction = card.transaction()?;
|
//! let mut transaction = card.transaction()?;
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
|
@ -60,13 +60,13 @@
|
||||||
//! implementation can then be obtained:
|
//! implementation can then be obtained:
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use openpgp_card_pcsc::PcscBackend;
|
//! use card_backend_pcsc::PcscBackend;
|
||||||
//! use openpgp_card_sequoia::{state::Open, Card};
|
//! use openpgp_card_sequoia::{state::Open, Card};
|
||||||
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//! // Open card via PCSC
|
//! // Open card via PCSC
|
||||||
//! use sequoia_openpgp::policy::StandardPolicy;
|
//! use sequoia_openpgp::policy::StandardPolicy;
|
||||||
//! let backend = PcscBackend::open_by_ident("abcd:01234567", None)?;
|
//! let cards = PcscBackend::card_backends(None)?;
|
||||||
//! let mut card: Card<Open> = backend.into();
|
//! let mut card = Card::<Open>::open_by_ident(cards, "abcd:01234567")?;
|
||||||
//! let mut transaction = card.transaction()?;
|
//! let mut transaction = card.transaction()?;
|
||||||
//!
|
//!
|
||||||
//! // Get authorization for user access to the card with password
|
//! // Get authorization for user access to the card with password
|
||||||
|
@ -95,13 +95,13 @@
|
||||||
//! user password before each signing operation!)
|
//! user password before each signing operation!)
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use openpgp_card_pcsc::PcscBackend;
|
//! use card_backend_pcsc::PcscBackend;
|
||||||
//! use openpgp_card_sequoia::{state::Open, Card};
|
//! use openpgp_card_sequoia::{state::Open, Card};
|
||||||
//!
|
//!
|
||||||
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//! // Open card via PCSC
|
//! // Open card via PCSC
|
||||||
//! let backend = PcscBackend::open_by_ident("abcd:01234567", None)?;
|
//! let cards = PcscBackend::card_backends(None)?;
|
||||||
//! let mut card: Card<Open> = backend.into();
|
//! let mut card = Card::<Open>::open_by_ident(cards, "abcd:01234567")?;
|
||||||
//! let mut transaction = card.transaction()?;
|
//! let mut transaction = card.transaction()?;
|
||||||
//!
|
//!
|
||||||
//! // Get authorization for signing access to the card with password
|
//! // Get authorization for signing access to the card with password
|
||||||
|
@ -121,13 +121,13 @@
|
||||||
//! # Setting up and configuring a card
|
//! # Setting up and configuring a card
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use openpgp_card_pcsc::PcscBackend;
|
//! use card_backend_pcsc::PcscBackend;
|
||||||
//! use openpgp_card_sequoia::{state::Open, Card};
|
//! use openpgp_card_sequoia::{state::Open, Card};
|
||||||
//!
|
//!
|
||||||
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//! // Open card via PCSC
|
//! // Open card via PCSC
|
||||||
//! let backend = PcscBackend::open_by_ident("abcd:01234567", None)?;
|
//! let cards = PcscBackend::card_backends(None)?;
|
||||||
//! let mut card: Card<Open> = backend.into();
|
//! let mut card = Card::<Open>::open_by_ident(cards, "abcd:01234567")?;
|
||||||
//! let mut transaction = card.transaction()?;
|
//! let mut transaction = card.transaction()?;
|
||||||
//!
|
//!
|
||||||
//! // Get authorization for admin access to the card with password
|
//! // Get authorization for admin access to the card with password
|
||||||
|
@ -142,6 +142,7 @@
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
use card_backend::{CardBackend, SmartcardError};
|
||||||
use openpgp_card::algorithm::{Algo, AlgoInfo, AlgoSimple};
|
use openpgp_card::algorithm::{Algo, AlgoInfo, AlgoSimple};
|
||||||
use openpgp_card::card_do::{
|
use openpgp_card::card_do::{
|
||||||
ApplicationIdentifier, CardholderRelatedData, ExtendedCapabilities, ExtendedLengthInfo,
|
ApplicationIdentifier, CardholderRelatedData, ExtendedCapabilities, ExtendedLengthInfo,
|
||||||
|
@ -149,7 +150,7 @@ use openpgp_card::card_do::{
|
||||||
SecuritySupportTemplate, Sex, TouchPolicy, UIF,
|
SecuritySupportTemplate, Sex, TouchPolicy, UIF,
|
||||||
};
|
};
|
||||||
use openpgp_card::crypto_data::PublicKeyMaterial;
|
use openpgp_card::crypto_data::PublicKeyMaterial;
|
||||||
use openpgp_card::{CardBackend, Error, KeySet, KeyType, OpenPgp, OpenPgpTransaction};
|
use openpgp_card::{Error, KeySet, KeyType, OpenPgp, OpenPgpTransaction};
|
||||||
use sequoia_openpgp::cert::prelude::ValidErasedKeyAmalgamation;
|
use sequoia_openpgp::cert::prelude::ValidErasedKeyAmalgamation;
|
||||||
use sequoia_openpgp::packet::key::SecretParts;
|
use sequoia_openpgp::packet::key::SecretParts;
|
||||||
use sequoia_openpgp::packet::{key, Key};
|
use sequoia_openpgp::packet::{key, Key};
|
||||||
|
@ -188,20 +189,38 @@ where
|
||||||
state: S,
|
state: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B> From<B> for Card<Open>
|
|
||||||
where
|
|
||||||
B: Into<Box<dyn CardBackend + Send + Sync>>,
|
|
||||||
{
|
|
||||||
fn from(backend: B) -> Self {
|
|
||||||
let pgp = OpenPgp::new(backend.into());
|
|
||||||
|
|
||||||
Card::<Open> {
|
|
||||||
state: Open { pgp },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Card<Open> {
|
impl Card<Open> {
|
||||||
|
pub fn open_by_ident(
|
||||||
|
cards: impl Iterator<Item = Result<Box<dyn CardBackend + Send + Sync>, SmartcardError>>,
|
||||||
|
ident: &str,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
for b in cards.filter_map(|c| c.ok()) {
|
||||||
|
let mut card = Self::new(b)?;
|
||||||
|
|
||||||
|
let aid = {
|
||||||
|
let tx = card.transaction()?;
|
||||||
|
tx.state.ard.application_id()?
|
||||||
|
};
|
||||||
|
|
||||||
|
if aid.ident() == ident.to_ascii_uppercase() {
|
||||||
|
return Ok(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(Error::NotFound(format!("Couldn't find card {}", ident)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new<B>(backend: B) -> Result<Self, Error>
|
||||||
|
where
|
||||||
|
B: Into<Box<dyn CardBackend + Send + Sync>>,
|
||||||
|
{
|
||||||
|
let pgp = OpenPgp::new(backend)?;
|
||||||
|
|
||||||
|
Ok(Card::<Open> {
|
||||||
|
state: Open { pgp },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn transaction(&mut self) -> Result<Card<Transaction>, Error> {
|
pub fn transaction(&mut self) -> Result<Card<Transaction>, Error> {
|
||||||
let opt = self.state.pgp.transaction()?;
|
let opt = self.state.pgp.transaction()?;
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,4 @@
|
||||||
pub use openpgp_card::algorithm::{Algo, AlgoSimple, Curve};
|
pub use openpgp_card::algorithm::{Algo, AlgoSimple, Curve};
|
||||||
pub use openpgp_card::card_do::{Sex, TouchPolicy};
|
pub use openpgp_card::card_do::{Sex, TouchPolicy};
|
||||||
pub use openpgp_card::crypto_data::{EccType, PublicKeyMaterial};
|
pub use openpgp_card::crypto_data::{EccType, PublicKeyMaterial};
|
||||||
pub use openpgp_card::{CardBackend, Error, KeyType, StatusBytes};
|
pub use openpgp_card::{Error, KeyType, StatusBytes};
|
||||||
|
|
Loading…
Reference in a new issue