From c7560e24f319eb69eb5f2bdf7cb87fca540390e5 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 9 Apr 2022 00:26:52 +0800 Subject: [PATCH] feat: v1.1.6, pgp card make --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmd_pgpcardmake.rs | 44 +++++++++++++++++++++++------------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3704e59..65a5f4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -384,7 +384,7 @@ dependencies = [ [[package]] name = "card-cli" -version = "1.1.5" +version = "1.1.6" dependencies = [ "authenticator", "base64 0.13.0", diff --git a/Cargo.toml b/Cargo.toml index 8799201..4d4bffe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "card-cli" -version = "1.1.5" +version = "1.1.6" authors = ["Hatter Jiang "] edition = "2018" diff --git a/src/cmd_pgpcardmake.rs b/src/cmd_pgpcardmake.rs index 62235f5..9b83662 100644 --- a/src/cmd_pgpcardmake.rs +++ b/src/cmd_pgpcardmake.rs @@ -182,16 +182,17 @@ impl Command for CommandImpl { } debugging!("Found PGP RSA private key set: {:?}", pgp_rsa_private_key_set); + + if pgp_rsa_private_key_set.signing.is_none() + || pgp_rsa_private_key_set.encryption.is_none() + || pgp_rsa_private_key_set.authentication.is_none() { + warning!("PGP RSA private keys is not complete!"); + } success!("Found PGP RSA private keys, signing: {}, encryption: {}, authentication: {}", pgp_rsa_private_key_set.signing.is_some(), pgp_rsa_private_key_set.encryption.is_some(), pgp_rsa_private_key_set.authentication.is_some()); - if pgp_rsa_private_key_set.signing.is_none() || pgp_rsa_private_key_set.encryption.is_none() || pgp_rsa_private_key_set.authentication.is_none() { - warning!("PGP RSA private keys is not complete!"); - return Ok(None); - } - let force_make = sub_arg_matches.is_present("force-make"); if !force_make { warning!("Force make is OFF, skip write private keys to card!"); @@ -206,23 +207,26 @@ impl Command for CommandImpl { opt_result!(trans.verify_pw3(pin.as_ref()), "Admin pin verify failed: {}"); success!("Admin pin verify success!"); - let signing_key = pgp_rsa_private_key_set.signing.unwrap(); - let signing_key_id = signing_key.key_id.clone(); - information!("Prepare write PGP signing key, key id: {}", signing_key_id); - opt_result!(trans.key_import(Box::new(signing_key), KeyType::Signing), "Write PGP signing key failed: {}"); - success!("Write PGP signing key success, key id: {}", signing_key_id); + if let Some(signing_key) = pgp_rsa_private_key_set.signing { + let signing_key_id = signing_key.key_id.clone(); + information!("Prepare write PGP signing key, key id: {}", signing_key_id); + opt_result!(trans.key_import(Box::new(signing_key), KeyType::Signing), "Write PGP signing key failed: {}"); + success!("Write PGP signing key success, key id: {}", signing_key_id); + } - let encryption_key = pgp_rsa_private_key_set.encryption.unwrap(); - let encryption_key_id = encryption_key.key_id.clone(); - information!("Prepare write PGP encryption key, key id: {}", signing_key_id); - opt_result!(trans.key_import(Box::new(encryption_key), KeyType::Decryption), "Write PGP encryption key failed: {}"); - success!("Write PGP encryption key success, key id: {}", encryption_key_id); + if let Some(encryption_key) = pgp_rsa_private_key_set.encryption { + let encryption_key_id = encryption_key.key_id.clone(); + information!("Prepare write PGP encryption key, key id: {}", signing_key_id); + opt_result!(trans.key_import(Box::new(encryption_key), KeyType::Decryption), "Write PGP encryption key failed: {}"); + success!("Write PGP encryption key success, key id: {}", encryption_key_id); + } - let authentication_key = pgp_rsa_private_key_set.authentication.unwrap(); - let authentication_key_id = authentication_key.key_id.clone(); - information!("Prepare write PGP authentication key, key id: {}", signing_key_id); - opt_result!(trans.key_import(Box::new(authentication_key), KeyType::Authentication), "Write PGP authentication key failed: {}"); - success!("Write PGP authentication key success, key id: {}", authentication_key_id); + if let Some(authentication_key) = pgp_rsa_private_key_set.authentication { + let authentication_key_id = authentication_key.key_id.clone(); + information!("Prepare write PGP authentication key, key id: {}", signing_key_id); + opt_result!(trans.key_import(Box::new(authentication_key), KeyType::Authentication), "Write PGP authentication key failed: {}"); + success!("Write PGP authentication key success, key id: {}", authentication_key_id); + } Ok(None) }