diff --git a/Cargo.lock b/Cargo.lock index 271d564..99dae68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -366,7 +366,7 @@ dependencies = [ [[package]] name = "card-cli" -version = "1.3.2" +version = "1.3.3" dependencies = [ "authenticator", "base64 0.13.0", @@ -374,7 +374,6 @@ dependencies = [ "clap", "digest 0.10.3", "hex", - "lazy_static", "openpgp-card", "openpgp-card-pcsc", "openpgp-card-sequoia", diff --git a/Cargo.toml b/Cargo.toml index ccc9bac..f49e173 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "card-cli" -version = "1.3.2" +version = "1.3.3" authors = ["Hatter Jiang "] edition = "2018" @@ -31,6 +31,6 @@ yubico_manager = "0.9" x509 = "0.2" x509-parser = "0.13" ssh-agent = { version = "0.2.3", features = ["agent"] } -lazy_static = "1.4.0" +#lazy_static = "1.4.0" #ssh-key = "0.4.0" #ctap-hid-fido2 = "2.1.3" diff --git a/src/cmd_sshagent.rs b/src/cmd_sshagent.rs index 4018225..7054d00 100644 --- a/src/cmd_sshagent.rs +++ b/src/cmd_sshagent.rs @@ -16,13 +16,10 @@ use ssh_agent::proto::message::{self, Message}; use ssh_agent::proto::public_key::PublicKey; use crate::digest::{copy_sha256, copy_sha512}; -use crate::sshutil::with_sign; - -lazy_static! { - static ref CARD: Mutex> = Mutex::new(None); -} +use crate::sshutil::{generate_ssh_string, with_sign}; struct SshAgent { + card: Mutex, use_sign: bool, pin: String, public_key: PublicKey, @@ -54,13 +51,10 @@ impl SshAgent { n: with_sign(n.to_vec()), }); let comment = format!("pgp-card:{}:{}", iff!(use_sign, "sign", "auth"), serial); - (public_key, comment.clone(), crate::sshutil::generate_ssh_string(e, n, &comment)) + (public_key, comment.clone(), generate_ssh_string(e, n, &comment)) }; - { - let mut card_mutex = CARD.lock().unwrap(); - *card_mutex = Some(card); - } Ok(Self { + card: Mutex::new(card), use_sign, pin, public_key, @@ -104,12 +98,8 @@ impl SshAgent { }; information!("SSH request, algorithm: {}", algorithm); - let mut card_mutex = CARD.lock().unwrap(); - let card_mut = match card_mutex.as_mut() { - Some(card) => card, - None => return Err(From::from("Illegal card status: none")), - }; - let mut pgp = OpenPgp::new(card_mut); + let mut card_mut = self.card.lock().unwrap(); + let mut pgp = OpenPgp::new(&mut *card_mut); let mut trans = opt_result!(pgp.transaction(), "Open card failed: {}"); let sig = if self.use_sign { debugging!("User pin verify for pw1 sign, use sign: {}", self.use_sign); diff --git a/src/main.rs b/src/main.rs index ae29f35..da415de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ #[macro_use] extern crate rust_util; -#[macro_use] -extern crate lazy_static; use clap::{App, AppSettings, ArgMatches}; use rust_util::util_clap::{Command, CommandError};