* Return an array of subjectAltName entries of type "type". If idx is -1, * return all entries of the given type, otherwise return an array consisting * of the n-th occurrence of that type only. Currently supported types: * GEN_EMAIL (rfc822Name) * GEN_DNS (dNSName) * GEN_OTHERNAME (requires the otherName form ["onf"] argument to be supplied, * see parse_otherName_value for th
| 294 | * see parse_otherName_value for the currently supported forms) |
| 295 | */ |
| 296 | BOOL modssl_X509_getSAN(apr_pool_t *p, X509 *x509, int type, const char *onf, |
| 297 | int idx, apr_array_header_t **entries) |
| 298 | { |
| 299 | STACK_OF(GENERAL_NAME) *names; |
| 300 | int nid = onf ? OBJ_txt2nid(onf) : NID_undef; |
| 301 | |
| 302 | if (!x509 || (type < GEN_OTHERNAME) || |
| 303 | ((type == GEN_OTHERNAME) && (nid == NID_undef)) || |
| 304 | (type > GEN_RID) || (idx < -1) || |
| 305 | !(*entries = apr_array_make(p, 0, sizeof(char *)))) { |
| 306 | *entries = NULL; |
| 307 | return FALSE; |
| 308 | } |
| 309 | |
| 310 | if ((names = X509_get_ext_d2i(x509, NID_subject_alt_name, NULL, NULL))) { |
| 311 | int i, n = 0; |
| 312 | GENERAL_NAME *name; |
| 313 | const char *utf8str; |
| 314 | |
| 315 | for (i = 0; i < sk_GENERAL_NAME_num(names); i++) { |
| 316 | name = sk_GENERAL_NAME_value(names, i); |
| 317 | |
| 318 | if (name->type != type) |
| 319 | continue; |
| 320 | |
| 321 | switch (type) { |
| 322 | case GEN_EMAIL: |
| 323 | case GEN_DNS: |
| 324 | if (((idx == -1) || (n == idx)) && |
| 325 | (utf8str = asn1_string_to_utf8(p, name->d.ia5))) { |
| 326 | APR_ARRAY_PUSH(*entries, const char *) = utf8str; |
| 327 | } |
| 328 | n++; |
| 329 | break; |
| 330 | case GEN_OTHERNAME: |
| 331 | if (OBJ_obj2nid(name->d.otherName->type_id) == nid) { |
| 332 | if (((idx == -1) || (n == idx))) { |
| 333 | parse_otherName_value(p, name->d.otherName->value, |
| 334 | onf, entries); |
| 335 | } |
| 336 | n++; |
| 337 | } |
| 338 | break; |
| 339 | default: |
| 340 | /* |
| 341 | * Not implemented right now: |
| 342 | * GEN_X400 (x400Address) |
| 343 | * GEN_DIRNAME (directoryName) |
| 344 | * GEN_EDIPARTY (ediPartyName) |
| 345 | * GEN_URI (uniformResourceIdentifier) |
| 346 | * GEN_IPADD (iPAddress) |
| 347 | * GEN_RID (registeredID) |
| 348 | */ |
| 349 | break; |
| 350 | } |
| 351 | |
| 352 | if ((idx != -1) && (n > idx)) |
| 353 | break; |
no test coverage detected