2013-04-08 11 views
6

posso ottenere il nome alternativo soggetto comeCome recuperare emittente nome alternativo per il certificato SSL OpenSSL

X509_NAME_get_text_by_NID(X509_get_subject_name(x), NID_subject_alt_name, hc->https_domain_name, 256) 

Con lo stesso metodo, cambiando 2. parametro NID_issuer_alt_name mi aspetto di ottenere il nome dell'emittente simili;

X509_NAME_get_text_by_NID(X509_get_subject_name(x), NID_issuer_alt_name, hc->https_ca_name, 256); 

Invece sto ricevendo una stringa vuota. Come posso recuperare correttamente il nome alternativo dell'emittente?

+1

Controllare se il certificato specificato ha il nome alternativo dell'emittente. Penso che sia un'estensione. – doptimusprime

+2

Dovresti ** non ** usare 'X509_NAME_get_text_by_NID' perché soffre dei trucchi' NULL' di Marlinspike incorporati. Dai documenti OpenSSL (che non menzionano la vulnerabilità): "È necessario utilizzare" X509_NAME_get_index_by_NID' o "X509_NAME_get_index_by_OBJ' seguito da" X509_NAME_get_entry' " – jww

+0

Vedere anche la pagina wiki di OpenSSL su [Hostname Validation] (https: //wiki.openssl. org/index.php/Hostname_validation). – jww

risposta

7

si potrebbe provare la seguente soluzione, come raccomandato nel https://github.com/iSECPartners/ssl-conservatory:

static HostnameValidationResult matches_subject_alternative_name (const char *hostname, const X509 *server_cert) { 
    HostnameValidationResult result = MatchNotFound; 
    int i; 
    int san_names_nb = -1; 
    STACK_OF(GENERAL_NAME) *san_names = NULL; 

    // Try to extract the names within the SAN extension from the certificate 
    san_names = X509_get_ext_d2i((X509 *) server_cert, NID_subject_alt_name, NULL, NULL); 
    if (san_names == NULL) { 
     return NoSANPresent; 
    } 
    san_names_nb = sk_GENERAL_NAME_num(san_names); 

    // Check each name within the extension 
    for (i=0; i<san_names_nb; i++) { 
     const GENERAL_NAME *current_name = sk_GENERAL_NAME_value(san_names, i); 

     if (current_name->type == GEN_DNS) { 
      // Current name is a DNS name, let's check it 
      char *dns_name = (char *) ASN1_STRING_data(current_name->d.dNSName); 

      // Make sure there isn't an embedded NUL character in the DNS name 
      if (ASN1_STRING_length(current_name->d.dNSName) != strlen(dns_name)) { 
       result = MalformedCertificate; 
       break; 
      } 
      else { // Compare expected hostname with the DNS name 
       if (strcasecmp(hostname, dns_name) == 0) { 
        result = MatchFound; 
        break; 
       } 
      } 
     } 
    } 
    sk_GENERAL_NAME_pop_free(san_names, GENERAL_NAME_free); 

    return result; 
} 

Speranza che aiuta!

+0

Come ho capito, questo è per ottenere il nome alternativo del soggetto. Ho bisogno del nome alternativo dell'emittente. –

+0

Prova a sostituire 'NID_subject_alt_name' con' NID_issuer_alt_name', proverò a farlo sul mio PC adesso e vedrò come funziona per me. – Paul

+0

Intendi proprio così, X509_get_ext_d2i ((X509 *) server_cert, NID_issuer_alt_name, NULL, NULL). Ho provato la corda ancora vuota, grazie per il consiglio però. –

0

Nella tua chiamata a X509_NAME_get_text_by_NID con la costante NID_issuer_alt_name, avrei sostituito X509_get_subject_name (x) con X509_get_issuer_name (x). Penso che questo dovrebbe fare il trucco che cerchi.

Problemi correlati