GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libcrypto/crypto/../../libssl/src/crypto/x509v3/v3_alt.c Lines: 0 278 0.0 %
Date: 2016-12-06 Branches: 0 188 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: v3_alt.c,v 1.25 2015/09/30 18:21:50 jsing Exp $ */
2
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3
 * project.
4
 */
5
/* ====================================================================
6
 * Copyright (c) 1999-2003 The OpenSSL Project.  All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright
13
 *    notice, this list of conditions and the following disclaimer.
14
 *
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19
 *
20
 * 3. All advertising materials mentioning features or use of this
21
 *    software must display the following acknowledgment:
22
 *    "This product includes software developed by the OpenSSL Project
23
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24
 *
25
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    licensing@OpenSSL.org.
29
 *
30
 * 5. Products derived from this software may not be called "OpenSSL"
31
 *    nor may "OpenSSL" appear in their names without prior written
32
 *    permission of the OpenSSL Project.
33
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *    "This product includes software developed by the OpenSSL Project
37
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38
 *
39
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 * OF THE POSSIBILITY OF SUCH DAMAGE.
51
 * ====================================================================
52
 *
53
 * This product includes cryptographic software written by Eric Young
54
 * (eay@cryptsoft.com).  This product includes software written by Tim
55
 * Hudson (tjh@cryptsoft.com).
56
 *
57
 */
58
59
#include <stdio.h>
60
#include <string.h>
61
62
#include <openssl/conf.h>
63
#include <openssl/err.h>
64
#include <openssl/x509v3.h>
65
66
static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
67
    X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
68
static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
69
    X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
70
static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p);
71
static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens);
72
static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx);
73
static int do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx);
74
75
const X509V3_EXT_METHOD v3_alt[] = {
76
	{
77
		.ext_nid = NID_subject_alt_name,
78
		.ext_flags = 0,
79
		.it = ASN1_ITEM_ref(GENERAL_NAMES),
80
		.ext_new = NULL,
81
		.ext_free = NULL,
82
		.d2i = NULL,
83
		.i2d = NULL,
84
		.i2s = NULL,
85
		.s2i = NULL,
86
		.i2v = (X509V3_EXT_I2V)i2v_GENERAL_NAMES,
87
		.v2i = (X509V3_EXT_V2I)v2i_subject_alt,
88
		.i2r = NULL,
89
		.r2i = NULL,
90
		.usr_data = NULL,
91
	},
92
	{
93
		.ext_nid = NID_issuer_alt_name,
94
		.ext_flags = 0,
95
		.it = ASN1_ITEM_ref(GENERAL_NAMES),
96
		.ext_new = NULL,
97
		.ext_free = NULL,
98
		.d2i = NULL,
99
		.i2d = NULL,
100
		.i2s = NULL,
101
		.s2i = NULL,
102
		.i2v = (X509V3_EXT_I2V)i2v_GENERAL_NAMES,
103
		.v2i = (X509V3_EXT_V2I)v2i_issuer_alt,
104
		.i2r = NULL,
105
		.r2i = NULL,
106
		.usr_data = NULL,
107
	},
108
	{
109
		.ext_nid = NID_certificate_issuer,
110
		.ext_flags = 0,
111
		.it = ASN1_ITEM_ref(GENERAL_NAMES),
112
		.ext_new = NULL,
113
		.ext_free = NULL,
114
		.d2i = NULL,
115
		.i2d = NULL,
116
		.i2s = NULL,
117
		.s2i = NULL,
118
		.i2v = (X509V3_EXT_I2V)i2v_GENERAL_NAMES,
119
		.v2i = NULL,
120
		.i2r = NULL,
121
		.r2i = NULL,
122
		.usr_data = NULL,
123
	},
124
};
125
126
STACK_OF(CONF_VALUE) *
127
i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, GENERAL_NAMES *gens,
128
    STACK_OF(CONF_VALUE) *ret)
129
{
130
	int i;
131
	GENERAL_NAME *gen;
132
133
	for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
134
		gen = sk_GENERAL_NAME_value(gens, i);
135
		ret = i2v_GENERAL_NAME(method, gen, ret);
136
	}
137
	if (!ret)
138
		return sk_CONF_VALUE_new_null();
139
	return ret;
140
}
141
142
STACK_OF(CONF_VALUE) *
143
i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen,
144
    STACK_OF(CONF_VALUE) *ret)
