diff --git a/tools/Cargo.toml b/tools/Cargo.toml index 1af20a2..2253711 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -16,6 +16,7 @@ sequoia-openpgp = "1.3" nettle = "7" openpgp-card = { path = "../openpgp-card", version = "0.1" } openpgp-card-pcsc = { path = "../pcsc", version = "0.1" } +pcsc = "2" openpgp-card-sequoia = { path = "../openpgp-card-sequoia", version = "0.0.7" } rpassword = "5" chrono = "0.4" diff --git a/tools/src/bin/opgpcard-pin/main.rs b/tools/src/bin/opgpcard-pin/main.rs index acd2393..a1177c4 100644 --- a/tools/src/bin/opgpcard-pin/main.rs +++ b/tools/src/bin/opgpcard-pin/main.rs @@ -5,7 +5,7 @@ use anyhow::Result; use structopt::StructOpt; use openpgp_card::{CardClient, Error, StatusBytes}; -use openpgp_card_pcsc::PcscCard; +use openpgp_card_pcsc::{get_txc, PcscCard, TxClient}; use openpgp_card_sequoia::card::Open; mod cli; @@ -16,10 +16,12 @@ fn main() -> Result<(), Box> { let cli = cli::Cli::from_args(); let mut card = PcscCard::open_by_ident(&cli.ident)?; - let pinpad_verify = card.feature_pinpad_verify(); - let pinpad_modify = card.feature_pinpad_modify(); + let mut txc = get_txc!(card, true)?; - let mut open = Open::new(&mut card)?; + let pinpad_verify = txc.feature_pinpad_verify(); + let pinpad_modify = txc.feature_pinpad_modify(); + + let mut open = Open::new(&mut txc)?; match cli.cmd { cli::Command::SetUserPin {} => { diff --git a/tools/src/bin/opgpcard/main.rs b/tools/src/bin/opgpcard/main.rs index 8318a8f..58d4751 100644 --- a/tools/src/bin/opgpcard/main.rs +++ b/tools/src/bin/opgpcard/main.rs @@ -12,7 +12,8 @@ use sequoia_openpgp::serialize::SerializeInto; use sequoia_openpgp::Cert; use openpgp_card::algorithm::AlgoSimple; -use openpgp_card::{card_do::Sex, CardApp, CardClient, KeyType}; +use openpgp_card::{card_do::Sex, CardClient, KeyType}; +use openpgp_card_pcsc::{get_txc, TxClient}; use openpgp_card_sequoia::card::{Admin, Open}; use openpgp_card_sequoia::util::{make_cert, public_key_material_to_key}; @@ -71,7 +72,9 @@ fn main() -> Result<(), Box> { cmd, } => { let mut card = util::open_card(&ident)?; - let mut open = Open::new(&mut card)?; + let mut txc = get_txc!(card, true)?; + + let mut open = Open::new(&mut txc)?; match cmd { cli::AdminCommand::Name { name } => { @@ -136,7 +139,9 @@ fn list_cards() -> Result<()> { println!("Available OpenPGP cards:"); for mut card in cards { - let open = Open::new(&mut card)?; + let mut txc = get_txc!(card, true)?; + + let open = Open::new(&mut txc)?; println!(" {}", open.application_identifier()?.ident()); } } else { @@ -150,14 +155,15 @@ fn set_identity( id: u8, ) -> Result<(), Box> { let mut card = util::open_card(ident)?; + let mut txc = get_txc!(card, true)?; - ::set_identity(&mut card, id)?; + ::set_identity(&mut txc, id)?; Ok(()) } fn print_status(ident: Option, verbose: bool) -> Result<()> { - let mut ca = if let Some(ident) = ident { + let mut card = if let Some(ident) = ident { util::open_card(&ident)? } else { let mut cards = util::cards()?; @@ -167,7 +173,10 @@ fn print_status(ident: Option, verbose: bool) -> Result<()> { return Err(anyhow::anyhow!("Found {} cards", cards.len())); } }; - let mut open = Open::new(&mut ca)?; + + let mut txc = get_txc!(card, true)?; + + let mut open = Open::new(&mut txc)?; print!("OpenPGP card {}", open.application_identifier()?.ident()); @@ -319,7 +328,9 @@ fn decrypt( let input = util::open_or_stdin(input.as_deref())?; let mut card = util::open_card(ident)?; - let mut open = Open::new(&mut card)?; + let mut txc = get_txc!(card, true)?; + + let mut open = Open::new(&mut txc)?; let mut user = util::verify_to_user(&mut open, pin_file)?; let d = user.decryptor(&cert)?; @@ -343,7 +354,9 @@ fn sign_detached( let mut input = util::open_or_stdin(input.as_deref())?; let mut card = util::open_card(ident)?; - let mut open = Open::new(&mut card)?; + let mut txc = get_txc!(card, true)?; + + let mut open = Open::new(&mut txc)?; let mut sign = util::verify_to_sign(&mut open, pin_file)?; let s = sign.signer(&cert)?; @@ -360,7 +373,9 @@ fn sign_detached( fn factory_reset(ident: &str) -> Result<()> { println!("Resetting Card {}", ident); let mut card = util::open_card(ident)?; - Open::new(&mut card)?.factory_reset() + let mut txc = get_txc!(card, true)?; + + Open::new(&mut txc)?.factory_reset() } fn key_import_yolo(mut admin: Admin, key: &Cert) -> Result<()> {