13  STACK_OF(GENERAL_NAME) *extensions;
 
   14  const GENERAL_NAME *ext;
 
   22  cert = SSL_get_peer_certificate(ssl); 
 
   25  if (SSL_get_verify_result(ssl) != X509_V_OK) 
return -2;
 
   28    if (!stralloc_copys(dnsout,
"")) 
return 1;
 
   29    extensions = X509_get_ext_d2i(
cert,NID_subject_alt_name,0,0);
 
   30    num = sk_GENERAL_NAME_num(extensions);      
 
   32    for (i = 0; i < num; ++i) {
 
   33      ext = sk_GENERAL_NAME_value(extensions,i);
 
   34      if (ext->type == GEN_DNS) {
 
   35        if (ASN1_STRING_type(ext->d.dNSName) != V_ASN1_IA5STRING) 
continue;
 
   36        dnsname = (
char *)ASN1_STRING_get0_data(ext->d.dNSName);
 
   37        len = ASN1_STRING_length(ext->d.dNSName);
 
   38        if (len != str_len(dnsname)) 
continue;
 
   39        if (!stralloc_copyb(dnsout,dnsname,len)) 
return 1; 
 
   40        if (case_diffs((
char *)
hostname,dnsname) == 0) 
return 0;
 
   46      X509_NAME_get_text_by_NID(X509_get_subject_name(
cert),NID_commonName,
buf,
sizeof(
buf));
 
   48      if (!stralloc_copyb(dnsout,
buf,str_len(
buf))) 
return 1; 
 
   49      if (case_diffs((
char *)
hostname,
buf) == 0) 
return 0;