#[cfg(any(windows, target_vendor = "apple"))]
use std::sync::Arc;
#[cfg(all(
any(unix, target_arch = "wasm32"),
not(target_os = "android"),
not(target_vendor = "apple"),
))]
mod others;
#[cfg(all(
any(unix, target_arch = "wasm32"),
not(target_os = "android"),
not(target_vendor = "apple"),
))]
pub use others::Verifier;
#[cfg(target_vendor = "apple")]
mod apple;
#[cfg(target_vendor = "apple")]
pub use apple::Verifier;
#[cfg(target_os = "android")]
pub(crate) mod android;
#[cfg(target_os = "android")]
pub use android::Verifier;
#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub use windows::Verifier;
#[cfg_attr(windows, allow(dead_code))] #[derive(Debug, PartialEq)]
pub(crate) struct EkuError;
impl std::fmt::Display for EkuError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("certificate had invalid extensions")
}
}
impl std::error::Error for EkuError {}
fn log_server_cert(_end_entity: &rustls::pki_types::CertificateDer<'_>) {
#[cfg(feature = "cert-logging")]
{
use base64::Engine;
log::debug!(
"verifying certificate: {}",
base64::engine::general_purpose::STANDARD.encode(_end_entity.as_ref())
);
}
}
#[cfg(any(windows, target_vendor = "apple"))]
fn invalid_certificate(reason: impl Into<String>) -> rustls::Error {
rustls::Error::InvalidCertificate(rustls::CertificateError::Other(rustls::OtherError(
Arc::from(Box::from(reason.into())),
)))
}
#[cfg(target_os = "windows")]
const ALLOWED_EKUS: &[windows_sys::core::PCSTR] =
&[windows_sys::Win32::Security::Cryptography::szOID_PKIX_KP_SERVER_AUTH];
#[cfg(target_os = "android")]
pub const ALLOWED_EKUS: &[&std::ffi::CStr] = &[c"1.3.6.1.5.5.7.3.1"];