145
{
146
	unsigned char *p;
147
	char oline[256], htmp[5];
148
	int i;
149
150
	switch (gen->type) {
151
	case GEN_OTHERNAME:
152
		X509V3_add_value("othername", "<unsupported>", &ret);
153
		break;
154
155
	case GEN_X400:
156
		X509V3_add_value("X400Name", "<unsupported>", &ret);
157
		break;
158
159
	case GEN_EDIPARTY:
160
		X509V3_add_value("EdiPartyName", "<unsupported>", &ret);
161
		break;
162
163
	case GEN_EMAIL:
164
		X509V3_add_value_uchar("email", gen->d.ia5->data, &ret);
165
		break;
166
167
	case GEN_DNS:
168
		X509V3_add_value_uchar("DNS", gen->d.ia5->data, &ret);
169
		break;
170
171
	case GEN_URI:
172
		X509V3_add_value_uchar("URI", gen->d.ia5->data, &ret);
173
		break;
174
175
	case GEN_DIRNAME:
176
		X509_NAME_oneline(gen->d.dirn, oline, 256);
177
		X509V3_add_value("DirName", oline, &ret);
178
		break;
179
180
	case GEN_IPADD:
181
		p = gen->d.ip->data;
182
		if (gen->d.ip->length == 4)
183
			(void) snprintf(oline, sizeof oline,
184
			    "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
185
		else if (gen->d.ip->length == 16) {
186
			oline[0] = 0;
187
			for (i = 0; i < 8; i++) {
188
				(void) snprintf(htmp, sizeof htmp,
189
				    "%X", p[0] << 8 | p[1]);
190
				p += 2;
191
				strlcat(oline, htmp, sizeof(oline));
192
				if (i != 7)
193
					strlcat(oline, ":", sizeof(oline));
194
			}
195
		} else {
196
			X509V3_add_value("IP Address", "<invalid>", &ret);
197
			break;
198
		}
199
		X509V3_add_value("IP Address", oline, &ret);
200
		break;
201
202
	case GEN_RID:
203
		i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
204
		X509V3_add_value("Registered ID", oline, &ret);
205
		break;
206
	}
207
	return ret;
208
}
209
210
int
211
GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
212
{
213
	unsigned char *p;
214
	int i;
215
216
	switch (gen->type) {
217
	case GEN_OTHERNAME:
218
		BIO_printf(out, "othername:<unsupported>");
219
		break;
220
221
	case GEN_X400:
222
		BIO_printf(out, "X400Name:<unsupported>");
223
		break;
224
225
	case GEN_EDIPARTY:
226
		/* Maybe fix this: it is supported now */
227
		BIO_printf(out, "EdiPartyName:<unsupported>");
228
		break;
229
230
	case GEN_EMAIL:
231
		BIO_printf(out, "email:%s", gen->d.ia5->data);
232
		break;
233
234
	case GEN_DNS:
235
		BIO_printf(out, "DNS:%s", gen->d.ia5->data);
236
		break;
237
238
	case GEN_URI:
239
		BIO_printf(out, "URI:%s", gen->d.ia5->data);
240
		break;
241
242
	case GEN_DIRNAME:
243
		BIO_printf(out, "DirName: ");
244
		X509_NAME_print_ex(out, gen->d.dirn, 0, XN_FLAG_ONELINE);
245
		break;
246
247
	case GEN_IPADD:
248
		p = gen->d.ip->data;
249
		if (gen->d.ip->length == 4)
250
			BIO_printf(out, "IP Address:%d.%d.%d.%d",
251
			    p[0], p[1], p[2], p[3]);
252
		else if (gen->d.ip->length == 16) {
253
			BIO_printf(out, "IP Address");
254
			for (i = 0; i < 8; i++) {
255
				BIO_printf(out, ":%X", p[0] << 8 | p[1]);
256
				p += 2;
257
			}
258
			BIO_puts(out, "\n");
259
		} else {
260
			BIO_printf(out, "IP Address:<invalid>");
261
			break;
262
		}
263
		break;
264
265
	case GEN_RID:
266
		BIO_printf(out, "Registered ID");
267
		i2a_ASN1_OBJECT(out, gen->d.rid);
268
		break;
269
	}
270
	return 1;
271
}
272
273
static GENERAL_NAMES *
274
v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
275
    STACK_OF(CONF_VALUE) *nval)
