mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
replace Certificate with CertificateDer
This commit is contained in:
parent
60aa640f23
commit
84200b2cd2
2 changed files with 10 additions and 11 deletions
|
|
@ -2,7 +2,7 @@ use locales::t;
|
||||||
use modals::Modals;
|
use modals::Modals;
|
||||||
use rustls::client::WebPkiServerVerifier;
|
use rustls::client::WebPkiServerVerifier;
|
||||||
use rustls::client::danger::ServerCertVerified;
|
use rustls::client::danger::ServerCertVerified;
|
||||||
use rustls::pki_types::{ServerName, UnixTime};
|
use rustls::pki_types::{CertificateDer, ServerName, UnixTime};
|
||||||
use rustls::{CertificateError, Error, RootCertStore};
|
use rustls::{CertificateError, Error, RootCertStore};
|
||||||
use xous_names::XousNames;
|
use xous_names::XousNames;
|
||||||
|
|
||||||
|
|
@ -16,8 +16,8 @@ impl rustls::client::ServerCertVerifier for StifledCertificateVerification {
|
||||||
/// return ServerCertVerified::assertion()
|
/// return ServerCertVerified::assertion()
|
||||||
fn verify_server_cert(
|
fn verify_server_cert(
|
||||||
&self,
|
&self,
|
||||||
end_entity: &rustls::Certificate,
|
end_entity: &CertificateDer,
|
||||||
intermediates: &[rustls::Certificate],
|
intermediates: &[CertificateDer],
|
||||||
server_name: &ServerName,
|
server_name: &ServerName,
|
||||||
scts: &mut dyn Iterator<Item = &[u8]>,
|
scts: &mut dyn Iterator<Item = &[u8]>,
|
||||||
ocsp: &[u8],
|
ocsp: &[u8],
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ use rkyv::{
|
||||||
ser::{serializers::WriteSerializer, Serializer},
|
ser::{serializers::WriteSerializer, Serializer},
|
||||||
Deserialize,
|
Deserialize,
|
||||||
};
|
};
|
||||||
use rustls::{Certificate, ClientConfig, ClientConnection, RootCertStore};
|
use rustls::{ClientConfig, ClientConnection, RootCertStore};
|
||||||
|
use rustls::pki_types::CertificateDer;
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
use x509_parser::prelude::{FromDer, X509Certificate};
|
use x509_parser::prelude::{FromDer, X509Certificate};
|
||||||
use xous_names::XousNames;
|
use xous_names::XousNames;
|
||||||
|
|
@ -42,16 +43,14 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// a count of trusted certificates
|
/// a count of trusted certificates
|
||||||
pub fn trust_modal(&self, certificates: Vec<Certificate>) -> usize {
|
pub fn trust_modal(&self, certificates: Vec<CertificateDer>) -> usize {
|
||||||
let xns = XousNames::new().unwrap();
|
let xns = XousNames::new().unwrap();
|
||||||
let modals = Modals::new(&xns).unwrap();
|
let modals = Modals::new(&xns).unwrap();
|
||||||
|
|
||||||
let certificates: Vec<(String, X509Certificate)> = certificates
|
let certificates: Vec<(String, X509Certificate)> = certificates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|cert| {
|
.map(|cert| {
|
||||||
let mut hasher = sha2::Sha256::new();
|
X509Certificate::from_der(cert)
|
||||||
hasher.update(&cert);
|
|
||||||
(format!("{:X}", hasher.finalize()), X509Certificate::from_der(cert.as_ref()))
|
|
||||||
})
|
})
|
||||||
.filter(|(_fingerprint, result)| result.is_ok())
|
.filter(|(_fingerprint, result)| result.is_ok())
|
||||||
.map(|(fingerprint, result)| (fingerprint, result.unwrap().1))
|
.map(|(fingerprint, result)| (fingerprint, result.unwrap().1))
|
||||||
|
|
@ -239,8 +238,8 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// true if the certificate is saved in the TLS_TRUSTED_DICT in the pddb
|
/// true if the certificate is saved in the TLS_TRUSTED_DICT in the pddb
|
||||||
pub fn is_trusted_cert(&self, cert: Certificate) -> bool {
|
pub fn is_trusted_cert(&self, cert: CertificateDer) -> bool {
|
||||||
match X509Certificate::from_der(cert.as_ref()) {
|
match X509Certificate::from_der(cert) {
|
||||||
Ok(result) => self.is_trusted_x509(&result.1),
|
Ok(result) => self.is_trusted_x509(&result.1),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("failed to get x509 from Certificate: {e}");
|
log::warn!("failed to get x509 from Certificate: {e}");
|
||||||
|
|
@ -307,7 +306,7 @@ impl Tls {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// The TLS chain of trust for the host
|
/// The TLS chain of trust for the host
|
||||||
pub fn probe(&self, host: &str) -> Result<Vec<Certificate>, Error> {
|
pub fn probe(&self, host: &str) -> Result<Vec<CertificateDer>, Error> {
|
||||||
log::info!("starting TLS probe");
|
log::info!("starting TLS probe");
|
||||||
// Attempt to open the tls connection with an empty root_store
|
// Attempt to open the tls connection with an empty root_store
|
||||||
let root_store = rustls::RootCertStore::empty();
|
let root_store = rustls::RootCertStore::empty();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue