| 1 |
// Written by Dr Stephen N Henson ([email protected]) for the OpenSSL project. |
| 2 |
// Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved. |
| 3 |
// SPDX-License-Identifier: Apache-2.0 |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
#include <openssl/conf.h> |
| 9 |
#include <openssl/err.h> |
| 10 |
#include <openssl/mem.h> |
| 11 |
#include <openssl/obj.h> |
| 12 |
#include <openssl/x509.h> |
| 13 |
|
| 14 |
#include "internal.h" |
| 15 |
|
| 16 |
|
| 17 |
static void *v2i_subject_alt(const X509V3_EXT_METHOD *method, |
| 18 |
const X509V3_CTX *ctx, |
| 19 |
const STACK_OF(CONF_VALUE) *nval); |
| 20 |
static void *v2i_issuer_alt(const X509V3_EXT_METHOD *method, |
| 21 |
const X509V3_CTX *ctx, |
| 22 |
const STACK_OF(CONF_VALUE) *nval); |
| 23 |
static int copy_email(const X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p); |
| 24 |
static int copy_issuer(const X509V3_CTX *ctx, GENERAL_NAMES *gens); |
| 25 |
static int do_othername(GENERAL_NAME *gen, const char *value, |
| 26 |
const X509V3_CTX *ctx); |
| 27 |
static int do_dirname(GENERAL_NAME *gen, const char *value, |
| 28 |
const X509V3_CTX *ctx); |
| 29 |
|
| 30 |
static STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES_cb( |
| 31 |
const X509V3_EXT_METHOD *method, void *ext, STACK_OF(CONF_VALUE) *ret) { |
| 32 |
return i2v_GENERAL_NAMES(method, ext, ret); |
| 33 |
} |
| 34 |
|
| 35 |
const X509V3_EXT_METHOD v3_alt[] = { |
| 36 |
{NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES), 0, 0, 0, 0, 0, 0, |
| 37 |
i2v_GENERAL_NAMES_cb, v2i_subject_alt, NULL, NULL, NULL}, |
| 38 |
|
| 39 |
{NID_issuer_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES), 0, 0, 0, 0, 0, 0, |
| 40 |
i2v_GENERAL_NAMES_cb, v2i_issuer_alt, NULL, NULL, NULL}, |
| 41 |
|
| 42 |
{NID_certificate_issuer, 0, ASN1_ITEM_ref(GENERAL_NAMES), 0, 0, 0, 0, 0, 0, |
| 43 |
i2v_GENERAL_NAMES_cb, NULL, NULL, NULL, NULL}, |
| 44 |
}; |
| 45 |
|
| 46 |
STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(const X509V3_EXT_METHOD *method, |
| 47 |
const GENERAL_NAMES *gens, |
| 48 |
STACK_OF(CONF_VALUE) *ret) { |
| 49 |
int ret_was_null = ret == NULL; |
| 50 |
for (size_t i = 0; i < sk_GENERAL_NAME_num(gens); i++) { |
| 51 |
const GENERAL_NAME *gen = sk_GENERAL_NAME_value(gens, i); |
| 52 |
STACK_OF(CONF_VALUE) *tmp = i2v_GENERAL_NAME(method, gen, ret); |
| 53 |
if (tmp == NULL) { |
| 54 |
if (ret_was_null) { |
| 55 |
sk_CONF_VALUE_pop_free(ret, X509V3_conf_free); |
| 56 |
} |
| 57 |
return NULL; |
| 58 |
} |
| 59 |
ret = tmp; |
| 60 |
} |
| 61 |
if (!ret) { |
| 62 |
return sk_CONF_VALUE_new_null(); |
| 63 |
} |
| 64 |
return ret; |
| 65 |
} |
| 66 |
|
| 67 |
STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(const X509V3_EXT_METHOD *method, |
| 68 |
const GENERAL_NAME *gen, |
| 69 |
STACK_OF(CONF_VALUE) *ret) { |
| 70 |
// Note the error-handling for this function relies on there being at most |
| 71 |
// one |X509V3_add_value| call. If there were two and the second failed, we |
| 72 |
// would need to sometimes free the first call's result. |
| 73 |
unsigned char *p; |
| 74 |
char oline[256], htmp[5]; |
| 75 |
int i; |
| 76 |
switch (gen->type) { |
| 77 |
case GEN_OTHERNAME: |
| 78 |
if (!X509V3_add_value("othername", "<unsupported>", &ret)) { |
| 79 |
return NULL; |
| 80 |
} |
| 81 |
break; |
| 82 |
|
| 83 |
case GEN_X400: |
| 84 |
if (!X509V3_add_value("X400Name", "<unsupported>", &ret)) { |
| 85 |
return NULL; |
| 86 |
} |
| 87 |
break; |
| 88 |
|
| 89 |
case GEN_EDIPARTY: |
| 90 |
if (!X509V3_add_value("EdiPartyName", "<unsupported>", &ret)) { |
| 91 |
return NULL; |
| 92 |
} |
| 93 |
break; |
| 94 |
|
| 95 |
case GEN_EMAIL: |
| 96 |
if (!x509V3_add_value_asn1_string("email", gen->d.ia5, &ret)) { |
| 97 |
return NULL; |
| 98 |
} |
| 99 |
break; |
| 100 |
|
| 101 |
case GEN_DNS: |
| 102 |
if (!x509V3_add_value_asn1_string("DNS", gen->d.ia5, &ret)) { |
| 103 |
return NULL; |
| 104 |
} |
| 105 |
break; |
| 106 |
|
| 107 |
case GEN_URI: |
| 108 |
if (!x509V3_add_value_asn1_string("URI", gen->d.ia5, &ret)) { |
| 109 |
return NULL; |
| 110 |
} |
| 111 |
break; |
| 112 |
|
| 113 |
case GEN_DIRNAME: |
| 114 |
if (X509_NAME_oneline(gen->d.dirn, oline, 256) == NULL || |
| 115 |
!X509V3_add_value("DirName", oline, &ret)) { |
| 116 |
return NULL; |
| 117 |
} |
| 118 |
break; |
| 119 |
|
| 120 |
case GEN_IPADD: |
| 121 |
p = gen->d.ip->data; |
| 122 |
if (gen->d.ip->length == 4) { |
| 123 |
snprintf(oline, sizeof(oline), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); |
| 124 |
} else if (gen->d.ip->length == 16) { |
| 125 |
oline[0] = 0; |
| 126 |
for (i = 0; i < 8; i++) { |
| 127 |
uint16_t v = ((uint16_t)p[0] << 8) | p[1]; |
| 128 |
snprintf(htmp, sizeof(htmp), "%X", v); |
| 129 |
p += 2; |
| 130 |
OPENSSL_strlcat(oline, htmp, sizeof(oline)); |
| 131 |
if (i != 7) { |
| 132 |
OPENSSL_strlcat(oline, ":", sizeof(oline)); |
| 133 |
} |
| 134 |
} |
| 135 |
} else { |
| 136 |
if (!X509V3_add_value("IP Address", "<invalid>", &ret)) { |
| 137 |
return NULL; |
| 138 |
} |
| 139 |
break; |
| 140 |
} |
| 141 |
if (!X509V3_add_value("IP Address", oline, &ret)) { |
| 142 |
return NULL; |
| 143 |
} |
| 144 |
break; |
| 145 |
|
| 146 |
case GEN_RID: |
| 147 |
i2t_ASN1_OBJECT(oline, 256, gen->d.rid); |
| 148 |
if (!X509V3_add_value("Registered ID", oline, &ret)) { |
| 149 |
return NULL; |
| 150 |
} |
| 151 |
break; |
| 152 |
} |
| 153 |
return ret; |
| 154 |
} |
| 155 |
|
| 156 |
int GENERAL_NAME_print(BIO *out, const GENERAL_NAME *gen) { |
| 157 |
switch (gen->type) { |
| 158 |
case GEN_OTHERNAME: |
| 159 |
BIO_printf(out, "othername:<unsupported>"); |
| 160 |
break; |
| 161 |
|
| 162 |
case GEN_X400: |
| 163 |
BIO_printf(out, "X400Name:<unsupported>"); |
| 164 |
break; |
| 165 |
|
| 166 |
case GEN_EDIPARTY: |
| 167 |
// Maybe fix this: it is supported now |
| 168 |
BIO_printf(out, "EdiPartyName:<unsupported>"); |
| 169 |
break; |
| 170 |
|
| 171 |
case GEN_EMAIL: |
| 172 |
BIO_printf(out, "email:"); |
| 173 |
ASN1_STRING_print(out, gen->d.ia5); |
| 174 |
break; |
| 175 |
|
| 176 |
case GEN_DNS: |
| 177 |
BIO_printf(out, "DNS:"); |
| 178 |
ASN1_STRING_print(out, gen->d.ia5); |
| 179 |
break; |
| 180 |
|
| 181 |
case GEN_URI: |
| 182 |
BIO_printf(out, "URI:"); |
| 183 |
ASN1_STRING_print(out, gen->d.ia5); |
| 184 |
break; |
| 185 |
|
| 186 |
case GEN_DIRNAME: |
| 187 |
BIO_printf(out, "DirName: "); |
| 188 |
X509_NAME_print_ex(out, gen->d.dirn, 0, XN_FLAG_ONELINE); |
| 189 |
break; |
| 190 |
|
| 191 |
case GEN_IPADD: { |
| 192 |
const unsigned char *p = gen->d.ip->data; |
| 193 |
if (gen->d.ip->length == 4) { |
| 194 |
BIO_printf(out, "IP Address:%d.%d.%d.%d", p[0], p[1], p[2], p[3]); |
| 195 |
} else if (gen->d.ip->length == 16) { |
| 196 |
BIO_printf(out, "IP Address"); |
| 197 |
for (int i = 0; i < 8; i++) { |
| 198 |
uint16_t v = ((uint16_t)p[0] << 8) | p[1]; |
| 199 |
BIO_printf(out, ":%X", v); |
| 200 |
p += 2; |
| 201 |
} |
| 202 |
BIO_puts(out, "\n"); |
| 203 |
} else { |
| 204 |
BIO_printf(out, "IP Address:<invalid>"); |
| 205 |
break; |
| 206 |
} |
| 207 |
break; |
| 208 |
} |
| 209 |
|
| 210 |
case GEN_RID: |
| 211 |
BIO_printf(out, "Registered ID"); |
| 212 |
i2a_ASN1_OBJECT(out, gen->d.rid); |
| 213 |
break; |
| 214 |
} |
| 215 |
return 1; |
| 216 |
} |
| 217 |
|
| 218 |
static void *v2i_issuer_alt(const X509V3_EXT_METHOD *method, |
| 219 |
const X509V3_CTX *ctx, |
| 220 |
const STACK_OF(CONF_VALUE) *nval) { |
| 221 |
GENERAL_NAMES *gens = sk_GENERAL_NAME_new_null(); |
| 222 |
if (gens == NULL) { |
| 223 |
return NULL; |
| 224 |
} |
| 225 |
for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 226 |
const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i); |
| 227 |
if (x509v3_conf_name_matches(cnf->name, "issuer") && cnf->value && |
| 228 |
!strcmp(cnf->value, "copy")) { |
| 229 |
if (!copy_issuer(ctx, gens)) { |
| 230 |
goto err; |
| 231 |
} |
| 232 |
} else { |
| 233 |
GENERAL_NAME *gen = v2i_GENERAL_NAME(method, ctx, cnf); |
| 234 |
if (gen == NULL || !sk_GENERAL_NAME_push(gens, gen)) { |
| 235 |
GENERAL_NAME_free(gen); |
| 236 |
goto err; |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
return gens; |
| 241 |
err: |
| 242 |
sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); |
| 243 |
return NULL; |
| 244 |
} |
| 245 |
|
| 246 |
// Append subject altname of issuer to issuer alt name of subject |
| 247 |
|
| 248 |
static int copy_issuer(const X509V3_CTX *ctx, GENERAL_NAMES *gens) { |
| 249 |
if (ctx && (ctx->flags == X509V3_CTX_TEST)) { |
| 250 |
return 1; |
| 251 |
} |
| 252 |
if (!ctx || !ctx->issuer_cert) { |
| 253 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_NO_ISSUER_DETAILS); |
| 254 |
return 0; |
| 255 |
} |
| 256 |
int i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1); |
| 257 |
if (i < 0) { |
| 258 |
return 1; |
| 259 |
} |
| 260 |
|
| 261 |
int ret = 0; |
| 262 |
GENERAL_NAMES *ialt = NULL; |
| 263 |
X509_EXTENSION *ext; |
| 264 |
if (!(ext = X509_get_ext(ctx->issuer_cert, i)) || |
| 265 |
!(ialt = X509V3_EXT_d2i(ext))) { |
| 266 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ISSUER_DECODE_ERROR); |
| 267 |
goto err; |
| 268 |
} |
| 269 |
|
| 270 |
for (size_t j = 0; j < sk_GENERAL_NAME_num(ialt); j++) { |
| 271 |
GENERAL_NAME *gen = sk_GENERAL_NAME_value(ialt, j); |
| 272 |
if (!sk_GENERAL_NAME_push(gens, gen)) { |
| 273 |
goto err; |
| 274 |
} |
| 275 |
// Ownership of |gen| has moved from |ialt| to |gens|. |
| 276 |
sk_GENERAL_NAME_set(ialt, j, NULL); |
| 277 |
} |
| 278 |
|
| 279 |
ret = 1; |
| 280 |
|
| 281 |
err: |
| 282 |
GENERAL_NAMES_free(ialt); |
| 283 |
return ret; |
| 284 |
} |
| 285 |
|
| 286 |
static void *v2i_subject_alt(const X509V3_EXT_METHOD *method, |
| 287 |
const X509V3_CTX *ctx, |
| 288 |
const STACK_OF(CONF_VALUE) *nval) { |
| 289 |
GENERAL_NAMES *gens = sk_GENERAL_NAME_new_null(); |
| 290 |
if (gens == NULL) { |
| 291 |
return NULL; |
| 292 |
} |
| 293 |
for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 294 |
const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i); |
| 295 |
if (x509v3_conf_name_matches(cnf->name, "email") && cnf->value && |
| 296 |
!strcmp(cnf->value, "copy")) { |
| 297 |
if (!copy_email(ctx, gens, 0)) { |
| 298 |
goto err; |
| 299 |
} |
| 300 |
} else if (x509v3_conf_name_matches(cnf->name, "email") && cnf->value && |
| 301 |
!strcmp(cnf->value, "move")) { |
| 302 |
if (!copy_email(ctx, gens, 1)) { |
| 303 |
goto err; |
| 304 |
} |
| 305 |
} else { |
| 306 |
GENERAL_NAME *gen = v2i_GENERAL_NAME(method, ctx, cnf); |
| 307 |
if (gen == NULL || !sk_GENERAL_NAME_push(gens, gen)) { |
| 308 |
GENERAL_NAME_free(gen); |
| 309 |
goto err; |
| 310 |
} |
| 311 |
} |
| 312 |
} |
| 313 |
return gens; |
| 314 |
err: |
| 315 |
sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); |
| 316 |
return NULL; |
| 317 |
} |
| 318 |
|
| 319 |
// Copy any email addresses in a certificate or request to GENERAL_NAMES |
| 320 |
|
| 321 |
static int copy_email(const X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p) { |
| 322 |
X509_NAME *nm; |
| 323 |
ASN1_IA5STRING *email = NULL; |
| 324 |
X509_NAME_ENTRY *ne; |
| 325 |
GENERAL_NAME *gen = NULL; |
| 326 |
int i; |
| 327 |
if (ctx != NULL && ctx->flags == X509V3_CTX_TEST) { |
| 328 |
return 1; |
| 329 |
} |
| 330 |
if (!ctx || (!ctx->subject_cert && !ctx->subject_req)) { |
| 331 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_NO_SUBJECT_DETAILS); |
| 332 |
goto err; |
| 333 |
} |
| 334 |
// Find the subject name |
| 335 |
if (ctx->subject_cert) { |
| 336 |
nm = X509_get_subject_name(ctx->subject_cert); |
| 337 |
} else { |
| 338 |
nm = X509_REQ_get_subject_name(ctx->subject_req); |
| 339 |
} |
| 340 |
|
| 341 |
// Now add any email address(es) to STACK |
| 342 |
i = -1; |
| 343 |
while ((i = X509_NAME_get_index_by_NID(nm, NID_pkcs9_emailAddress, i)) >= 0) { |
| 344 |
ne = X509_NAME_get_entry(nm, i); |
| 345 |
email = ASN1_STRING_dup(X509_NAME_ENTRY_get_data(ne)); |
| 346 |
if (move_p) { |
| 347 |
X509_NAME_delete_entry(nm, i); |
| 348 |
X509_NAME_ENTRY_free(ne); |
| 349 |
i--; |
| 350 |
} |
| 351 |
if (!email || !(gen = GENERAL_NAME_new())) { |
| 352 |
goto err; |
| 353 |
} |
| 354 |
gen->d.ia5 = email; |
| 355 |
email = NULL; |
| 356 |
gen->type = GEN_EMAIL; |
| 357 |
if (!sk_GENERAL_NAME_push(gens, gen)) { |
| 358 |
goto err; |
| 359 |
} |
| 360 |
gen = NULL; |
| 361 |
} |
| 362 |
|
| 363 |
return 1; |
| 364 |
|
| 365 |
err: |
| 366 |
GENERAL_NAME_free(gen); |
| 367 |
ASN1_IA5STRING_free(email); |
| 368 |
return 0; |
| 369 |
} |
| 370 |
|
| 371 |
GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, |
| 372 |
const X509V3_CTX *ctx, |
| 373 |
const STACK_OF(CONF_VALUE) *nval) { |
| 374 |
GENERAL_NAMES *gens = sk_GENERAL_NAME_new_null(); |
| 375 |
if (gens == NULL) { |
| 376 |
return NULL; |
| 377 |
} |
| 378 |
for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
| 379 |
const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i); |
| 380 |
GENERAL_NAME *gen = v2i_GENERAL_NAME(method, ctx, cnf); |
| 381 |
if (gen == NULL || !sk_GENERAL_NAME_push(gens, gen)) { |
| 382 |
GENERAL_NAME_free(gen); |
| 383 |
goto err; |
| 384 |
} |
| 385 |
} |
| 386 |
return gens; |
| 387 |
err: |
| 388 |
sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); |
| 389 |
return NULL; |
| 390 |
} |
| 391 |
|
| 392 |
GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, |
| 393 |
const X509V3_CTX *ctx, const CONF_VALUE *cnf) { |
| 394 |
return v2i_GENERAL_NAME_ex(NULL, method, ctx, cnf, 0); |
| 395 |
} |
| 396 |
|
| 397 |
static GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out, |
| 398 |
const X509V3_EXT_METHOD *method, |
| 399 |
const X509V3_CTX *ctx, int gen_type, |
| 400 |
const char *value, int is_nc) { |
| 401 |
if (!value) { |
| 402 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_MISSING_VALUE); |
| 403 |
return NULL; |
| 404 |
} |
| 405 |
|
| 406 |
GENERAL_NAME *gen = NULL; |
| 407 |
if (out) { |
| 408 |
gen = out; |
| 409 |
} else { |
| 410 |
gen = GENERAL_NAME_new(); |
| 411 |
if (gen == NULL) { |
| 412 |
return NULL; |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
switch (gen_type) { |
| 417 |
case GEN_URI: |
| 418 |
case GEN_EMAIL: |
| 419 |
case GEN_DNS: { |
| 420 |
ASN1_IA5STRING *str = ASN1_IA5STRING_new(); |
| 421 |
if (str == NULL || !ASN1_STRING_set(str, value, strlen(value))) { |
| 422 |
ASN1_STRING_free(str); |
| 423 |
goto err; |
| 424 |
} |
| 425 |
gen->type = gen_type; |
| 426 |
gen->d.ia5 = str; |
| 427 |
break; |
| 428 |
} |
| 429 |
|
| 430 |
case GEN_RID: { |
| 431 |
ASN1_OBJECT *obj; |
| 432 |
if (!(obj = OBJ_txt2obj(value, 0))) { |
| 433 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_BAD_OBJECT); |
| 434 |
ERR_add_error_data(2, "value=", value); |
| 435 |
goto err; |
| 436 |
} |
| 437 |
gen->type = GEN_RID; |
| 438 |
gen->d.rid = obj; |
| 439 |
break; |
| 440 |
} |
| 441 |
|
| 442 |
case GEN_IPADD: |
| 443 |
gen->type = GEN_IPADD; |
| 444 |
if (is_nc) { |
| 445 |
gen->d.ip = a2i_IPADDRESS_NC(value); |
| 446 |
} else { |
| 447 |
gen->d.ip = a2i_IPADDRESS(value); |
| 448 |
} |
| 449 |
if (gen->d.ip == NULL) { |
| 450 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_BAD_IP_ADDRESS); |
| 451 |
ERR_add_error_data(2, "value=", value); |
| 452 |
goto err; |
| 453 |
} |
| 454 |
break; |
| 455 |
|
| 456 |
case GEN_DIRNAME: |
| 457 |
if (!do_dirname(gen, value, ctx)) { |
| 458 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_DIRNAME_ERROR); |
| 459 |
goto err; |
| 460 |
} |
| 461 |
break; |
| 462 |
|
| 463 |
case GEN_OTHERNAME: |
| 464 |
if (!do_othername(gen, value, ctx)) { |
| 465 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_OTHERNAME_ERROR); |
| 466 |
goto err; |
| 467 |
} |
| 468 |
break; |
| 469 |
default: |
| 470 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNSUPPORTED_TYPE); |
| 471 |
goto err; |
| 472 |
} |
| 473 |
|
| 474 |
return gen; |
| 475 |
|
| 476 |
err: |
| 477 |
if (!out) { |
| 478 |
GENERAL_NAME_free(gen); |
| 479 |
} |
| 480 |
return NULL; |
| 481 |
} |
| 482 |
|
| 483 |
GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, |
| 484 |
const X509V3_EXT_METHOD *method, |
| 485 |
const X509V3_CTX *ctx, const CONF_VALUE *cnf, |
| 486 |
int is_nc) { |
| 487 |
const char *name = cnf->name; |
| 488 |
const char *value = cnf->value; |
| 489 |
if (!value) { |
| 490 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_MISSING_VALUE); |
| 491 |
return NULL; |
| 492 |
} |
| 493 |
|
| 494 |
int type; |
| 495 |
if (x509v3_conf_name_matches(name, "email")) { |
| 496 |
type = GEN_EMAIL; |
| 497 |
} else if (x509v3_conf_name_matches(name, "URI")) { |
| 498 |
type = GEN_URI; |
| 499 |
} else if (x509v3_conf_name_matches(name, "DNS")) { |
| 500 |
type = GEN_DNS; |
| 501 |
} else if (x509v3_conf_name_matches(name, "RID")) { |
| 502 |
type = GEN_RID; |
| 503 |
} else if (x509v3_conf_name_matches(name, "IP")) { |
| 504 |
type = GEN_IPADD; |
| 505 |
} else if (x509v3_conf_name_matches(name, "dirName")) { |
| 506 |
type = GEN_DIRNAME; |
| 507 |
} else if (x509v3_conf_name_matches(name, "otherName")) { |
| 508 |
type = GEN_OTHERNAME; |
| 509 |
} else { |
| 510 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNSUPPORTED_OPTION); |
| 511 |
ERR_add_error_data(2, "name=", name); |
| 512 |
return NULL; |
| 513 |
} |
| 514 |
|
| 515 |
return a2i_GENERAL_NAME(out, method, ctx, type, value, is_nc); |
| 516 |
} |
| 517 |
|
| 518 |
static int do_othername(GENERAL_NAME *gen, const char *value, |
| 519 |
const X509V3_CTX *ctx) { |
| 520 |
const char *semicolon = strchr(value, ';'); |
| 521 |
if (semicolon == NULL) { |
| 522 |
return 0; |
| 523 |
} |
| 524 |
|
| 525 |
OTHERNAME *name = OTHERNAME_new(); |
| 526 |
if (name == NULL) { |
| 527 |
return 0; |
| 528 |
} |
| 529 |
|
| 530 |
char *objtmp = OPENSSL_strndup(value, semicolon - value); |
| 531 |
if (objtmp == NULL) { |
| 532 |
goto err; |
| 533 |
} |
| 534 |
ASN1_OBJECT_free(name->type_id); |
| 535 |
name->type_id = OBJ_txt2obj(objtmp, /*dont_search_names=*/0); |
| 536 |
OPENSSL_free(objtmp); |
| 537 |
if (name->type_id == NULL) { |
| 538 |
goto err; |
| 539 |
} |
| 540 |
|
| 541 |
ASN1_TYPE_free(name->value); |
| 542 |
name->value = ASN1_generate_v3(semicolon + 1, ctx); |
| 543 |
if (name->value == NULL) { |
| 544 |
goto err; |
| 545 |
} |
| 546 |
|
| 547 |
gen->type = GEN_OTHERNAME; |
| 548 |
gen->d.otherName = name; |
| 549 |
return 1; |
| 550 |
|
| 551 |
err: |
| 552 |
OTHERNAME_free(name); |
| 553 |
return 0; |
| 554 |
} |
| 555 |
|
| 556 |
static int do_dirname(GENERAL_NAME *gen, const char *value, |
| 557 |
const X509V3_CTX *ctx) { |
| 558 |
int ret = 0; |
| 559 |
X509_NAME *nm = X509_NAME_new(); |
| 560 |
if (nm == NULL) { |
| 561 |
goto err; |
| 562 |
} |
| 563 |
const STACK_OF(CONF_VALUE) *sk = X509V3_get_section(ctx, value); |
| 564 |
if (sk == NULL) { |
| 565 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_SECTION_NOT_FOUND); |
| 566 |
ERR_add_error_data(2, "section=", value); |
| 567 |
goto err; |
| 568 |
} |
| 569 |
// FIXME: should allow other character types... |
| 570 |
if (!X509V3_NAME_from_section(nm, sk, MBSTRING_ASC)) { |
| 571 |
goto err; |
| 572 |
} |
| 573 |
gen->type = GEN_DIRNAME; |
| 574 |
gen->d.dirn = nm; |
| 575 |
ret = 1; |
| 576 |
|
| 577 |
err: |
| 578 |
if (!ret) { |
| 579 |
X509_NAME_free(nm); |
| 580 |
} |
| 581 |
return ret; |
| 582 |
} |