276
{
277
	GENERAL_NAMES *gens = NULL;
278
	CONF_VALUE *cnf;
279
	int i;
280
281
	if ((gens = sk_GENERAL_NAME_new_null()) == NULL) {
282
		X509V3err(X509V3_F_V2I_ISSUER_ALT, ERR_R_MALLOC_FAILURE);
283
		return NULL;
284
	}
285
	for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
286
		cnf = sk_CONF_VALUE_value(nval, i);
287
		if (name_cmp(cnf->name, "issuer") == 0 && cnf->value != NULL &&
288
		    strcmp(cnf->value, "copy") == 0) {
289
			if (!copy_issuer(ctx, gens))
290
				goto err;
291
		} else {
292
			GENERAL_NAME *gen;
293
			if ((gen = v2i_GENERAL_NAME(method, ctx, cnf)) == NULL)
294
				goto err;
295
			if (sk_GENERAL_NAME_push(gens, gen) == 0) {
296
				GENERAL_NAME_free(gen);
297
				goto err;
298
			}
299
		}
300
	}
301
	return gens;
302
303
err:
304
	sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
305
	return NULL;
306
}
307
308
/* Append subject altname of issuer to issuer alt name of subject */
309
310
static int
311
copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens)
312
{
313
	GENERAL_NAMES *ialt;
314
	GENERAL_NAME *gen;
315
	X509_EXTENSION *ext;
316
	int i;
317
318
	if (ctx && (ctx->flags == CTX_TEST))
319
		return 1;
320
	if (!ctx || !ctx->issuer_cert) {
321
		X509V3err(X509V3_F_COPY_ISSUER, X509V3_R_NO_ISSUER_DETAILS);
322
		goto err;
323
	}
324
	i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
325
	if (i < 0)
326
		return 1;
327
	if (!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
328
	    !(ialt = X509V3_EXT_d2i(ext))) {
329
		X509V3err(X509V3_F_COPY_ISSUER, X509V3_R_ISSUER_DECODE_ERROR);
330
		goto err;
331
	}
332
333
	for (i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
334
		gen = sk_GENERAL_NAME_value(ialt, i);
335
		if (!sk_GENERAL_NAME_push(gens, gen)) {
336
			X509V3err(X509V3_F_COPY_ISSUER, ERR_R_MALLOC_FAILURE);
337
			goto err;
338
		}
339
	}
340
	sk_GENERAL_NAME_free(ialt);
341
342
	return 1;
343
344
err:
345
	return 0;
346
347
}
348
349
static GENERAL_NAMES *
350
v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
351
    STACK_OF(CONF_VALUE) *nval)
352
{
353
	GENERAL_NAMES *gens = NULL;
354
	CONF_VALUE *cnf;
355
	int i;
356
357
	if (!(gens = sk_GENERAL_NAME_new_null())) {
358
		X509V3err(X509V3_F_V2I_SUBJECT_ALT, ERR_R_MALLOC_FAILURE);
359
		return NULL;
360
	}
361
	for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
362
		cnf = sk_CONF_VALUE_value(nval, i);
363
		if (!name_cmp(cnf->name, "email") && cnf->value &&
364
		    !strcmp(cnf->value, "copy")) {
365
			if (!copy_email(ctx, gens, 0))
366
				goto err;
367
		} else if (!name_cmp(cnf->name, "email") && cnf->value &&
368
		    !strcmp(cnf->value, "move")) {
369
			if (!copy_email(ctx, gens, 1))
370
				goto err;
371
		} else {
372
			GENERAL_NAME *gen;
373
			if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
374
				goto err;
375
			if (sk_GENERAL_NAME_push(gens, gen) == 0) {
376
				GENERAL_NAME_free(gen);
377
				goto err;
378
			}
379
		}
380
	}
381
	return gens;
382
383
err:
384
	sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
385
	return NULL;
386
}
387
388
/* Copy any email addresses in a certificate or request to
389
 * GENERAL_NAMES
390
 */
