include broken tls::rota::public_key()

This commit is contained in:
nworbnhoj 2023-07-04 07:34:55 +10:00
parent a5ef4585a8
commit 4e0298c17a
2 changed files with 20 additions and 3 deletions

View file

@ -134,8 +134,6 @@ impl Tls {
// saves a tls trust-anchor to the pddb
pub fn save_cert(&self, ta: &RustlsOwnedTrustAnchor) -> Result<(), Error> {
// let xns = XousNames::new().unwrap();
// let modals = Modals::new(&xns).unwrap();
let key = ta.pddb_key();
match self.pddb.get(
TLS_TRUSTED_DICT,
@ -163,7 +161,6 @@ impl Tls {
let pos_bytes = pos.to_be_bytes();
bytes[0] = pos_bytes[0];
bytes[1] = pos_bytes[1];
match pddb_key.write(&bytes) {
Ok(len) => {
self.pddb.sync().ok();

View file

@ -50,6 +50,26 @@ impl RustlsOwnedTrustAnchor {
}
}
// decoded public key
// see https://docs.rs/x509-parser/0.15.0/src/x509_parser/x509.rs.html#260-274
#[allow(unreachable_code)]
pub fn public_key(&self) -> Result<Vec<u8>, Error> {
todo!(); // fails decode
match add_der_header(Tag::Sequence, &self.spki) {
Ok(der) => match x509_parser::x509::SubjectPublicKeyInfo::from_der(&der) {
Ok((_, spki)) => Ok(spki.subject_public_key.data.to_vec()),
Err(e) => {
log::warn!("{:?}", e);
Err(Error::new(ErrorKind::InvalidData, "failed spki der decode"))
}
},
Err(e) => {
log::warn!("{:?}", e.into_inner().unwrap());
Err(Error::new(ErrorKind::InvalidData, "failed spki der header"))
}
}
}
pub fn pddb_key(&self) -> String {
let subject = &self.subject();
let begin = match subject.find("CN=") {