feat: updates

This commit is contained in:
2024-12-15 14:14:06 +08:00
parent d686bbe767
commit 4406cf6d2e
4 changed files with 39 additions and 35 deletions

View File

@@ -44,9 +44,8 @@ impl Command for CommandImpl {
util_msg::set_logger_std_out(false); util_msg::set_logger_std_out(false);
} }
let se_key_uri = match parse_key_uri(key)? { let KeyUri::SecureEnclaveKey(se_key_uri) = parse_key_uri(key)?;
KeyUri::SecureEnclaveKey(se_key_uri) => se_key_uri, debugging!("Secure enclave key URI: {:?}", se_key_uri);
};
let ephemeral_public_key_bytes = hex::decode(epk)?; let ephemeral_public_key_bytes = hex::decode(epk)?;
let dh = let dh =

View File

@@ -55,10 +55,7 @@ impl Command for CommandImpl {
util_msg::set_logger_std_out(false); util_msg::set_logger_std_out(false);
} }
let se_key_uri = match parse_key_uri(key)? { let KeyUri::SecureEnclaveKey(se_key_uri) = parse_key_uri(key)?;
KeyUri::SecureEnclaveKey(se_key_uri) => se_key_uri,
};
debugging!("Secure enclave key URI: {:?}", se_key_uri); debugging!("Secure enclave key URI: {:?}", se_key_uri);
let signature = seutil::secure_enclave_p256_sign(&se_key_uri.private_key, &message_bytes)?; let signature = seutil::secure_enclave_p256_sign(&se_key_uri.private_key, &message_bytes)?;

View File

@@ -7,23 +7,23 @@ pub enum KeyUri {
SecureEnclaveKey(SecureEnclaveKey), SecureEnclaveKey(SecureEnclaveKey),
} }
#[derive(Debug, PartialEq, Eq)] // #[derive(Debug, PartialEq, Eq)]
pub enum KeyModule { // pub enum KeyModule {
SecureEnclave, // SecureEnclave,
OpenPgpCard, // OpenPgpCard,
PersonalIdentityVerification, // PersonalIdentityVerification,
} // }
//
impl KeyModule { // impl KeyModule {
pub fn from(module: &str) -> Option<Self> { // pub fn from(module: &str) -> Option<Self> {
match module { // match module {
"se" => Some(Self::SecureEnclave), // "se" => Some(Self::SecureEnclave),
"pgp" => Some(Self::OpenPgpCard), // "pgp" => Some(Self::OpenPgpCard),
"piv" => Some(Self::PersonalIdentityVerification), // "piv" => Some(Self::PersonalIdentityVerification),
_ => None, // _ => None,
} // }
} // }
} // }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum KeyUsage { pub enum KeyUsage {
@@ -37,12 +37,13 @@ impl KeyUsage {
match usage { match usage {
"signing" => Some(Self::Singing), "signing" => Some(Self::Singing),
"key_agreement" => Some(Self::KeyAgreement), "key_agreement" => Some(Self::KeyAgreement),
"*" => Some(Self::Singing), "*" => Some(Self::Any),
_ => None, _ => None,
} }
} }
} }
#[allow(dead_code)]
#[derive(Debug)] #[derive(Debug)]
pub struct SecureEnclaveKey { pub struct SecureEnclaveKey {
pub host: String, pub host: String,
@@ -75,11 +76,14 @@ pub fn parse_key_uri(key_uri: &str) -> XResult<KeyUri> {
Some(key_usage) => key_usage, Some(key_usage) => key_usage,
}; };
Ok(KeyUri::SecureEnclaveKey(SecureEnclaveKey { let parsed_key_uri = KeyUri::SecureEnclaveKey(SecureEnclaveKey {
host: host.to_string(), host: host.to_string(),
usage: key_usage, usage: key_usage,
private_key: left_part.to_string(), private_key: left_part.to_string(),
})) });
debugging!("Parsed key uri: {:?}", parsed_key_uri);
Ok(parsed_key_uri)
} }
#[test] #[test]

View File

@@ -33,11 +33,11 @@ mod cmd_rsaverify;
#[cfg(feature = "with-secure-enclave")] #[cfg(feature = "with-secure-enclave")]
mod cmd_se; mod cmd_se;
#[cfg(feature = "with-secure-enclave")] #[cfg(feature = "with-secure-enclave")]
mod cmd_se_generate; mod cmd_se_ecdh;
#[cfg(feature = "with-secure-enclave")] #[cfg(feature = "with-secure-enclave")]
mod cmd_se_ecsign; mod cmd_se_ecsign;
#[cfg(feature = "with-secure-enclave")] #[cfg(feature = "with-secure-enclave")]
mod cmd_se_ecdh; mod cmd_se_generate;
mod cmd_signfile; mod cmd_signfile;
mod cmd_signjwt; mod cmd_signjwt;
mod cmd_sshagent; mod cmd_sshagent;
@@ -54,6 +54,7 @@ mod ecdhutil;
mod ecdsautil; mod ecdsautil;
mod fido; mod fido;
mod hmacutil; mod hmacutil;
mod keyutil;
mod pgpcardutil; mod pgpcardutil;
mod pinutil; mod pinutil;
mod pivutil; mod pivutil;
@@ -64,7 +65,6 @@ mod seutil;
mod signfile; mod signfile;
mod sshutil; mod sshutil;
mod util; mod util;
mod keyutil;
pub struct DefaultCommandImpl; pub struct DefaultCommandImpl;
@@ -138,11 +138,15 @@ fn inner_main() -> CommandError {
Box::new(cmd_se_ecdh::CommandImpl), Box::new(cmd_se_ecdh::CommandImpl),
]; ];
#[allow(clippy::vec_init_then_push)]
let features = {
let mut features: Vec<&str> = vec![]; let mut features: Vec<&str> = vec![];
#[cfg(feature = "with-sequoia-openpgp")] #[cfg(feature = "with-sequoia-openpgp")]
features.push("sequoia-openpgp"); features.push("sequoia-openpgp");
#[cfg(feature = "with-secure-enclave")] #[cfg(feature = "with-secure-enclave")]
features.push("secure-enclave"); features.push("secure-enclave");
features
};
let about = format!( let about = format!(
"{}, features: [{}]", "{}, features: [{}]",
"Card Cli is a command tool for WebAuthn, OpenPGP, YubiKey ... smart cards", "Card Cli is a command tool for WebAuthn, OpenPGP, YubiKey ... smart cards",