391
392
static int
393
copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
394
{
395
	X509_NAME *nm;
396
	ASN1_IA5STRING *email = NULL;
397
	X509_NAME_ENTRY *ne;
398
	GENERAL_NAME *gen = NULL;
399
	int i;
400
401
	if (ctx != NULL && ctx->flags == CTX_TEST)
402
		return 1;
403
	if (!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
404
		X509V3err(X509V3_F_COPY_EMAIL, X509V3_R_NO_SUBJECT_DETAILS);
405
		goto err;
406
	}
407
	/* Find the subject name */
408
	if (ctx->subject_cert)
409
		nm = X509_get_subject_name(ctx->subject_cert);
410
	else
411
		nm = X509_REQ_get_subject_name(ctx->subject_req);
412
413
	/* Now add any email address(es) to STACK */
414
	i = -1;
415
	while ((i = X509_NAME_get_index_by_NID(nm,
416
	    NID_pkcs9_emailAddress, i)) >= 0) {
417
		ne = X509_NAME_get_entry(nm, i);
418
		email = ASN1_STRING_dup(X509_NAME_ENTRY_get_data(ne));
419
		if (move_p) {
420
			X509_NAME_delete_entry(nm, i);
421
			X509_NAME_ENTRY_free(ne);
422
			i--;
423
		}
424
		if (!email || !(gen = GENERAL_NAME_new())) {
425
			X509V3err(X509V3_F_COPY_EMAIL, ERR_R_MALLOC_FAILURE);
426
			goto err;
427
		}
428
		gen->d.ia5 = email;
429
		email = NULL;
430
		gen->type = GEN_EMAIL;
431
		if (!sk_GENERAL_NAME_push(gens, gen)) {
432
			X509V3err(X509V3_F_COPY_EMAIL, ERR_R_MALLOC_FAILURE);
433
			goto err;
434
		}
435
		gen = NULL;
436
	}
437
438
	return 1;
439
440
err:
441
	GENERAL_NAME_free(gen);
442
	ASN1_IA5STRING_free(email);
443
	return 0;
444
}
445
446
GENERAL_NAMES *
447
v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
448
    STACK_OF(CONF_VALUE) *nval)
449
{
450
	GENERAL_NAME *gen;
451
	GENERAL_NAMES *gens = NULL;
452
	CONF_VALUE *cnf;
453
	int i;
454
455
	if (!(gens = sk_GENERAL_NAME_new_null())) {
456
		X509V3err(X509V3_F_V2I_GENERAL_NAMES, ERR_R_MALLOC_FAILURE);
457
		return NULL;
458
	}
459
	for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
460
		cnf = sk_CONF_VALUE_value(nval, i);
461
		if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
462
			goto err;
463
		if (sk_GENERAL_NAME_push(gens, gen) == 0) {
464
			GENERAL_NAME_free(gen);
465
			goto err;
466
		}
467
	}
468
	return gens;
469
470
err:
471
	sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
472
	return NULL;
473
}
474
475
GENERAL_NAME *
476
v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
477
    CONF_VALUE *cnf)
478
{
479
	return v2i_GENERAL_NAME_ex(NULL, method, ctx, cnf, 0);
480
}
481
482
GENERAL_NAME *
483
a2i_GENERAL_NAME(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
484
    X509V3_CTX *ctx, int gen_type, char *value, int is_nc)
485
{
486
	char is_string = 0;
487
	GENERAL_NAME *gen = NULL;
488
489
	if (!value) {
490
		X509V3err(X509V3_F_A2I_GENERAL_NAME, X509V3_R_MISSING_VALUE);
491
		return NULL;
492
	}
493
494
	if (out)
495
		gen = out;
496
	else {
497
		gen = GENERAL_NAME_new();
498
		if (gen == NULL) {
499
			X509V3err(X509V3_F_A2I_GENERAL_NAME,
500
			    ERR_R_MALLOC_FAILURE);
501
			return NULL;
502
		}
503
	}
504
505
	switch (gen_type) {
506
	case GEN_URI:
507
	case GEN_EMAIL:
508
	case GEN_DNS:
509
		is_string = 1;
510
		break;
511
512
	case GEN_RID:
513
		{
514
			ASN1_OBJECT *obj;
515
			if (!(obj = OBJ_txt2obj(value, 0))) {
516
				X509V3err(X509V3_F_A2I_GENERAL_NAME,
517
				    X509V3_R_BAD_OBJECT);
518
				ERR_asprintf_error_data("value=%s", value);
519
				goto err;
520
			}
521
			gen->d.rid = obj;
522
		}
523
		break;
524
525
	case GEN_IPADD:
526
		if (is_nc)
527
			gen->d.ip = a2i_IPADDRESS_NC(value);
528
		else
529
			gen->d.ip = a2i_IPADDRESS(value);
530
		if (gen->d.ip == NULL) {
531
			X509V3err(X509V3_F_A2I_GENERAL_NAME,
532
			    X509V3_R_BAD_IP_ADDRESS);
533
			ERR_asprintf_error_data("value=%s", value);
534
			goto err;
535
		}
536
		break;
537
538
	case GEN_DIRNAME:
539
		if (!do_dirname(gen, value, ctx)) {
540
			X509V3err(X509V3_F_A2I_GENERAL_NAME,
541
			    X509V3_R_DIRNAME_ERROR);
542
			goto err;
543
		}
544
		break;
545
546
	case GEN_OTHERNAME:
547
		if (!do_othername(gen, value, ctx)) {
548
			X509V3err(X509V3_F_A2I_GENERAL_NAME,
549
			    X509V3_R_OTHERNAME_ERROR);
550
			goto err;
551
		}
552
		break;
553
554
	default:
555
		X509V3err(X509V3_F_A2I_GENERAL_NAME, X509V3_R_UNSUPPORTED_TYPE);
556
		goto err;
557
	}
558
559
	if (is_string) {
560
		if (!(gen->d.ia5 = ASN1_IA5STRING_new()) ||
561
		    !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
562
			strlen(value))) {
563
			X509V3err(X509V3_F_A2I_GENERAL_NAME,
564
			    ERR_R_MALLOC_FAILURE);
565
			goto err;
566
		}
567
	}
