feat: v1.1.3, pgp-card-list add public key sha256
This commit is contained in:
@@ -9,6 +9,8 @@ use openssl::rsa::Rsa;
|
||||
use pem::Pem;
|
||||
use rust_util::util_clap::{Command, CommandError};
|
||||
|
||||
use crate::digest::sha256_bytes;
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
impl Command for CommandImpl {
|
||||
@@ -110,9 +112,11 @@ impl Command for CommandImpl {
|
||||
}
|
||||
if detail_output {
|
||||
if let Ok(public_key) = trans.public_key(KeyType::Authentication) {
|
||||
if let Some(public_key_pem) = public_key_pem(&public_key) {
|
||||
if let Some((public_key_sha256, public_key_pem)) = public_key_pem(&public_key) {
|
||||
information!("Authentication public key sha256: {}", hex::encode(&public_key_sha256));
|
||||
information!("Authentication public key: {}", public_key_pem.trim());
|
||||
if json_output {
|
||||
json.insert("authentication_public_key_sha256", hex::encode(&public_key_sha256));
|
||||
json.insert("authentication_public_key_pem", public_key_pem);
|
||||
}
|
||||
}
|
||||
@@ -129,9 +133,11 @@ impl Command for CommandImpl {
|
||||
}
|
||||
if detail_output {
|
||||
if let Ok(public_key) = trans.public_key(KeyType::Decryption) {
|
||||
if let Some(public_key_pem) = public_key_pem(&public_key) {
|
||||
if let Some((public_key_sha256, public_key_pem)) = public_key_pem(&public_key) {
|
||||
information!("Encryption public key sha256: {}", hex::encode(&public_key_sha256));
|
||||
information!("Encryption public key: {}", public_key_pem.trim());
|
||||
if json_output {
|
||||
json.insert("encryption_public_key_sha256", hex::encode(&public_key_sha256));
|
||||
json.insert("encryption_public_key_pem", public_key_pem);
|
||||
}
|
||||
}
|
||||
@@ -148,9 +154,11 @@ impl Command for CommandImpl {
|
||||
}
|
||||
if detail_output {
|
||||
if let Ok(public_key) = trans.public_key(KeyType::Signing) {
|
||||
if let Some(public_key_pem) = public_key_pem(&public_key) {
|
||||
if let Some((public_key_sha256, public_key_pem)) = public_key_pem(&public_key) {
|
||||
information!("Signature public key sha256: {}", hex::encode(&public_key_sha256));
|
||||
information!("Signature public key: {}", public_key_pem.trim());
|
||||
if json_output {
|
||||
json.insert("signature_public_key_sha256", hex::encode(&public_key_sha256));
|
||||
json.insert("signature_public_key_pem", public_key_pem);
|
||||
}
|
||||
}
|
||||
@@ -169,18 +177,20 @@ impl Command for CommandImpl {
|
||||
}
|
||||
}
|
||||
|
||||
fn public_key_pem(public_key: &PublicKeyMaterial) -> Option<String> {
|
||||
fn public_key_pem(public_key: &PublicKeyMaterial) -> Option<(Vec<u8>, String)> {
|
||||
match public_key {
|
||||
PublicKeyMaterial::R(rsa_pub) => {
|
||||
let rsa_pub_key = Rsa::from_public_components(
|
||||
BigNum::from_slice(rsa_pub.n()).unwrap(),
|
||||
BigNum::from_slice(rsa_pub.v()).unwrap(),
|
||||
);
|
||||
let rsa_pub_key_bytes = rsa_pub_key.unwrap().public_key_to_der().unwrap();
|
||||
let rsa_pub_key_bytes_sha256 = sha256_bytes(&rsa_pub_key_bytes);
|
||||
let pub_key_pem_obj = Pem {
|
||||
tag: String::from("PUBLIC KEY"),
|
||||
contents: rsa_pub_key.unwrap().public_key_to_der().unwrap(),
|
||||
contents: rsa_pub_key_bytes,
|
||||
};
|
||||
Some(pem::encode(&pub_key_pem_obj))
|
||||
Some((rsa_pub_key_bytes_sha256, pem::encode(&pub_key_pem_obj)))
|
||||
}
|
||||
_ => {
|
||||
warning!("Not RSA public key: {:?}", public_key);
|
||||
|
||||
Reference in New Issue
Block a user