]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/x509/v3_san.c
22cef0537076a916217d9611637d09289f95002b
[thirdparty/openssl.git] / crypto / x509 / v3_san.c
1 /*
2 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <stdio.h>
11 #include "internal/cryptlib.h"
12 #include "crypto/x509.h"
13 #include <openssl/conf.h>
14 #include <openssl/x509v3.h>
15 #include <openssl/bio.h>
16 #include "ext_dat.h"
17
18 static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
19 X509V3_CTX *ctx,
20 STACK_OF(CONF_VALUE) *nval);
21 static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
22 X509V3_CTX *ctx,
23 STACK_OF(CONF_VALUE) *nval);
24 static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p);
25 static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens);
26 static int do_othername(GENERAL_NAME *gen, const char *value, X509V3_CTX *ctx);
27 static int do_dirname(GENERAL_NAME *gen, const char *value, X509V3_CTX *ctx);
28
29 const X509V3_EXT_METHOD ossl_v3_alt[3] = {
30 {NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
31 0, 0, 0, 0,
32 0, 0,
33 (X509V3_EXT_I2V) i2v_GENERAL_NAMES,
34 (X509V3_EXT_V2I)v2i_subject_alt,
35 NULL, NULL, NULL},
36
37 {NID_issuer_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
38 0, 0, 0, 0,
39 0, 0,
40 (X509V3_EXT_I2V) i2v_GENERAL_NAMES,
41 (X509V3_EXT_V2I)v2i_issuer_alt,
42 NULL, NULL, NULL},
43
44 {NID_certificate_issuer, 0, ASN1_ITEM_ref(GENERAL_NAMES),
45 0, 0, 0, 0,
46 0, 0,
47 (X509V3_EXT_I2V) i2v_GENERAL_NAMES,
48 NULL, NULL, NULL, NULL},
49 };
50
51 STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
52 GENERAL_NAMES *gens,
53 STACK_OF(CONF_VALUE) *ret)
54 {
55 int i;
56 GENERAL_NAME *gen;
57 STACK_OF(CONF_VALUE) *tmpret = NULL, *origret = ret;
58
59 for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
60 gen = sk_GENERAL_NAME_value(gens, i);
61 /*
62 * i2v_GENERAL_NAME allocates ret if it is NULL. If something goes
63 * wrong we need to free the stack - but only if it was empty when we
64 * originally entered this function.
65 */
66 tmpret = i2v_GENERAL_NAME(method, gen, ret);
67 if (tmpret == NULL) {
68 if (origret == NULL)
69 sk_CONF_VALUE_pop_free(ret, X509V3_conf_free);
70 return NULL;
71 }
72 ret = tmpret;
73 }
74 if (ret == NULL)
75 return sk_CONF_VALUE_new_null();
76 return ret;
77 }
78
79 STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
80 GENERAL_NAME *gen,
81 STACK_OF(CONF_VALUE) *ret)
82 {
83 char othername[300];
84 char oline[256], *tmp;
85
86 switch (gen->type) {
87 case GEN_OTHERNAME:
88 switch (OBJ_obj2nid(gen->d.otherName->type_id)) {
89 case NID_id_on_SmtpUTF8Mailbox:
90 if (gen->d.otherName->value->type != V_ASN1_UTF8STRING
91 || !x509v3_add_len_value_uchar("othername: SmtpUTF8Mailbox:",
92 gen->d.otherName->value->value.utf8string->data,
93 gen->d.otherName->value->value.utf8string->length,
94 &ret))
95 return NULL;
96 break;
97 case NID_XmppAddr:
98 if (gen->d.otherName->value->type != V_ASN1_UTF8STRING
99 || !x509v3_add_len_value_uchar("othername: XmppAddr:",
100 gen->d.otherName->value->value.utf8string->data,
101 gen->d.otherName->value->value.utf8string->length,
102 &ret))
103 return NULL;
104 break;
105 case NID_SRVName:
106 if (gen->d.otherName->value->type != V_ASN1_IA5STRING
107 || !x509v3_add_len_value_uchar("othername: SRVName:",
108 gen->d.otherName->value->value.ia5string->data,
109 gen->d.otherName->value->value.ia5string->length,
110 &ret))
111 return NULL;
112 break;
113 case NID_ms_upn:
114 if (gen->d.otherName->value->type != V_ASN1_UTF8STRING
115 || !x509v3_add_len_value_uchar("othername: UPN:",
116 gen->d.otherName->value->value.utf8string->data,
117 gen->d.otherName->value->value.utf8string->length,
118 &ret))
119 return NULL;
120 break;
121 case NID_NAIRealm:
122 if (gen->d.otherName->value->type != V_ASN1_UTF8STRING
123 || !x509v3_add_len_value_uchar("othername: NAIRealm:",
124 gen->d.otherName->value->value.utf8string->data,
125 gen->d.otherName->value->value.utf8string->length,
126 &ret))
127 return NULL;
128 break;
129 default:
130 if (OBJ_obj2txt(oline, sizeof(oline), gen->d.otherName->type_id, 0) > 0)
131 BIO_snprintf(othername, sizeof(othername), "othername: %s:",
132 oline);
133 else
134 OPENSSL_strlcpy(othername, "othername:", sizeof(othername));
135
136 /* check if the value is something printable */
137 if (gen->d.otherName->value->type == V_ASN1_IA5STRING) {
138 if (x509v3_add_len_value_uchar(othername,
139 gen->d.otherName->value->value.ia5string->data,
140 gen->d.otherName->value->value.ia5string->length,
141 &ret))
142 return ret;
143 }
144 if (gen->d.otherName->value->type == V_ASN1_UTF8STRING) {
145 if (x509v3_add_len_value_uchar(othername,
146 gen->d.otherName->value->value.utf8string->data,
147 gen->d.otherName->value->value.utf8string->length,
148 &ret))
149 return ret;
150 }
151 if (!X509V3_add_value(othername, "<unsupported>", &ret))
152 return NULL;
153 break;
154 }
155 break;
156
157 case GEN_X400:
158 if (!X509V3_add_value("X400Name", "<unsupported>", &ret))
159 return NULL;
160 break;
161
162 case GEN_EDIPARTY:
163 if (!X509V3_add_value("EdiPartyName", "<unsupported>", &ret))
164 return NULL;
165 break;
166
167 case GEN_EMAIL:
168 if (!x509v3_add_len_value_uchar("email", gen->d.ia5->data,
169 gen->d.ia5->length, &ret))
170 return NULL;
171 break;
172
173 case GEN_DNS:
174 if (!x509v3_add_len_value_uchar("DNS", gen->d.ia5->data,
175 gen->d.ia5->length, &ret))
176 return NULL;
177 break;
178
179 case GEN_URI:
180 if (!x509v3_add_len_value_uchar("URI", gen->d.ia5->data,
181 gen->d.ia5->length, &ret))
182 return NULL;
183 break;
184
185 case GEN_DIRNAME:
186 if (X509_NAME_oneline(gen->d.dirn, oline, sizeof(oline)) == NULL
187 || !X509V3_add_value("DirName", oline, &ret))
188 return NULL;
189 break;
190
191 case GEN_IPADD:
192 tmp = ossl_ipaddr_to_asc(gen->d.ip->data, gen->d.ip->length);
193 if (tmp == NULL || !X509V3_add_value("IP Address", tmp, &ret))
194 ret = NULL;
195 OPENSSL_free(tmp);
196 break;
197
198 case GEN_RID:
199 i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
200 if (!X509V3_add_value("Registered ID", oline, &ret))
201 return NULL;
202 break;
203 }
204 return ret;
205 }
206
207 int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
208 {
209 char *tmp;
210 int nid;
211
212 switch (gen->type) {
213 case GEN_OTHERNAME:
214 nid = OBJ_obj2nid(gen->d.otherName->type_id);
215 /* Validate the types are as we expect before we use them */
216 if ((nid == NID_SRVName
217 && gen->d.otherName->value->type != V_ASN1_IA5STRING)
218 || (nid != NID_SRVName
219 && gen->d.otherName->value->type != V_ASN1_UTF8STRING)) {
220 BIO_printf(out, "othername:<unsupported>");
221 break;
222 }
223
224 switch (nid) {
225 case NID_id_on_SmtpUTF8Mailbox:
226 BIO_printf(out, "othername:SmtpUTF8Mailbox:%s",
227 gen->d.otherName->value->value.utf8string->data);
228 break;
229 case NID_XmppAddr:
230 BIO_printf(out, "othername:XmppAddr:%s",
231 gen->d.otherName->value->value.utf8string->data);
232 break;
233 case NID_SRVName:
234 BIO_printf(out, "othername:SRVName:%s",
235 gen->d.otherName->value->value.ia5string->data);
236 break;
237 case NID_ms_upn:
238 BIO_printf(out, "othername:UPN:%s",
239 gen->d.otherName->value->value.utf8string->data);
240 break;
241 case NID_NAIRealm:
242 BIO_printf(out, "othername:NAIRealm:%s",
243 gen->d.otherName->value->value.utf8string->data);
244 break;
245 default:
246 BIO_printf(out, "othername:<unsupported>");
247 break;
248 }
249 break;
250
251 case GEN_X400:
252 BIO_printf(out, "X400Name:<unsupported>");
253 break;
254
255 case GEN_EDIPARTY:
256 /* Maybe fix this: it is supported now */
257 BIO_printf(out, "EdiPartyName:<unsupported>");
258 break;
259
260 case GEN_EMAIL:
261 BIO_printf(out, "email:");
262 ASN1_STRING_print(out, gen->d.ia5);
263 break;
264
265 case GEN_DNS:
266 BIO_printf(out, "DNS:");
267 ASN1_STRING_print(out, gen->d.ia5);
268 break;
269
270 case GEN_URI:
271 BIO_printf(out, "URI:");
272 ASN1_STRING_print(out, gen->d.ia5);
273 break;
274
275 case GEN_DIRNAME:
276 BIO_printf(out, "DirName:");
277 X509_NAME_print_ex(out, gen->d.dirn, 0, XN_FLAG_ONELINE);
278 break;
279
280 case GEN_IPADD:
281 tmp = ossl_ipaddr_to_asc(gen->d.ip->data, gen->d.ip->length);
282 if (tmp == NULL)
283 return 0;
284 BIO_printf(out, "IP Address:%s", tmp);
285 OPENSSL_free(tmp);
286 break;
287
288 case GEN_RID:
289 BIO_printf(out, "Registered ID:");
290 i2a_ASN1_OBJECT(out, gen->d.rid);
291 break;
292 }
293 return 1;
294 }
295
296 static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
297 X509V3_CTX *ctx,
298 STACK_OF(CONF_VALUE) *nval)
299 {
300 const int num = sk_CONF_VALUE_num(nval);
301 GENERAL_NAMES *gens = sk_GENERAL_NAME_new_reserve(NULL, num);
302 int i;
303
304 if (gens == NULL) {
305 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
306 sk_GENERAL_NAME_free(gens);
307 return NULL;
308 }
309 for (i = 0; i < num; i++) {
310 CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i);
311
312 if (!ossl_v3_name_cmp(cnf->name, "issuer")
313 && cnf->value && strcmp(cnf->value, "copy") == 0) {
314 if (!copy_issuer(ctx, gens))
315 goto err;
316 } else {
317 GENERAL_NAME *gen = v2i_GENERAL_NAME(method, ctx, cnf);
318
319 if (gen == NULL)
320 goto err;
321 sk_GENERAL_NAME_push(gens, gen); /* no failure as it was reserved */
322 }
323 }
324 return gens;
325 err:
326 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
327 return NULL;
328 }
329
330 /* Append subject altname of issuer to issuer alt name of subject */
331
332 static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens)
333 {
334 GENERAL_NAMES *ialt;
335 GENERAL_NAME *gen;
336 X509_EXTENSION *ext;
337 int i, num;
338
339 if (ctx != NULL && (ctx->flags & X509V3_CTX_TEST) != 0)
340 return 1;
341 if (!ctx || !ctx->issuer_cert) {
342 ERR_raise(ERR_LIB_X509V3, X509V3_R_NO_ISSUER_DETAILS);
343 goto err;
344 }
345 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
346 if (i < 0)
347 return 1;
348 if ((ext = X509_get_ext(ctx->issuer_cert, i)) == NULL
349 || (ialt = X509V3_EXT_d2i(ext)) == NULL) {
350 ERR_raise(ERR_LIB_X509V3, X509V3_R_ISSUER_DECODE_ERROR);
351 goto err;
352 }
353
354 num = sk_GENERAL_NAME_num(ialt);
355 if (!sk_GENERAL_NAME_reserve(gens, num)) {
356 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
357 goto err;
358 }
359
360 for (i = 0; i < num; i++) {
361 gen = sk_GENERAL_NAME_value(ialt, i);
362 sk_GENERAL_NAME_push(gens, gen); /* no failure as it was reserved */
363 }
364 sk_GENERAL_NAME_free(ialt);
365
366 return 1;
367
368 err:
369 return 0;
370
371 }
372
373 static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
374 X509V3_CTX *ctx,
375 STACK_OF(CONF_VALUE) *nval)
376 {
377 GENERAL_NAMES *gens;
378 CONF_VALUE *cnf;
379 const int num = sk_CONF_VALUE_num(nval);
380 int i;
381
382 gens = sk_GENERAL_NAME_new_reserve(NULL, num);
383 if (gens == NULL) {
384 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
385 sk_GENERAL_NAME_free(gens);
386 return NULL;
387 }
388
389 for (i = 0; i < num; i++) {
390 cnf = sk_CONF_VALUE_value(nval, i);
391 if (!ossl_v3_name_cmp(cnf->name, "email")
392 && cnf->value && strcmp(cnf->value, "copy") == 0) {
393 if (!copy_email(ctx, gens, 0))
394 goto err;
395 } else if (!ossl_v3_name_cmp(cnf->name, "email")
396 && cnf->value && strcmp(cnf->value, "move") == 0) {
397 if (!copy_email(ctx, gens, 1))
398 goto err;
399 } else {
400 GENERAL_NAME *gen;
401 if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL)
402 goto err;
403 sk_GENERAL_NAME_push(gens, gen); /* no failure as it was reserved */
404 }
405 }
406 return gens;
407 err:
408 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
409 return NULL;
410 }
411
412 /*
413 * Copy any email addresses in a certificate or request to GENERAL_NAMES
414 */
415
416 static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
417 {
418 X509_NAME *nm;
419 ASN1_IA5STRING *email = NULL;
420 X509_NAME_ENTRY *ne;
421 GENERAL_NAME *gen = NULL;
422 int i = -1;
423
424 if (ctx != NULL && (ctx->flags & X509V3_CTX_TEST) != 0)
425 return 1;
426 if (ctx == NULL
427 || (ctx->subject_cert == NULL && ctx->subject_req == NULL)) {
428 ERR_raise(ERR_LIB_X509V3, X509V3_R_NO_SUBJECT_DETAILS);
429 return 0;
430 }
431 /* Find the subject name */
432 if (ctx->subject_cert)
433 nm = X509_get_subject_name(ctx->subject_cert);
434 else
435 nm = X509_REQ_get_subject_name(ctx->subject_req);
436
437 /* Now add any email address(es) to STACK */
438 while ((i = X509_NAME_get_index_by_NID(nm,
439 NID_pkcs9_emailAddress, i)) >= 0) {
440 ne = X509_NAME_get_entry(nm, i);
441 email = ASN1_STRING_dup(X509_NAME_ENTRY_get_data(ne));
442 if (move_p) {
443 X509_NAME_delete_entry(nm, i);
444 X509_NAME_ENTRY_free(ne);
445 i--;
446 }
447 if (email == NULL || (gen = GENERAL_NAME_new()) == NULL) {
448 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
449 goto err;
450 }
451 gen->d.ia5 = email;
452 email = NULL;
453 gen->type = GEN_EMAIL;
454 if (!sk_GENERAL_NAME_push(gens, gen)) {
455 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
456 goto err;
457 }
458 gen = NULL;
459 }
460
461 return 1;
462
463 err:
464 GENERAL_NAME_free(gen);
465 ASN1_IA5STRING_free(email);
466 return 0;
467
468 }
469
470 GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method,
471 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
472 {
473 GENERAL_NAME *gen;
474 GENERAL_NAMES *gens;
475 CONF_VALUE *cnf;
476 const int num = sk_CONF_VALUE_num(nval);
477 int i;
478
479 gens = sk_GENERAL_NAME_new_reserve(NULL, num);
480 if (gens == NULL) {
481 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
482 sk_GENERAL_NAME_free(gens);
483 return NULL;
484 }
485
486 for (i = 0; i < num; i++) {
487 cnf = sk_CONF_VALUE_value(nval, i);
488 if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL)
489 goto err;
490 sk_GENERAL_NAME_push(gens, gen); /* no failure as it was reserved */
491 }
492 return gens;
493 err:
494 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
495 return NULL;
496 }
497
498 GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method,
499 X509V3_CTX *ctx, CONF_VALUE *cnf)
500 {
501 return v2i_GENERAL_NAME_ex(NULL, method, ctx, cnf, 0);
502 }
503
504 GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out,
505 const X509V3_EXT_METHOD *method,
506 X509V3_CTX *ctx, int gen_type, const char *value,
507 int is_nc)
508 {
509 char is_string = 0;
510 GENERAL_NAME *gen = NULL;
511
512 if (!value) {
513 ERR_raise(ERR_LIB_X509V3, X509V3_R_MISSING_VALUE);
514 return NULL;
515 }
516
517 if (out)
518 gen = out;
519 else {
520 gen = GENERAL_NAME_new();
521 if (gen == NULL) {
522 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
523 return NULL;
524 }
525 }
526
527 switch (gen_type) {
528 case GEN_URI:
529 case GEN_EMAIL:
530 case GEN_DNS:
531 is_string = 1;
532 break;
533
534 case GEN_RID:
535 {
536 ASN1_OBJECT *obj;
537 if ((obj = OBJ_txt2obj(value, 0)) == NULL) {
538 ERR_raise_data(ERR_LIB_X509V3, X509V3_R_BAD_OBJECT,
539 "value=%s", value);
540 goto err;
541 }
542 gen->d.rid = obj;
543 }
544 break;
545
546 case GEN_IPADD:
547 if (is_nc)
548 gen->d.ip = a2i_IPADDRESS_NC(value);
549 else
550 gen->d.ip = a2i_IPADDRESS(value);
551 if (gen->d.ip == NULL) {
552 ERR_raise_data(ERR_LIB_X509V3, X509V3_R_BAD_IP_ADDRESS,
553 "value=%s", value);
554 goto err;
555 }
556 break;
557
558 case GEN_DIRNAME:
559 if (!do_dirname(gen, value, ctx)) {
560 ERR_raise(ERR_LIB_X509V3, X509V3_R_DIRNAME_ERROR);
561 goto err;
562 }
563 break;
564
565 case GEN_OTHERNAME:
566 if (!do_othername(gen, value, ctx)) {
567 ERR_raise(ERR_LIB_X509V3, X509V3_R_OTHERNAME_ERROR);
568 goto err;
569 }
570 break;
571 default:
572 ERR_raise(ERR_LIB_X509V3, X509V3_R_UNSUPPORTED_TYPE);
573 goto err;
574 }
575
576 if (is_string) {
577 if ((gen->d.ia5 = ASN1_IA5STRING_new()) == NULL ||
578 !ASN1_STRING_set(gen->d.ia5, (unsigned char *)value,
579 strlen(value))) {
580 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
581 goto err;
582 }
583 }
584
585 gen->type = gen_type;
586
587 return gen;
588
589 err:
590 if (!out)
591 GENERAL_NAME_free(gen);
592 return NULL;
593 }
594
595 GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
596 const X509V3_EXT_METHOD *method,
597 X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc)
598 {
599 int type;
600
601 char *name, *value;
602
603 name = cnf->name;
604 value = cnf->value;
605
606 if (!value) {
607 ERR_raise(ERR_LIB_X509V3, X509V3_R_MISSING_VALUE);
608 return NULL;
609 }
610
611 if (!ossl_v3_name_cmp(name, "email"))
612 type = GEN_EMAIL;
613 else if (!ossl_v3_name_cmp(name, "URI"))
614 type = GEN_URI;
615 else if (!ossl_v3_name_cmp(name, "DNS"))
616 type = GEN_DNS;
617 else if (!ossl_v3_name_cmp(name, "RID"))
618 type = GEN_RID;
619 else if (!ossl_v3_name_cmp(name, "IP"))
620 type = GEN_IPADD;
621 else if (!ossl_v3_name_cmp(name, "dirName"))
622 type = GEN_DIRNAME;
623 else if (!ossl_v3_name_cmp(name, "otherName"))
624 type = GEN_OTHERNAME;
625 else {
626 ERR_raise_data(ERR_LIB_X509V3, X509V3_R_UNSUPPORTED_OPTION,
627 "name=%s", name);
628 return NULL;
629 }
630
631 return a2i_GENERAL_NAME(out, method, ctx, type, value, is_nc);
632
633 }
634
635 static int do_othername(GENERAL_NAME *gen, const char *value, X509V3_CTX *ctx)
636 {
637 char *objtmp = NULL, *p;
638 int objlen;
639
640 if ((p = strchr(value, ';')) == NULL)
641 return 0;
642 if ((gen->d.otherName = OTHERNAME_new()) == NULL)
643 return 0;
644 /*
645 * Free this up because we will overwrite it. no need to free type_id
646 * because it is static
647 */
648 ASN1_TYPE_free(gen->d.otherName->value);
649 if ((gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx)) == NULL)
650 return 0;
651 objlen = p - value;
652 objtmp = OPENSSL_strndup(value, objlen);
653 if (objtmp == NULL)
654 return 0;
655 gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0);
656 OPENSSL_free(objtmp);
657 if (!gen->d.otherName->type_id)
658 return 0;
659 return 1;
660 }
661
662 static int do_dirname(GENERAL_NAME *gen, const char *value, X509V3_CTX *ctx)
663 {
664 int ret = 0;
665 STACK_OF(CONF_VALUE) *sk = NULL;
666 X509_NAME *nm;
667
668 if ((nm = X509_NAME_new()) == NULL)
669 goto err;
670 sk = X509V3_get_section(ctx, value);
671 if (!sk) {
672 ERR_raise_data(ERR_LIB_X509V3, X509V3_R_SECTION_NOT_FOUND,
673 "section=%s", value);
674 goto err;
675 }
676 /* FIXME: should allow other character types... */
677 ret = X509V3_NAME_from_section(nm, sk, MBSTRING_ASC);
678 if (!ret)
679 goto err;
680 gen->d.dirn = nm;
681
682 err:
683 if (ret == 0)
684 X509_NAME_free(nm);
685 X509V3_section_free(ctx, sk);
686 return ret;
687 }