/// Validate a given hostname using peer certificate. This function returns
/// true if there is no CN record or the CN record matches with the given
/// hostname. False is returned if there is no certificate or the hostname does
/// not match.
Validate a given hostname using peer certificate. This function returns
true if there is no CN record or the CN record matches with the given
hostname. False is returned if there is no certificate or the hostname does
not match.
Validate a given hostname using peer certificate . This function returns true if there is no CN record or the CN record matches with the given hostname . False is returned if there is no certificate or the hostname does not match .
fn validate_hostname(x509_ctx: &X509StoreContext, hostname: &str) -> bool {
    if let Some(cert) = x509_ctx.get_current_cert() {
        let subject_name = cert.subject_name();
        if let Some(cn) = subject_name.text_by_nid(Nid::CN) {
            let re = "^".to_string()
                + &cn.replace(r".", r"\.")
                    .replace(r"*", r"\S+")
                + "$";
            if let Ok(re) = Regex::new(&re) {
                re.is_match(hostname)
            } else {
                false
            }
        } else {
            true
        }
    } else {
        false
    }
}
fn validate_hostname ( x509_ctx : & X509StoreContext , hostname : & str ) -> bool { if let Some ( cert ) = x509_ctx . get_current_cert ( ) { let subject_name = cert . subject_name ( ) ; if let Some ( cn ) = subject_name . text_by_nid ( Nid :: CN ) { let re = " " . to_string ( ) + & cn . replace ( r"." , r"\." ) . replace ( r"*" , r"\S+" ) + " " ; if let Ok ( re ) = Regex :: new ( & re ) { re . is_match ( hostname ) } else { false } } else { true } } else { false } }
Validate a given hostname using peer certificate.
Validate a given hostname using peer certificate .
x509_ctx
&X509StoreContext
hostname
&str