13 STACK_OF(GENERAL_NAME) *extensions;
14 const GENERAL_NAME *ext;
22 #if (OPENSSL_VERSION_NUMBER > 0x30000000L)
23 cert = SSL_get_peer_cert_chain(ssl);
25 cert = SSL_get_peer_certificate(ssl);
29 if (SSL_get_verify_result(ssl) != X509_V_OK)
return -2;
32 if (!stralloc_copys(dnsout,
""))
return 1;
33 extensions = X509_get_ext_d2i(
cert,NID_subject_alt_name,0,0);
34 num = sk_GENERAL_NAME_num(extensions);
36 for (i = 0; i < num; ++i) {
37 ext = sk_GENERAL_NAME_value(extensions,i);
38 if (ext->type == GEN_DNS) {
39 if (ASN1_STRING_type(ext->d.dNSName) != V_ASN1_IA5STRING)
continue;
40 #if ((OPENSSL_VERSION_NUMBER < 0x10100000L) || (LIBRESSL_VERSION_NUMBER > 0 && LIBRESSL_VERSION_NUMBER < 0x20700000L))
41 dnsname = (
char *)ASN1_STRING_data(ext->d.dNSName);
43 dnsname = (
char *)ASN1_STRING_get0_data(ext->d.dNSName);
45 len = ASN1_STRING_length(ext->d.dNSName);
46 if (len != str_len(dnsname))
continue;
47 if (!stralloc_copyb(dnsout,dnsname,len))
return 1;
48 if (case_diffs((
char *)
hostname,dnsname) == 0)
return 0;
54 X509_NAME_get_text_by_NID(X509_get_subject_name(
cert),NID_commonName,
buf,
sizeof(
buf));
56 if (!stralloc_copyb(dnsout,
buf,str_len(
buf)))
return 1;
57 if (case_diffs((
char *)
hostname,
buf) == 0)
return 0;
int ssl_verify(SSL *ssl, const char *hostname, stralloc *dnsout)
Header file to be used with sqmail; previously called ssl.h. (name clash)