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

Line Branch Exec Source
1
/* $OpenBSD: v3_extku.c,v 1.13 2015/07/29 16:13:48 jsing Exp $ */
2
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3
 * project 1999.
4
 */
5
/* ====================================================================
6
 * Copyright (c) 1999 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
61
#include <openssl/asn1t.h>
62
#include <openssl/conf.h>
63
#include <openssl/err.h>
64
#include <openssl/x509v3.h>
65
66
static void *v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method,
67
    X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
68
static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(
69
    const X509V3_EXT_METHOD *method, void *eku, STACK_OF(CONF_VALUE) *extlist);
70
71
const X509V3_EXT_METHOD v3_ext_ku = {
72
	.ext_nid = NID_ext_key_usage,
73
	.ext_flags = 0,
74
	.it = ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
75
	.ext_new = NULL,
76
	.ext_free = NULL,
77
	.d2i = NULL,
78
	.i2d = NULL,
79
	.i2s = NULL,
80
	.s2i = NULL,
81
	.i2v = i2v_EXTENDED_KEY_USAGE,
82
	.v2i = v2i_EXTENDED_KEY_USAGE,
83
	.i2r = NULL,
84
	.r2i = NULL,
85
	.usr_data = NULL,
86
};
87
88
/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
89
const X509V3_EXT_METHOD v3_ocsp_accresp = {
90
	.ext_nid = NID_id_pkix_OCSP_acceptableResponses,
91
	.ext_flags = 0,
92
	.it = ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
93
	.ext_new = NULL,
94
	.ext_free = NULL,
95
	.d2i = NULL,
96
	.i2d = NULL,
97
	.i2s = NULL,
98
	.s2i = NULL,
99
	.i2v = i2v_EXTENDED_KEY_USAGE,
100
	.v2i = v2i_EXTENDED_KEY_USAGE,
101
	.i2r = NULL,
102
	.r2i = NULL,
103
	.usr_data = NULL,
104
};
105
106
static const ASN1_TEMPLATE EXTENDED_KEY_USAGE_item_tt = {
107
	.flags = ASN1_TFLG_SEQUENCE_OF,
108
	.tag = 0,
109
	.offset = 0,
110
	.field_name = "EXTENDED_KEY_USAGE",
111
	.item = &ASN1_OBJECT_it,
112
};
113
114
const ASN1_ITEM EXTENDED_KEY_USAGE_it = {
115
	.itype = ASN1_ITYPE_PRIMITIVE,
116
	.utype = -1,
117
	.templates = &EXTENDED_KEY_USAGE_item_tt,
118
	.tcount = 0,
119
	.funcs = NULL,
120
	.size = 0,
121
	.sname = "EXTENDED_KEY_USAGE",
122
};
123
124
125
EXTENDED_KEY_USAGE *
126
d2i_EXTENDED_KEY_USAGE(EXTENDED_KEY_USAGE **a, const unsigned char **in, long len)
127
{
128
	return (EXTENDED_KEY_USAGE *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
129
	    &EXTENDED_KEY_USAGE_it);
130
}
131
132
int
133
i2d_EXTENDED_KEY_USAGE(EXTENDED_KEY_USAGE *a, unsigned char **out)
134
{
135
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &EXTENDED_KEY_USAGE_it);
136
}
137
138
EXTENDED_KEY_USAGE *
139
EXTENDED_KEY_USAGE_new(void)
140
{
141
	return (EXTENDED_KEY_USAGE *)ASN1_item_new(&EXTENDED_KEY_USAGE_it);
142
}
143
144
void
145
EXTENDED_KEY_USAGE_free(EXTENDED_KEY_USAGE *a)
146
{
147
	ASN1_item_free((ASN1_VALUE *)a, &EXTENDED_KEY_USAGE_it);
148
}
149
150
static STACK_OF(CONF_VALUE) *
151
i2v_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, void *a,
152
    STACK_OF(CONF_VALUE) *ext_list)
153
{
154
	EXTENDED_KEY_USAGE *eku = a;
155
	int i;
156
	ASN1_OBJECT *obj;
157
	char obj_tmp[80];
158
159
	for (i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
160
		obj = sk_ASN1_OBJECT_value(eku, i);
161
		i2t_ASN1_OBJECT(obj_tmp, 80, obj);
162
		X509V3_add_value(NULL, obj_tmp, &ext_list);
163
	}
164
	return ext_list;
165
}
166
167
static void *
168
v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
169
    STACK_OF(CONF_VALUE) *nval)
170
{
171
	EXTENDED_KEY_USAGE *extku;
172
	char *extval;
173
	ASN1_OBJECT *objtmp;
174
	CONF_VALUE *val;
175
	int i;
176
177
	if (!(extku = sk_ASN1_OBJECT_new_null())) {
178
		X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,
179
		    ERR_R_MALLOC_FAILURE);
180
		return NULL;
181
	}
182
183
	for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
184
		val = sk_CONF_VALUE_value(nval, i);
185
		if (val->value)
186
			extval = val->value;
187
		else
188
			extval = val->name;
189
		if (!(objtmp = OBJ_txt2obj(extval, 0))) {
190
			sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
191
			X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,
192
			    X509V3_R_INVALID_OBJECT_IDENTIFIER);
193
			X509V3_conf_err(val);
194
			return NULL;
195
		}
196
		if (sk_ASN1_OBJECT_push(extku, objtmp) == 0) {
197
			ASN1_OBJECT_free(objtmp);
198
			sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
199
			X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,
200
			    ERR_R_MALLOC_FAILURE);
201
			return NULL;
202
		}
203
	}
204
	return extku;
205
}