568
569
	gen->type = gen_type;
570
571
	return gen;
572
573
err:
574
	if (out == NULL)
575
		GENERAL_NAME_free(gen);
576
	return NULL;
577
}
578
579
GENERAL_NAME *
580
v2i_GENERAL_NAME_ex(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
581
    X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc)
582
{
583
	int type;
584
	char *name, *value;
585
586
	name = cnf->name;
587
	value = cnf->value;
588
589
	if (!value) {
590
		X509V3err(X509V3_F_V2I_GENERAL_NAME_EX, X509V3_R_MISSING_VALUE);
591
		return NULL;
592
	}
593
594
	if (!name_cmp(name, "email"))
595
		type = GEN_EMAIL;
596
	else if (!name_cmp(name, "URI"))
597
		type = GEN_URI;
598
	else if (!name_cmp(name, "DNS"))
599
		type = GEN_DNS;
600
	else if (!name_cmp(name, "RID"))
601
		type = GEN_RID;
602
	else if (!name_cmp(name, "IP"))
603
		type = GEN_IPADD;
604
	else if (!name_cmp(name, "dirName"))
605
		type = GEN_DIRNAME;
606
	else if (!name_cmp(name, "otherName"))
607
		type = GEN_OTHERNAME;
608
	else {
609
		X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,
610
		    X509V3_R_UNSUPPORTED_OPTION);
611
		ERR_asprintf_error_data("name=%s", name);
612
		return NULL;
613
	}
614
615
	return a2i_GENERAL_NAME(out, method, ctx, type, value, is_nc);
616
}
617
618
static int
619
do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
620
{
621
	char *objtmp = NULL, *p;
622
	int objlen;
623
624
	if (!(p = strchr(value, ';')))
625
		return 0;
626
	if (!(gen->d.otherName = OTHERNAME_new()))
627
		return 0;
628
	/* Free this up because we will overwrite it.
629
	 * no need to free type_id because it is static
630
	 */
631
	ASN1_TYPE_free(gen->d.otherName->value);
632
	if (!(gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx)))
633
		return 0;
634
	objlen = p - value;
635
	objtmp = malloc(objlen + 1);
636
	if (objtmp) {
637
		strlcpy(objtmp, value, objlen + 1);
638
		gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0);
639
		free(objtmp);
640
	} else
641
		gen->d.otherName->type_id = NULL;
642
	if (!gen->d.otherName->type_id)
643
		return 0;
644
	return 1;
645
}
646
647
static int
648
do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
649
{
650
	int ret;
651
	STACK_OF(CONF_VALUE) *sk;
652
	X509_NAME *nm;
653
654
	if (!(nm = X509_NAME_new()))
655
		return 0;
656
	sk = X509V3_get_section(ctx, value);
657
	if (!sk) {
658
		X509V3err(X509V3_F_DO_DIRNAME, X509V3_R_SECTION_NOT_FOUND);
659
		ERR_asprintf_error_data("section=%s", value);
660
		X509_NAME_free(nm);
661
		return 0;
662
	}
663
	/* FIXME: should allow other character types... */
664
	ret = X509V3_NAME_from_section(nm, sk, MBSTRING_ASC);
665
	if (!ret)
666
		X509_NAME_free(nm);
667
	gen->d.dirn = nm;
668
	X509V3_section_free(ctx, sk);
669
670
	return ret;
671
}