feat: init commit
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use tracing::instrument;
|
||||
use x509_cert::der::Encode;
|
||||
use x509_parser::nom::Parser;
|
||||
use yubikey::piv::AlgorithmId;
|
||||
use yubikey::YubiKey;
|
||||
|
||||
use native_pkcs11_traits::{Backend, KeySearchOptions};
|
||||
@@ -25,6 +28,9 @@ use native_pkcs11_traits::PrivateKey as P11PrivateKey;
|
||||
use native_pkcs11_traits::PublicKey as P11PublicKey;
|
||||
use native_pkcs11_traits::Result as P11Result;
|
||||
|
||||
use crate::certificate::YubikeyPivCertificate;
|
||||
use crate::piv::util::get_algorithm_id_by_certificate;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct YubikeyPivBackend {
|
||||
cached_pin: Mutex<Option<String>>,
|
||||
@@ -82,8 +88,26 @@ impl Backend for YubikeyPivBackend {
|
||||
fn find_all_certificates(
|
||||
&self,
|
||||
) -> P11Result<Vec<Box<dyn P11Certificate>>> {
|
||||
// TODO ...
|
||||
Ok(vec![])
|
||||
let mut certs = vec![];
|
||||
self.run_with_yubikey(false, |yk| {
|
||||
let keys = yk.piv_keys()?;
|
||||
for key in keys {
|
||||
let certificate_der = key.certificate().cert.to_der()?;
|
||||
let public_key_der = key.certificate().cert.tbs_certificate.subject_public_key_info.to_der()?;
|
||||
let algorithm_id = get_algorithm_id_by_certificate(key.certificate())?;
|
||||
if algorithm_id == AlgorithmId::EccP256 || algorithm_id == AlgorithmId::EccP384 {
|
||||
let cert: Box<dyn P11Certificate> = Box::new(YubikeyPivCertificate::new(
|
||||
key.slot().to_string(),
|
||||
key.slot().to_string(),
|
||||
certificate_der,
|
||||
public_key_der,
|
||||
)?);
|
||||
certs.push(cert);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(certs)
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
@@ -92,8 +116,12 @@ impl Backend for YubikeyPivBackend {
|
||||
query: P11KeySearchOptions,
|
||||
) -> P11Result<Option<Arc<dyn P11PrivateKey>>> {
|
||||
match query {
|
||||
KeySearchOptions::Label(label) => {}
|
||||
KeySearchOptions::PublicKeyHash(public_key_hash) => {}
|
||||
KeySearchOptions::Label(label) => {
|
||||
println!(">>> find private key >>>: {}", label);
|
||||
}
|
||||
KeySearchOptions::PublicKeyHash(public_key_hash) => {
|
||||
println!(">>> find private key >>>: {:?}", public_key_hash);
|
||||
}
|
||||
}
|
||||
// TODO ...
|
||||
Ok(None)
|
||||
@@ -105,8 +133,12 @@ impl Backend for YubikeyPivBackend {
|
||||
query: P11KeySearchOptions,
|
||||
) -> P11Result<Option<Box<dyn P11PublicKey>>> {
|
||||
match query {
|
||||
KeySearchOptions::Label(label) => {}
|
||||
KeySearchOptions::PublicKeyHash(public_key_hash) => {}
|
||||
KeySearchOptions::Label(label) => {
|
||||
println!(">>> find public key >>>: {}", label);
|
||||
}
|
||||
KeySearchOptions::PublicKeyHash(public_key_hash) => {
|
||||
println!(">>> find public key >>>: {:?}", public_key_hash);
|
||||
}
|
||||
}
|
||||
// TODO ...
|
||||
Ok(None)
|
||||
@@ -122,6 +154,9 @@ impl Backend for YubikeyPivBackend {
|
||||
fn find_all_public_keys(
|
||||
&self,
|
||||
) -> P11Result<Vec<Arc<dyn P11PublicKey>>> {
|
||||
// self.find_all_certificates().map(|c|{
|
||||
// c.as_mut().map(|c| )
|
||||
// })
|
||||
// TODO ...
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user