diff options
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_alt.c')
-rw-r--r-- | src/lib/libcrypto/x509v3/v3_alt.c | 458 |
1 files changed, 0 insertions, 458 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c deleted file mode 100644 index 58b935a3b6..0000000000 --- a/src/lib/libcrypto/x509v3/v3_alt.c +++ /dev/null | |||
@@ -1,458 +0,0 @@ | |||
1 | /* v3_alt.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) 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 | #include "cryptlib.h" | ||
61 | #include <openssl/conf.h> | ||
62 | #include <openssl/x509v3.h> | ||
63 | |||
64 | static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); | ||
65 | static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); | ||
66 | static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p); | ||
67 | static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens); | ||
68 | X509V3_EXT_METHOD v3_alt[] = { | ||
69 | { NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES), | ||
70 | 0,0,0,0, | ||
71 | 0,0, | ||
72 | (X509V3_EXT_I2V)i2v_GENERAL_NAMES, | ||
73 | (X509V3_EXT_V2I)v2i_subject_alt, | ||
74 | NULL, NULL, NULL}, | ||
75 | |||
76 | { NID_issuer_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES), | ||
77 | 0,0,0,0, | ||
78 | 0,0, | ||
79 | (X509V3_EXT_I2V)i2v_GENERAL_NAMES, | ||
80 | (X509V3_EXT_V2I)v2i_issuer_alt, | ||
81 | NULL, NULL, NULL}, | ||
82 | }; | ||
83 | |||
84 | STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, | ||
85 | GENERAL_NAMES *gens, STACK_OF(CONF_VALUE) *ret) | ||
86 | { | ||
87 | int i; | ||
88 | GENERAL_NAME *gen; | ||
89 | for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) { | ||
90 | gen = sk_GENERAL_NAME_value(gens, i); | ||
91 | ret = i2v_GENERAL_NAME(method, gen, ret); | ||
92 | } | ||
93 | if(!ret) return sk_CONF_VALUE_new_null(); | ||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, | ||
98 | GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret) | ||
99 | { | ||
100 | unsigned char *p; | ||
101 | char oline[256]; | ||
102 | switch (gen->type) | ||
103 | { | ||
104 | case GEN_OTHERNAME: | ||
105 | X509V3_add_value("othername","<unsupported>", &ret); | ||
106 | break; | ||
107 | |||
108 | case GEN_X400: | ||
109 | X509V3_add_value("X400Name","<unsupported>", &ret); | ||
110 | break; | ||
111 | |||
112 | case GEN_EDIPARTY: | ||
113 | X509V3_add_value("EdiPartyName","<unsupported>", &ret); | ||
114 | break; | ||
115 | |||
116 | case GEN_EMAIL: | ||
117 | X509V3_add_value_uchar("email",gen->d.ia5->data, &ret); | ||
118 | break; | ||
119 | |||
120 | case GEN_DNS: | ||
121 | X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret); | ||
122 | break; | ||
123 | |||
124 | case GEN_URI: | ||
125 | X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret); | ||
126 | break; | ||
127 | |||
128 | case GEN_DIRNAME: | ||
129 | X509_NAME_oneline(gen->d.dirn, oline, 256); | ||
130 | X509V3_add_value("DirName",oline, &ret); | ||
131 | break; | ||
132 | |||
133 | case GEN_IPADD: | ||
134 | p = gen->d.ip->data; | ||
135 | /* BUG: doesn't support IPV6 */ | ||
136 | if(gen->d.ip->length != 4) { | ||
137 | X509V3_add_value("IP Address","<invalid>", &ret); | ||
138 | break; | ||
139 | } | ||
140 | BIO_snprintf(oline, sizeof oline, | ||
141 | "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); | ||
142 | X509V3_add_value("IP Address",oline, &ret); | ||
143 | break; | ||
144 | |||
145 | case GEN_RID: | ||
146 | i2t_ASN1_OBJECT(oline, 256, gen->d.rid); | ||
147 | X509V3_add_value("Registered ID",oline, &ret); | ||
148 | break; | ||
149 | } | ||
150 | return ret; | ||
151 | } | ||
152 | |||
153 | int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen) | ||
154 | { | ||
155 | unsigned char *p; | ||
156 | switch (gen->type) | ||
157 | { | ||
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:%s",gen->d.ia5->data); | ||
173 | break; | ||
174 | |||
175 | case GEN_DNS: | ||
176 | BIO_printf(out, "DNS:%s",gen->d.ia5->data); | ||
177 | break; | ||
178 | |||
179 | case GEN_URI: | ||
180 | BIO_printf(out, "URI:%s",gen->d.ia5->data); | ||
181 | break; | ||
182 | |||
183 | case GEN_DIRNAME: | ||
184 | BIO_printf(out, "DirName: "); | ||
185 | X509_NAME_print_ex(out, gen->d.dirn, 0, XN_FLAG_ONELINE); | ||
186 | break; | ||
187 | |||
188 | case GEN_IPADD: | ||
189 | p = gen->d.ip->data; | ||
190 | /* BUG: doesn't support IPV6 */ | ||
191 | if(gen->d.ip->length != 4) { | ||
192 | BIO_printf(out,"IP Address:<invalid>"); | ||
193 | break; | ||
194 | } | ||
195 | BIO_printf(out, "IP Address:%d.%d.%d.%d", p[0], p[1], p[2], p[3]); | ||
196 | break; | ||
197 | |||
198 | case GEN_RID: | ||
199 | BIO_printf(out, "Registered ID"); | ||
200 | i2a_ASN1_OBJECT(out, gen->d.rid); | ||
201 | break; | ||
202 | } | ||
203 | return 1; | ||
204 | } | ||
205 | |||
206 | static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, | ||
207 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) | ||
208 | { | ||
209 | GENERAL_NAMES *gens = NULL; | ||
210 | CONF_VALUE *cnf; | ||
211 | int i; | ||
212 | if(!(gens = sk_GENERAL_NAME_new_null())) { | ||
213 | X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE); | ||
214 | return NULL; | ||
215 | } | ||
216 | for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { | ||
217 | cnf = sk_CONF_VALUE_value(nval, i); | ||
218 | if(!name_cmp(cnf->name, "issuer") && cnf->value && | ||
219 | !strcmp(cnf->value, "copy")) { | ||
220 | if(!copy_issuer(ctx, gens)) goto err; | ||
221 | } else { | ||
222 | GENERAL_NAME *gen; | ||
223 | if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) | ||
224 | goto err; | ||
225 | sk_GENERAL_NAME_push(gens, gen); | ||
226 | } | ||
227 | } | ||
228 | return gens; | ||
229 | err: | ||
230 | sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); | ||
231 | return NULL; | ||
232 | } | ||
233 | |||
234 | /* Append subject altname of issuer to issuer alt name of subject */ | ||
235 | |||
236 | static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens) | ||
237 | { | ||
238 | GENERAL_NAMES *ialt; | ||
239 | GENERAL_NAME *gen; | ||
240 | X509_EXTENSION *ext; | ||
241 | int i; | ||
242 | if(ctx && (ctx->flags == CTX_TEST)) return 1; | ||
243 | if(!ctx || !ctx->issuer_cert) { | ||
244 | X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS); | ||
245 | goto err; | ||
246 | } | ||
247 | i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1); | ||
248 | if(i < 0) return 1; | ||
249 | if(!(ext = X509_get_ext(ctx->issuer_cert, i)) || | ||
250 | !(ialt = X509V3_EXT_d2i(ext)) ) { | ||
251 | X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR); | ||
252 | goto err; | ||
253 | } | ||
254 | |||
255 | for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) { | ||
256 | gen = sk_GENERAL_NAME_value(ialt, i); | ||
257 | if(!sk_GENERAL_NAME_push(gens, gen)) { | ||
258 | X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE); | ||
259 | goto err; | ||
260 | } | ||
261 | } | ||
262 | sk_GENERAL_NAME_free(ialt); | ||
263 | |||
264 | return 1; | ||
265 | |||
266 | err: | ||
267 | return 0; | ||
268 | |||
269 | } | ||
270 | |||
271 | static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, | ||
272 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) | ||
273 | { | ||
274 | GENERAL_NAMES *gens = NULL; | ||
275 | CONF_VALUE *cnf; | ||
276 | int i; | ||
277 | if(!(gens = sk_GENERAL_NAME_new_null())) { | ||
278 | X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE); | ||
279 | return NULL; | ||
280 | } | ||
281 | for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { | ||
282 | cnf = sk_CONF_VALUE_value(nval, i); | ||
283 | if(!name_cmp(cnf->name, "email") && cnf->value && | ||
284 | !strcmp(cnf->value, "copy")) { | ||
285 | if(!copy_email(ctx, gens, 0)) goto err; | ||
286 | } else if(!name_cmp(cnf->name, "email") && cnf->value && | ||
287 | !strcmp(cnf->value, "move")) { | ||
288 | if(!copy_email(ctx, gens, 1)) goto err; | ||
289 | } else { | ||
290 | GENERAL_NAME *gen; | ||
291 | if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) | ||
292 | goto err; | ||
293 | sk_GENERAL_NAME_push(gens, gen); | ||
294 | } | ||
295 | } | ||
296 | return gens; | ||
297 | err: | ||
298 | sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); | ||
299 | return NULL; | ||
300 | } | ||
301 | |||
302 | /* Copy any email addresses in a certificate or request to | ||
303 | * GENERAL_NAMES | ||
304 | */ | ||
305 | |||
306 | static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p) | ||
307 | { | ||
308 | X509_NAME *nm; | ||
309 | ASN1_IA5STRING *email = NULL; | ||
310 | X509_NAME_ENTRY *ne; | ||
311 | GENERAL_NAME *gen = NULL; | ||
312 | int i; | ||
313 | if(ctx->flags == CTX_TEST) return 1; | ||
314 | if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) { | ||
315 | X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS); | ||
316 | goto err; | ||
317 | } | ||
318 | /* Find the subject name */ | ||
319 | if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert); | ||
320 | else nm = X509_REQ_get_subject_name(ctx->subject_req); | ||
321 | |||
322 | /* Now add any email address(es) to STACK */ | ||
323 | i = -1; | ||
324 | while((i = X509_NAME_get_index_by_NID(nm, | ||
325 | NID_pkcs9_emailAddress, i)) >= 0) { | ||
326 | ne = X509_NAME_get_entry(nm, i); | ||
327 | email = M_ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne)); | ||
328 | if (move_p) | ||
329 | { | ||
330 | X509_NAME_delete_entry(nm, i); | ||
331 | i--; | ||
332 | } | ||
333 | if(!email || !(gen = GENERAL_NAME_new())) { | ||
334 | X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE); | ||
335 | goto err; | ||
336 | } | ||
337 | gen->d.ia5 = email; | ||
338 | email = NULL; | ||
339 | gen->type = GEN_EMAIL; | ||
340 | if(!sk_GENERAL_NAME_push(gens, gen)) { | ||
341 | X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE); | ||
342 | goto err; | ||
343 | } | ||
344 | gen = NULL; | ||
345 | } | ||
346 | |||
347 | |||
348 | return 1; | ||
349 | |||
350 | err: | ||
351 | GENERAL_NAME_free(gen); | ||
352 | M_ASN1_IA5STRING_free(email); | ||
353 | return 0; | ||
354 | |||
355 | } | ||
356 | |||
357 | GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method, | ||
358 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) | ||
359 | { | ||
360 | GENERAL_NAME *gen; | ||
361 | GENERAL_NAMES *gens = NULL; | ||
362 | CONF_VALUE *cnf; | ||
363 | int i; | ||
364 | if(!(gens = sk_GENERAL_NAME_new_null())) { | ||
365 | X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE); | ||
366 | return NULL; | ||
367 | } | ||
368 | for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { | ||
369 | cnf = sk_CONF_VALUE_value(nval, i); | ||
370 | if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err; | ||
371 | sk_GENERAL_NAME_push(gens, gen); | ||
372 | } | ||
373 | return gens; | ||
374 | err: | ||
375 | sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); | ||
376 | return NULL; | ||
377 | } | ||
378 | |||
379 | GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, | ||
380 | CONF_VALUE *cnf) | ||
381 | { | ||
382 | char is_string = 0; | ||
383 | int type; | ||
384 | GENERAL_NAME *gen = NULL; | ||
385 | |||
386 | char *name, *value; | ||
387 | |||
388 | name = cnf->name; | ||
389 | value = cnf->value; | ||
390 | |||
391 | if(!value) { | ||
392 | X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE); | ||
393 | return NULL; | ||
394 | } | ||
395 | |||
396 | if(!(gen = GENERAL_NAME_new())) { | ||
397 | X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); | ||
398 | return NULL; | ||
399 | } | ||
400 | |||
401 | if(!name_cmp(name, "email")) { | ||
402 | is_string = 1; | ||
403 | type = GEN_EMAIL; | ||
404 | } else if(!name_cmp(name, "URI")) { | ||
405 | is_string = 1; | ||
406 | type = GEN_URI; | ||
407 | } else if(!name_cmp(name, "DNS")) { | ||
408 | is_string = 1; | ||
409 | type = GEN_DNS; | ||
410 | } else if(!name_cmp(name, "RID")) { | ||
411 | ASN1_OBJECT *obj; | ||
412 | if(!(obj = OBJ_txt2obj(value,0))) { | ||
413 | X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT); | ||
414 | ERR_add_error_data(2, "value=", value); | ||
415 | goto err; | ||
416 | } | ||
417 | gen->d.rid = obj; | ||
418 | type = GEN_RID; | ||
419 | } else if(!name_cmp(name, "IP")) { | ||
420 | int i1,i2,i3,i4; | ||
421 | unsigned char ip[4]; | ||
422 | if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) || | ||
423 | (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) || | ||
424 | (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) { | ||
425 | X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS); | ||
426 | ERR_add_error_data(2, "value=", value); | ||
427 | goto err; | ||
428 | } | ||
429 | ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4; | ||
430 | if(!(gen->d.ip = M_ASN1_OCTET_STRING_new()) || | ||
431 | !ASN1_STRING_set(gen->d.ip, ip, 4)) { | ||
432 | X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); | ||
433 | goto err; | ||
434 | } | ||
435 | type = GEN_IPADD; | ||
436 | } else { | ||
437 | X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION); | ||
438 | ERR_add_error_data(2, "name=", name); | ||
439 | goto err; | ||
440 | } | ||
441 | |||
442 | if(is_string) { | ||
443 | if(!(gen->d.ia5 = M_ASN1_IA5STRING_new()) || | ||
444 | !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value, | ||
445 | strlen(value))) { | ||
446 | X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); | ||
447 | goto err; | ||
448 | } | ||
449 | } | ||
450 | |||
451 | gen->type = type; | ||
452 | |||
453 | return gen; | ||
454 | |||
455 | err: | ||
456 | GENERAL_NAME_free(gen); | ||
457 | return NULL; | ||
458 | } | ||