feat: v1.1.4 add pkiutil

This commit is contained in:
2022-04-03 21:37:55 +08:00
parent 6f4f3f74f1
commit 779f76f3ec
6 changed files with 62 additions and 56 deletions

View File

@@ -2,17 +2,15 @@ use std::ops::Deref;
use chrono::{DateTime, Local};
use clap::{App, Arg, ArgMatches, SubCommand};
use openssl::bn::BigNum;
use openssl::rsa::Rsa;
use pem::Pem;
use rust_util::util_clap::{Command, CommandError};
use sequoia_openpgp::crypto::mpi::PublicKey;
use sequoia_openpgp::Packet;
use sequoia_openpgp::packet::{Body, Key, PKESK, SEIP, Signature};
use sequoia_openpgp::packet::signature::subpacket::{SubpacketTag, SubpacketValue};
use sequoia_openpgp::parse::{PacketParser, PacketParserResult};
use sequoia_openpgp::parse::Parse;
use crate::pkiutil::sequoia_openpgp_public_key_pem as public_key_pem;
pub struct CommandImpl;
impl Command for CommandImpl {
@@ -91,7 +89,8 @@ impl Command for CommandImpl {
public_key4.push_str(&format!("\n\tCreation time {}", creation_time_str));
public_key4.push_str(&format!("\n\tPublic algo: {:?}", key4.pk_algo()));
if show_detail {
if let Some(pubkey_pem) = public_key_pem(key4.mpis()) {
if let Some((pubkey_sha256, pubkey_pem)) = public_key_pem(key4.mpis()) {
public_key4.push_str(&format!("\n\tPublic key sha256: {}", hex::encode(pubkey_sha256)));
public_key4.push_str(&format!("\n\tPublic key PEM: {}", pubkey_pem));
}
}
@@ -114,7 +113,8 @@ impl Command for CommandImpl {
public_key4.push_str(&format!("\n\tCreation time {}", creation_time_str));
public_key4.push_str(&format!("\n\tPublic algo: {:?}", key4.pk_algo()));
if show_detail {
if let Some(pub_key_pem) = public_key_pem(key4.mpis()) {
if let Some((pubkey_sha256, pub_key_pem)) = public_key_pem(key4.mpis()) {
public_key4.push_str(&format!("\n\tPublic key sha256: {}", hex::encode(pubkey_sha256)));
public_key4.push_str(&format!("\n\tPublic key PEM: {}", pub_key_pem));
}
}
@@ -200,23 +200,3 @@ impl Command for CommandImpl {
Ok(None)
}
}
fn public_key_pem(public_key: &PublicKey) -> Option<String> {
match public_key {
PublicKey::RSA { e, n } => {
let rsa_pub_key = Rsa::from_public_components(
BigNum::from_slice(n.value()).unwrap(),
BigNum::from_slice(e.value()).unwrap(),
);
let pub_key_pem_obj = Pem {
tag: String::from("PUBLIC KEY"),
contents: rsa_pub_key.unwrap().public_key_to_der().unwrap(),
};
Some(pem::encode(&pub_key_pem_obj))
}
_ => {
warning!("Not RSA public key: {:?}", public_key);
None
}
}
}