mirror of
https://github.com/aramperes/nut-rs.git
synced 2025-09-09 05:28:31 -04:00
parent
d78fd8c141
commit
d36999db6d
16 changed files with 494 additions and 104 deletions
40
nut-client/src/ssl/mod.rs
Normal file
40
nut-client/src/ssl/mod.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use crate::Config;
|
||||
|
||||
/// The certificate validation mechanism for NUT.
|
||||
pub struct NutCertificateValidator {
|
||||
debug: bool,
|
||||
}
|
||||
|
||||
impl NutCertificateValidator {
|
||||
/// Initialize a new instance.
|
||||
pub fn new(config: &Config) -> Self {
|
||||
NutCertificateValidator {
|
||||
debug: config.debug,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl rustls::ServerCertVerifier for NutCertificateValidator {
|
||||
fn verify_server_cert(
|
||||
&self,
|
||||
_roots: &rustls::RootCertStore,
|
||||
presented_certs: &[rustls::Certificate],
|
||||
_dns_name: webpki::DNSNameRef<'_>,
|
||||
_ocsp: &[u8],
|
||||
) -> Result<rustls::ServerCertVerified, rustls::TLSError> {
|
||||
// todo: verify certificates, but not hostnames
|
||||
|
||||
if self.debug {
|
||||
let parsed = webpki::EndEntityCert::from(presented_certs[0].0.as_slice()).ok();
|
||||
if let Some(_parsed) = parsed {
|
||||
eprintln!("DEBUG <- Certificate received and parsed");
|
||||
// todo: reading values here... https://github.com/briansmith/webpki/pull/103
|
||||
} else {
|
||||
eprintln!("DEBUG <- Certificate not-parseable");
|
||||
}
|
||||
}
|
||||
|
||||
// trust everything for now
|
||||
Ok(rustls::ServerCertVerified::assertion())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue