| 283 | } |
| 284 | |
| 285 | EMatchResult MatchCertAltNames(X509* cert, TStringBuf hostname) { |
| 286 | EMatchResult result = NO_MATCH; |
| 287 | STACK_OF(GENERAL_NAME)* names = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, NULL); |
| 288 | if (!names) { |
| 289 | return NO_EXTENSION; |
| 290 | } |
| 291 | |
| 292 | int namesCt = sk_GENERAL_NAME_num(names); |
| 293 | for (int i = 0; i < namesCt; ++i) { |
| 294 | const GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i); |
| 295 | |
| 296 | if (name->type == GEN_DNS) { |
| 297 | TStringBuf dnsName((const char*)ASN1_STRING_get0_data(name->d.dNSName), ASN1_STRING_length(name->d.dNSName)); |
| 298 | if (MatchDomainName(dnsName, hostname)) { |
| 299 | result = MATCH_FOUND; |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); |
| 305 | return result; |
| 306 | } |
| 307 | |
| 308 | EMatchResult MatchCertCommonName(X509* cert, TStringBuf hostname) { |
| 309 | int commonNameLoc = X509_NAME_get_index_by_NID(X509_get_subject_name(cert), NID_commonName, -1); |
no test coverage detected