feat: v1.11.16
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -508,7 +508,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.11.15"
|
version = "1.11.16"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-gcm-stream",
|
"aes-gcm-stream",
|
||||||
"authenticator 0.3.1",
|
"authenticator 0.3.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "card-cli"
|
name = "card-cli"
|
||||||
version = "1.11.15"
|
version = "1.11.16"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::{cmdutil, ecdsautil, hmacutil, util};
|
|||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use rust_util::util_clap::{Command, CommandError};
|
use rust_util::util_clap::{Command, CommandError};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use crate::util::base64_encode;
|
||||||
|
|
||||||
pub struct CommandImpl;
|
pub struct CommandImpl;
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (pkcs8_base64, secret_key_pem, public_key_pem, jwk_ec_key) = match key_type.as_str() {
|
let (pkcs8_base64, secret_key_pem, public_key_pem, public_key_der, jwk_ec_key) = match key_type.as_str() {
|
||||||
"p256" => ecdsautil::generate_p256_keypair()?,
|
"p256" => ecdsautil::generate_p256_keypair()?,
|
||||||
"p384" => ecdsautil::generate_p384_keypair()?,
|
"p384" => ecdsautil::generate_p384_keypair()?,
|
||||||
_ => {
|
_ => {
|
||||||
@@ -59,6 +60,7 @@ impl Command for CommandImpl {
|
|||||||
} else {
|
} else {
|
||||||
(pkcs8_base64, secret_key_pem)
|
(pkcs8_base64, secret_key_pem)
|
||||||
};
|
};
|
||||||
|
let public_key_base64 = base64_encode(&public_key_der);
|
||||||
|
|
||||||
let keychain_key_uri = if let Some(keychain_name) = keychain_name {
|
let keychain_key_uri = if let Some(keychain_name) = keychain_name {
|
||||||
let keychain_key_value = KeychainKeyValue {
|
let keychain_key_value = KeychainKeyValue {
|
||||||
@@ -89,6 +91,7 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
json.insert("public_key_pem", public_key_pem);
|
json.insert("public_key_pem", public_key_pem);
|
||||||
|
json.insert("public_key_base64", public_key_base64);
|
||||||
json.insert("public_key_jwk", jwk_ec_key.to_string());
|
json.insert("public_key_jwk", jwk_ec_key.to_string());
|
||||||
|
|
||||||
util::print_pretty_json(&json);
|
util::print_pretty_json(&json);
|
||||||
@@ -103,6 +106,7 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
information!("Public key PEM:\n{}", public_key_pem);
|
information!("Public key PEM:\n{}", public_key_pem);
|
||||||
|
information!("Public key Base64:\n{}\n", public_key_base64);
|
||||||
information!("Public key JWK:\n{}", jwk_ec_key.to_string());
|
information!("Public key JWK:\n{}", jwk_ec_key.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,22 +56,24 @@ fn trim_point_leading_zero(p: &[u8]) -> Vec<u8> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_p256_keypair() -> XResult<(String, String, String, JwkEcKey)> {
|
pub fn generate_p256_keypair() -> XResult<(String, String, String, Vec<u8>, JwkEcKey)> {
|
||||||
let secret_key = p256::SecretKey::random(&mut rand::thread_rng());
|
let secret_key = p256::SecretKey::random(&mut rand::thread_rng());
|
||||||
let secret_key_der_base64 = base64_encode(secret_key.to_pkcs8_der()?.as_bytes());
|
let secret_key_der_base64 = base64_encode(secret_key.to_pkcs8_der()?.as_bytes());
|
||||||
let secret_key_pem = secret_key.to_pkcs8_pem(LineEnding::LF)?.to_string();
|
let secret_key_pem = secret_key.to_pkcs8_pem(LineEnding::LF)?.to_string();
|
||||||
let public_key_pem = secret_key.public_key().to_public_key_pem(LineEnding::LF)?;
|
let public_key_pem = secret_key.public_key().to_public_key_pem(LineEnding::LF)?;
|
||||||
|
let public_key_der = secret_key.public_key().to_public_key_der()?.to_vec();
|
||||||
let jwk_ec_key = secret_key.public_key().to_jwk();
|
let jwk_ec_key = secret_key.public_key().to_jwk();
|
||||||
Ok((secret_key_der_base64, secret_key_pem, public_key_pem, jwk_ec_key))
|
Ok((secret_key_der_base64, secret_key_pem, public_key_pem, public_key_der, jwk_ec_key))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_p384_keypair() -> XResult<(String, String, String, JwkEcKey)> {
|
pub fn generate_p384_keypair() -> XResult<(String, String, String, Vec<u8>, JwkEcKey)> {
|
||||||
let secret_key = p384::SecretKey::random(&mut rand::thread_rng());
|
let secret_key = p384::SecretKey::random(&mut rand::thread_rng());
|
||||||
let secret_key_der_base64 = base64_encode(secret_key.to_pkcs8_der()?.as_bytes());
|
let secret_key_der_base64 = base64_encode(secret_key.to_pkcs8_der()?.as_bytes());
|
||||||
let secret_key_pem = secret_key.to_pkcs8_pem(LineEnding::LF)?.to_string();
|
let secret_key_pem = secret_key.to_pkcs8_pem(LineEnding::LF)?.to_string();
|
||||||
let public_key_pem = secret_key.public_key().to_public_key_pem(LineEnding::LF)?;
|
let public_key_pem = secret_key.public_key().to_public_key_pem(LineEnding::LF)?;
|
||||||
|
let public_key_der = secret_key.public_key().to_public_key_der()?.to_vec();
|
||||||
let jwk_ec_key = secret_key.public_key().to_jwk();
|
let jwk_ec_key = secret_key.public_key().to_jwk();
|
||||||
Ok((secret_key_der_base64, secret_key_pem, public_key_pem, jwk_ec_key))
|
Ok((secret_key_der_base64, secret_key_pem, public_key_pem, public_key_der, jwk_ec_key))
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! parse_ecdsa_private_key {
|
macro_rules! parse_ecdsa_private_key {
|
||||||
|
|||||||
Reference in New Issue
Block a user