Ran cargo fmt
This commit is contained in:
parent
e25ebfa353
commit
d2802ced83
5 changed files with 36 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
|||
use digest::Digest;
|
||||
use rustls::Certificate;
|
||||
use sha2::Sha256;
|
||||
use std::fmt::{Write, self};
|
||||
use std::fmt::{self, Write};
|
||||
use x509_parser::prelude::*;
|
||||
|
||||
pub trait Fingerprint {
|
||||
|
@ -63,4 +63,3 @@ impl Fingerprint for Certificate {
|
|||
Ok((subject[3..].to_string(), s))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
use std::{io::{Read, Write, self}, fmt};
|
||||
use crate::{request::{Request, ParseRequestError}, response::{Response, ParseResponseError}};
|
||||
use self::{verifier::Verifier, store::CertificateStore};
|
||||
use self::{store::CertificateStore, verifier::Verifier};
|
||||
use crate::{
|
||||
request::{ParseRequestError, Request},
|
||||
response::{ParseResponseError, Response},
|
||||
};
|
||||
use std::{
|
||||
fmt,
|
||||
io::{self, Read, Write},
|
||||
};
|
||||
|
||||
pub mod store;
|
||||
pub mod verifier;
|
||||
|
@ -67,7 +73,11 @@ impl From<io::Error> for Error {
|
|||
}
|
||||
|
||||
impl<'a, S, C, T> Sender<'a, S, C, T>
|
||||
where S: CertificateStore + Sync, C: Sized, T: Read + Write + Sized {
|
||||
where
|
||||
S: CertificateStore + Sync,
|
||||
C: Sized,
|
||||
T: Read + Write + Sized,
|
||||
{
|
||||
pub fn new(request_str: &str, store: &'a S) -> Result<Self, Error> {
|
||||
let request: Request = request_str.parse()?;
|
||||
let verifier = Verifier::new(store);
|
||||
|
|
|
@ -2,4 +2,3 @@ pub trait CertificateStore {
|
|||
fn get(&self, host: &str) -> Option<String>;
|
||||
fn insert(&mut self, host: &str, fingerprint: &str);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use crate::fingerprint::Fingerprint;
|
||||
use rustls::{client::{ServerCertVerified, ServerCertVerifier}, Certificate};
|
||||
use super::store::CertificateStore;
|
||||
use crate::fingerprint::Fingerprint;
|
||||
use rustls::{
|
||||
client::{ServerCertVerified, ServerCertVerifier},
|
||||
Certificate,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Verifier<'a, T: CertificateStore> {
|
||||
|
@ -17,11 +20,13 @@ impl<'a, T: CertificateStore + Sync> ServerCertVerifier for Verifier<'a, T> {
|
|||
_ocsp_response: &[u8],
|
||||
_now: std::time::SystemTime,
|
||||
) -> Result<ServerCertVerified, rustls::Error> {
|
||||
let fp = end_entity.fingerprint().map_err(|e| rustls::Error::General(e.to_string()))?;
|
||||
let fp = end_entity
|
||||
.fingerprint()
|
||||
.map_err(|e| rustls::Error::General(e.to_string()))?;
|
||||
let name = match server_name {
|
||||
rustls::ServerName::DnsName(n) => n.as_ref().to_string(),
|
||||
rustls::ServerName::IpAddress(ip) => ip.to_string(),
|
||||
_ => todo!()
|
||||
_ => todo!(),
|
||||
};
|
||||
if let Some(fingerprint) = match server_name {
|
||||
rustls::ServerName::DnsName(n) => self.store.get(n.as_ref()),
|
||||
|
@ -35,7 +40,9 @@ impl<'a, T: CertificateStore + Sync> ServerCertVerifier for Verifier<'a, T> {
|
|||
// todo: need a way to update `self.store`. Probably will require
|
||||
// an Arc<Mutex<T>> for interior mutability
|
||||
}
|
||||
return Err(rustls::Error::General("Unrecognized certificate".to_string()));
|
||||
return Err(rustls::Error::General(
|
||||
"Unrecognized certificate".to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue