Adjust tools to changed openpgp-card API
This commit is contained in:
parent
376072910e
commit
6100ec4318
3 changed files with 31 additions and 13 deletions
|
@ -16,6 +16,7 @@ sequoia-openpgp = "1.3"
|
||||||
nettle = "7"
|
nettle = "7"
|
||||||
openpgp-card = { path = "../openpgp-card", version = "0.1" }
|
openpgp-card = { path = "../openpgp-card", version = "0.1" }
|
||||||
openpgp-card-pcsc = { path = "../pcsc", version = "0.1" }
|
openpgp-card-pcsc = { path = "../pcsc", version = "0.1" }
|
||||||
|
pcsc = "2"
|
||||||
openpgp-card-sequoia = { path = "../openpgp-card-sequoia", version = "0.0.7" }
|
openpgp-card-sequoia = { path = "../openpgp-card-sequoia", version = "0.0.7" }
|
||||||
rpassword = "5"
|
rpassword = "5"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
|
|
@ -5,7 +5,7 @@ use anyhow::Result;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use openpgp_card::{CardClient, Error, StatusBytes};
|
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;
|
use openpgp_card_sequoia::card::Open;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
|
@ -16,10 +16,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let cli = cli::Cli::from_args();
|
let cli = cli::Cli::from_args();
|
||||||
|
|
||||||
let mut card = PcscCard::open_by_ident(&cli.ident)?;
|
let mut card = PcscCard::open_by_ident(&cli.ident)?;
|
||||||
let pinpad_verify = card.feature_pinpad_verify();
|
let mut txc = get_txc!(card, true)?;
|
||||||
let pinpad_modify = card.feature_pinpad_modify();
|
|
||||||
|
|
||||||
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 {
|
match cli.cmd {
|
||||||
cli::Command::SetUserPin {} => {
|
cli::Command::SetUserPin {} => {
|
||||||
|
|
|
@ -12,7 +12,8 @@ use sequoia_openpgp::serialize::SerializeInto;
|
||||||
use sequoia_openpgp::Cert;
|
use sequoia_openpgp::Cert;
|
||||||
|
|
||||||
use openpgp_card::algorithm::AlgoSimple;
|
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::card::{Admin, Open};
|
||||||
use openpgp_card_sequoia::util::{make_cert, public_key_material_to_key};
|
use openpgp_card_sequoia::util::{make_cert, public_key_material_to_key};
|
||||||
|
@ -71,7 +72,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
cmd,
|
cmd,
|
||||||
} => {
|
} => {
|
||||||
let mut card = util::open_card(&ident)?;
|
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 {
|
match cmd {
|
||||||
cli::AdminCommand::Name { name } => {
|
cli::AdminCommand::Name { name } => {
|
||||||
|
@ -136,7 +139,9 @@ fn list_cards() -> Result<()> {
|
||||||
println!("Available OpenPGP cards:");
|
println!("Available OpenPGP cards:");
|
||||||
|
|
||||||
for mut card in 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());
|
println!(" {}", open.application_identifier()?.ident());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -150,14 +155,15 @@ fn set_identity(
|
||||||
id: u8,
|
id: u8,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut card = util::open_card(ident)?;
|
let mut card = util::open_card(ident)?;
|
||||||
|
let mut txc = get_txc!(card, true)?;
|
||||||
|
|
||||||
<dyn CardClient>::set_identity(&mut card, id)?;
|
<dyn CardClient>::set_identity(&mut txc, id)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
|
fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
|
||||||
let mut ca = if let Some(ident) = ident {
|
let mut card = if let Some(ident) = ident {
|
||||||
util::open_card(&ident)?
|
util::open_card(&ident)?
|
||||||
} else {
|
} else {
|
||||||
let mut cards = util::cards()?;
|
let mut cards = util::cards()?;
|
||||||
|
@ -167,7 +173,10 @@ fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
|
||||||
return Err(anyhow::anyhow!("Found {} cards", cards.len()));
|
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());
|
print!("OpenPGP card {}", open.application_identifier()?.ident());
|
||||||
|
|
||||||
|
@ -319,7 +328,9 @@ fn decrypt(
|
||||||
let input = util::open_or_stdin(input.as_deref())?;
|
let input = util::open_or_stdin(input.as_deref())?;
|
||||||
|
|
||||||
let mut card = util::open_card(ident)?;
|
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 mut user = util::verify_to_user(&mut open, pin_file)?;
|
||||||
let d = user.decryptor(&cert)?;
|
let d = user.decryptor(&cert)?;
|
||||||
|
@ -343,7 +354,9 @@ fn sign_detached(
|
||||||
let mut input = util::open_or_stdin(input.as_deref())?;
|
let mut input = util::open_or_stdin(input.as_deref())?;
|
||||||
|
|
||||||
let mut card = util::open_card(ident)?;
|
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 mut sign = util::verify_to_sign(&mut open, pin_file)?;
|
||||||
let s = sign.signer(&cert)?;
|
let s = sign.signer(&cert)?;
|
||||||
|
@ -360,7 +373,9 @@ fn sign_detached(
|
||||||
fn factory_reset(ident: &str) -> Result<()> {
|
fn factory_reset(ident: &str) -> Result<()> {
|
||||||
println!("Resetting Card {}", ident);
|
println!("Resetting Card {}", ident);
|
||||||
let mut card = util::open_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<()> {
|
fn key_import_yolo(mut admin: Admin, key: &Cert) -> Result<()> {
|
||||||
|
|
Loading…
Reference in a new issue