feat: v1.1.3, pgp-card-list add public key sha256
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -384,7 +384,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.1.2"
|
version = "1.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"authenticator",
|
"authenticator",
|
||||||
"base64 0.13.0",
|
"base64 0.13.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.1.2"
|
version = "1.1.3"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ cargo install --git https://git.hatter.ink/hatter/card-cli.git
|
|||||||
|
|
||||||
## encrypt & decrypt
|
## encrypt & decrypt
|
||||||
|
|
||||||
sample public key
|
sample encrypt public key
|
||||||
```
|
```
|
||||||
-----BEGIN PUBLIC KEY-----
|
-----BEGIN PUBLIC KEY-----
|
||||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApUM8M+QRMUw0dIvXISFx
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApUM8M+QRMUw0dIvXISFx
|
||||||
@@ -43,7 +43,7 @@ $ cargo r -- pgp-card-decrypt -c $(cat enc.txt | xxd -ps -c 11111)
|
|||||||
|
|
||||||
sign
|
sign
|
||||||
```
|
```
|
||||||
$ cargo r -- pgp-card-sign -2 $(shasum -a 256 test.txt | awk '{print $1}')
|
$ cargo r -- pgp-card-sign -2 $(shasum -a 256 test.txt | awk '{print $1}')
|
||||||
|
|
||||||
OR
|
OR
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ use openssl::rsa::Rsa;
|
|||||||
use pem::Pem;
|
use pem::Pem;
|
||||||
use rust_util::util_clap::{Command, CommandError};
|
use rust_util::util_clap::{Command, CommandError};
|
||||||
|
|
||||||
|
use crate::digest::sha256_bytes;
|
||||||
|
|
||||||
pub struct CommandImpl;
|
pub struct CommandImpl;
|
||||||
|
|
||||||
impl Command for CommandImpl {
|
impl Command for CommandImpl {
|
||||||
@@ -110,9 +112,11 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
if detail_output {
|
if detail_output {
|
||||||
if let Ok(public_key) = trans.public_key(KeyType::Authentication) {
|
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());
|
information!("Authentication public key: {}", public_key_pem.trim());
|
||||||
if json_output {
|
if json_output {
|
||||||
|
json.insert("authentication_public_key_sha256", hex::encode(&public_key_sha256));
|
||||||
json.insert("authentication_public_key_pem", public_key_pem);
|
json.insert("authentication_public_key_pem", public_key_pem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,9 +133,11 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
if detail_output {
|
if detail_output {
|
||||||
if let Ok(public_key) = trans.public_key(KeyType::Decryption) {
|
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());
|
information!("Encryption public key: {}", public_key_pem.trim());
|
||||||
if json_output {
|
if json_output {
|
||||||
|
json.insert("encryption_public_key_sha256", hex::encode(&public_key_sha256));
|
||||||
json.insert("encryption_public_key_pem", public_key_pem);
|
json.insert("encryption_public_key_pem", public_key_pem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,9 +154,11 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
if detail_output {
|
if detail_output {
|
||||||
if let Ok(public_key) = trans.public_key(KeyType::Signing) {
|
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());
|
information!("Signature public key: {}", public_key_pem.trim());
|
||||||
if json_output {
|
if json_output {
|
||||||
|
json.insert("signature_public_key_sha256", hex::encode(&public_key_sha256));
|
||||||
json.insert("signature_public_key_pem", public_key_pem);
|
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 {
|
match public_key {
|
||||||
PublicKeyMaterial::R(rsa_pub) => {
|
PublicKeyMaterial::R(rsa_pub) => {
|
||||||
let rsa_pub_key = Rsa::from_public_components(
|
let rsa_pub_key = Rsa::from_public_components(
|
||||||
BigNum::from_slice(rsa_pub.n()).unwrap(),
|
BigNum::from_slice(rsa_pub.n()).unwrap(),
|
||||||
BigNum::from_slice(rsa_pub.v()).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 {
|
let pub_key_pem_obj = Pem {
|
||||||
tag: String::from("PUBLIC KEY"),
|
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);
|
warning!("Not RSA public key: {:?}", public_key);
|
||||||
|
|||||||
Reference in New Issue
Block a user