diff options
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_pci.c')
-rw-r--r-- | src/lib/libcrypto/x509v3/v3_pci.c | 327 |
1 files changed, 0 insertions, 327 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_pci.c b/src/lib/libcrypto/x509v3/v3_pci.c deleted file mode 100644 index d3f73352d9..0000000000 --- a/src/lib/libcrypto/x509v3/v3_pci.c +++ /dev/null | |||
@@ -1,327 +0,0 @@ | |||
1 | /* $OpenBSD: v3_pci.c,v 1.8 2014/07/11 08:44:49 jsing Exp $ */ | ||
2 | /* Contributed to the OpenSSL Project 2004 | ||
3 | * by Richard Levitte (richard@levitte.org) | ||
4 | */ | ||
5 | /* Copyright (c) 2004 Kungliga Tekniska Högskolan | ||
6 | * (Royal Institute of Technology, Stockholm, Sweden). | ||
7 | * All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * | ||
20 | * 3. Neither the name of the Institute nor the names of its contributors | ||
21 | * may be used to endorse or promote products derived from this software | ||
22 | * without specific prior written permission. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND | ||
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE | ||
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
34 | * SUCH DAMAGE. | ||
35 | */ | ||
36 | |||
37 | #include <stdio.h> | ||
38 | #include <string.h> | ||
39 | |||
40 | #include <openssl/conf.h> | ||
41 | #include <openssl/err.h> | ||
42 | #include <openssl/x509v3.h> | ||
43 | |||
44 | static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *ext, | ||
45 | BIO *out, int indent); | ||
46 | static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method, | ||
47 | X509V3_CTX *ctx, char *str); | ||
48 | |||
49 | const X509V3_EXT_METHOD v3_pci = { | ||
50 | NID_proxyCertInfo, 0, ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION), | ||
51 | 0, 0, 0, 0, 0, 0, NULL, NULL, | ||
52 | (X509V3_EXT_I2R)i2r_pci, | ||
53 | (X509V3_EXT_R2I)r2i_pci, | ||
54 | NULL, | ||
55 | }; | ||
56 | |||
57 | static int | ||
58 | i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *pci, BIO *out, | ||
59 | int indent) | ||
60 | { | ||
61 | BIO_printf(out, "%*sPath Length Constraint: ", indent, ""); | ||
62 | if (pci->pcPathLengthConstraint) | ||
63 | i2a_ASN1_INTEGER(out, pci->pcPathLengthConstraint); | ||
64 | else | ||
65 | BIO_printf(out, "infinite"); | ||
66 | BIO_puts(out, "\n"); | ||
67 | BIO_printf(out, "%*sPolicy Language: ", indent, ""); | ||
68 | i2a_ASN1_OBJECT(out, pci->proxyPolicy->policyLanguage); | ||
69 | BIO_puts(out, "\n"); | ||
70 | if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data) | ||
71 | BIO_printf(out, "%*sPolicy Text: %s\n", indent, "", | ||
72 | pci->proxyPolicy->policy->data); | ||
73 | return 1; | ||
74 | } | ||
75 | |||
76 | static int | ||
77 | process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language, | ||
78 | ASN1_INTEGER **pathlen, ASN1_OCTET_STRING **policy) | ||
79 | { | ||
80 | int free_policy = 0; | ||
81 | |||
82 | if (strcmp(val->name, "language") == 0) { | ||
83 | if (*language) { | ||
84 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
85 | X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED); | ||
86 | X509V3_conf_err(val); | ||
87 | return 0; | ||
88 | } | ||
89 | if (!(*language = OBJ_txt2obj(val->value, 0))) { | ||
90 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
91 | X509V3_R_INVALID_OBJECT_IDENTIFIER); | ||
92 | X509V3_conf_err(val); | ||
93 | return 0; | ||
94 | } | ||
95 | } | ||
96 | else if (strcmp(val->name, "pathlen") == 0) { | ||
97 | if (*pathlen) { | ||
98 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
99 | X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED); | ||
100 | X509V3_conf_err(val); | ||
101 | return 0; | ||
102 | } | ||
103 | if (!X509V3_get_value_int(val, pathlen)) { | ||
104 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
105 | X509V3_R_POLICY_PATH_LENGTH); | ||
106 | X509V3_conf_err(val); | ||
107 | return 0; | ||
108 | } | ||
109 | } | ||
110 | else if (strcmp(val->name, "policy") == 0) { | ||
111 | unsigned char *tmp_data = NULL; | ||
112 | long val_len; | ||
113 | if (!*policy) { | ||
114 | *policy = ASN1_OCTET_STRING_new(); | ||
115 | if (!*policy) { | ||
116 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
117 | ERR_R_MALLOC_FAILURE); | ||
118 | X509V3_conf_err(val); | ||
119 | return 0; | ||
120 | } | ||
121 | free_policy = 1; | ||
122 | } | ||
123 | if (strncmp(val->value, "hex:", 4) == 0) { | ||
124 | unsigned char *tmp_data2 = | ||
125 | string_to_hex(val->value + 4, &val_len); | ||
126 | |||
127 | if (!tmp_data2) { | ||
128 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
129 | X509V3_R_ILLEGAL_HEX_DIGIT); | ||
130 | X509V3_conf_err(val); | ||
131 | goto err; | ||
132 | } | ||
133 | |||
134 | tmp_data = realloc((*policy)->data, | ||
135 | (*policy)->length + val_len + 1); | ||
136 | if (tmp_data) { | ||
137 | (*policy)->data = tmp_data; | ||
138 | memcpy(&(*policy)->data[(*policy)->length], | ||
139 | tmp_data2, val_len); | ||
140 | (*policy)->length += val_len; | ||
141 | (*policy)->data[(*policy)->length] = '\0'; | ||
142 | } else { | ||
143 | free(tmp_data2); | ||
144 | free((*policy)->data); | ||
145 | (*policy)->data = NULL; | ||
146 | (*policy)->length = 0; | ||
147 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
148 | ERR_R_MALLOC_FAILURE); | ||
149 | X509V3_conf_err(val); | ||
150 | goto err; | ||
151 | } | ||
152 | free(tmp_data2); | ||
153 | } | ||
154 | else if (strncmp(val->value, "file:", 5) == 0) { | ||
155 | unsigned char buf[2048]; | ||
156 | int n; | ||
157 | BIO *b = BIO_new_file(val->value + 5, "r"); | ||
158 | if (!b) { | ||
159 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
160 | ERR_R_BIO_LIB); | ||
161 | X509V3_conf_err(val); | ||
162 | goto err; | ||
163 | } | ||
164 | while ((n = BIO_read(b, buf, sizeof(buf))) > 0 || | ||
165 | (n == 0 && BIO_should_retry(b))) { | ||
166 | if (!n) | ||
167 | continue; | ||
168 | |||
169 | tmp_data = realloc((*policy)->data, | ||
170 | (*policy)->length + n + 1); | ||
171 | |||
172 | if (!tmp_data) | ||
173 | break; | ||
174 | |||
175 | (*policy)->data = tmp_data; | ||
176 | memcpy(&(*policy)->data[(*policy)->length], | ||
177 | buf, n); | ||
178 | (*policy)->length += n; | ||
179 | (*policy)->data[(*policy)->length] = '\0'; | ||
180 | } | ||
181 | BIO_free_all(b); | ||
182 | |||
183 | if (n < 0) { | ||
184 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
185 | ERR_R_BIO_LIB); | ||
186 | X509V3_conf_err(val); | ||
187 | goto err; | ||
188 | } | ||
189 | } | ||
190 | else if (strncmp(val->value, "text:", 5) == 0) { | ||
191 | val_len = strlen(val->value + 5); | ||
192 | tmp_data = realloc((*policy)->data, | ||
193 | (*policy)->length + val_len + 1); | ||
194 | if (tmp_data) { | ||
195 | (*policy)->data = tmp_data; | ||
196 | memcpy(&(*policy)->data[(*policy)->length], | ||
197 | val->value + 5, val_len); | ||
198 | (*policy)->length += val_len; | ||
199 | (*policy)->data[(*policy)->length] = '\0'; | ||
200 | } else { | ||
201 | free((*policy)->data); | ||
202 | (*policy)->data = NULL; | ||
203 | (*policy)->length = 0; | ||
204 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
205 | ERR_R_MALLOC_FAILURE); | ||
206 | X509V3_conf_err(val); | ||
207 | goto err; | ||
208 | } | ||
209 | } else { | ||
210 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
211 | X509V3_R_INCORRECT_POLICY_SYNTAX_TAG); | ||
212 | X509V3_conf_err(val); | ||
213 | goto err; | ||
214 | } | ||
215 | if (!tmp_data) { | ||
216 | X509V3err(X509V3_F_PROCESS_PCI_VALUE, | ||
217 | ERR_R_MALLOC_FAILURE); | ||
218 | X509V3_conf_err(val); | ||
219 | goto err; | ||
220 | } | ||
221 | } | ||
222 | return 1; | ||
223 | |||
224 | err: | ||
225 | if (free_policy) { | ||
226 | ASN1_OCTET_STRING_free(*policy); | ||
227 | *policy = NULL; | ||
228 | } | ||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static PROXY_CERT_INFO_EXTENSION * | ||
233 | r2i_pci(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value) | ||
234 | { | ||
235 | PROXY_CERT_INFO_EXTENSION *pci = NULL; | ||
236 | STACK_OF(CONF_VALUE) *vals; | ||
237 | ASN1_OBJECT *language = NULL; | ||
238 | ASN1_INTEGER *pathlen = NULL; | ||
239 | ASN1_OCTET_STRING *policy = NULL; | ||
240 | int i, j; | ||
241 | |||
242 | vals = X509V3_parse_list(value); | ||
243 | for (i = 0; i < sk_CONF_VALUE_num(vals); i++) { | ||
244 | CONF_VALUE *cnf = sk_CONF_VALUE_value(vals, i); | ||
245 | if (!cnf->name || (*cnf->name != '@' && !cnf->value)) { | ||
246 | X509V3err(X509V3_F_R2I_PCI, | ||
247 | X509V3_R_INVALID_PROXY_POLICY_SETTING); | ||
248 | X509V3_conf_err(cnf); | ||
249 | goto err; | ||
250 | } | ||
251 | if (*cnf->name == '@') { | ||
252 | STACK_OF(CONF_VALUE) *sect; | ||
253 | int success_p = 1; | ||
254 | |||
255 | sect = X509V3_get_section(ctx, cnf->name + 1); | ||
256 | if (!sect) { | ||
257 | X509V3err(X509V3_F_R2I_PCI, | ||
258 | X509V3_R_INVALID_SECTION); | ||
259 | X509V3_conf_err(cnf); | ||
260 | goto err; | ||
261 | } | ||
262 | for (j = 0; success_p && | ||
263 | j < sk_CONF_VALUE_num(sect); j++) { | ||
264 | success_p = process_pci_value( | ||
265 | sk_CONF_VALUE_value(sect, j), | ||
266 | &language, &pathlen, &policy); | ||
267 | } | ||
268 | X509V3_section_free(ctx, sect); | ||
269 | if (!success_p) | ||
270 | goto err; | ||
271 | } else { | ||
272 | if (!process_pci_value(cnf, | ||
273 | &language, &pathlen, &policy)) { | ||
274 | X509V3_conf_err(cnf); | ||
275 | goto err; | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | |||
280 | /* Language is mandatory */ | ||
281 | if (!language) { | ||
282 | X509V3err(X509V3_F_R2I_PCI, | ||
283 | X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED); | ||
284 | goto err; | ||
285 | } | ||
286 | i = OBJ_obj2nid(language); | ||
287 | if ((i == NID_Independent || i == NID_id_ppl_inheritAll) && policy) { | ||
288 | X509V3err(X509V3_F_R2I_PCI, | ||
289 | X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY); | ||
290 | goto err; | ||
291 | } | ||
292 | |||
293 | pci = PROXY_CERT_INFO_EXTENSION_new(); | ||
294 | if (!pci) { | ||
295 | X509V3err(X509V3_F_R2I_PCI, ERR_R_MALLOC_FAILURE); | ||
296 | goto err; | ||
297 | } | ||
298 | |||
299 | pci->proxyPolicy->policyLanguage = language; | ||
300 | language = NULL; | ||
301 | pci->proxyPolicy->policy = policy; | ||
302 | policy = NULL; | ||
303 | pci->pcPathLengthConstraint = pathlen; | ||
304 | pathlen = NULL; | ||
305 | goto end; | ||
306 | |||
307 | err: | ||
308 | if (language) { | ||
309 | ASN1_OBJECT_free(language); | ||
310 | language = NULL; | ||
311 | } | ||
312 | if (pathlen) { | ||
313 | ASN1_INTEGER_free(pathlen); | ||
314 | pathlen = NULL; | ||
315 | } | ||
316 | if (policy) { | ||
317 | ASN1_OCTET_STRING_free(policy); | ||
318 | policy = NULL; | ||
319 | } | ||
320 | if (pci) { | ||
321 | PROXY_CERT_INFO_EXTENSION_free(pci); | ||
322 | pci = NULL; | ||
323 | } | ||
324 | end: | ||
325 | sk_CONF_VALUE_pop_free(vals, X509V3_conf_free); | ||
326 | return pci; | ||
327 | } | ||