From 84200b2cd2cff39ae3173afe5f75d848d9cc5867 Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Thu, 15 Feb 2024 10:41:45 +1000 Subject: [PATCH] replace Certificate with CertificateDer --- libs/tls/src/danger.rs | 6 +++--- libs/tls/src/lib.rs | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libs/tls/src/danger.rs b/libs/tls/src/danger.rs index c983d5394..f04c6b6f0 100644 --- a/libs/tls/src/danger.rs +++ b/libs/tls/src/danger.rs @@ -2,7 +2,7 @@ use locales::t; use modals::Modals; use rustls::client::WebPkiServerVerifier; use rustls::client::danger::ServerCertVerified; -use rustls::pki_types::{ServerName, UnixTime}; +use rustls::pki_types::{CertificateDer, ServerName, UnixTime}; use rustls::{CertificateError, Error, RootCertStore}; use xous_names::XousNames; @@ -16,8 +16,8 @@ impl rustls::client::ServerCertVerifier for StifledCertificateVerification { /// return ServerCertVerified::assertion() fn verify_server_cert( &self, - end_entity: &rustls::Certificate, - intermediates: &[rustls::Certificate], + end_entity: &CertificateDer, + intermediates: &[CertificateDer], server_name: &ServerName, scts: &mut dyn Iterator, ocsp: &[u8], diff --git a/libs/tls/src/lib.rs b/libs/tls/src/lib.rs index bd26111bb..963b7394b 100644 --- a/libs/tls/src/lib.rs +++ b/libs/tls/src/lib.rs @@ -15,7 +15,8 @@ use rkyv::{ ser::{serializers::WriteSerializer, Serializer}, Deserialize, }; -use rustls::{Certificate, ClientConfig, ClientConnection, RootCertStore}; +use rustls::{ClientConfig, ClientConnection, RootCertStore}; +use rustls::pki_types::CertificateDer; use sha2::Digest; use x509_parser::prelude::{FromDer, X509Certificate}; use xous_names::XousNames; @@ -42,16 +43,14 @@ impl Tls { /// # Returns /// /// a count of trusted certificates - pub fn trust_modal(&self, certificates: Vec) -> usize { + pub fn trust_modal(&self, certificates: Vec) -> usize { let xns = XousNames::new().unwrap(); let modals = Modals::new(&xns).unwrap(); let certificates: Vec<(String, X509Certificate)> = certificates .iter() .map(|cert| { - let mut hasher = sha2::Sha256::new(); - hasher.update(&cert); - (format!("{:X}", hasher.finalize()), X509Certificate::from_der(cert.as_ref())) + X509Certificate::from_der(cert) }) .filter(|(_fingerprint, result)| result.is_ok()) .map(|(fingerprint, result)| (fingerprint, result.unwrap().1)) @@ -239,8 +238,8 @@ impl Tls { /// # Returns /// /// true if the certificate is saved in the TLS_TRUSTED_DICT in the pddb - pub fn is_trusted_cert(&self, cert: Certificate) -> bool { - match X509Certificate::from_der(cert.as_ref()) { + pub fn is_trusted_cert(&self, cert: CertificateDer) -> bool { + match X509Certificate::from_der(cert) { Ok(result) => self.is_trusted_x509(&result.1), Err(e) => { log::warn!("failed to get x509 from Certificate: {e}"); @@ -307,7 +306,7 @@ impl Tls { /// # Returns /// /// The TLS chain of trust for the host - pub fn probe(&self, host: &str) -> Result, Error> { + pub fn probe(&self, host: &str) -> Result, Error> { log::info!("starting TLS probe"); // Attempt to open the tls connection with an empty root_store let root_store = rustls::RootCertStore::empty();