diff options
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_cpols.c')
-rw-r--r-- | src/lib/libcrypto/x509v3/v3_cpols.c | 655 |
1 files changed, 655 insertions, 0 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c new file mode 100644 index 0000000000..b4d4883545 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_cpols.c | |||
@@ -0,0 +1,655 @@ | |||
1 | /* v3_cpols.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/asn1.h> | ||
63 | #include <openssl/asn1_mac.h> | ||
64 | #include <openssl/x509v3.h> | ||
65 | |||
66 | /* Certificate policies extension support: this one is a bit complex... */ | ||
67 | |||
68 | static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent); | ||
69 | static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value); | ||
70 | static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent); | ||
71 | static void print_notice(BIO *out, USERNOTICE *notice, int indent); | ||
72 | static POLICYINFO *policy_section(X509V3_CTX *ctx, | ||
73 | STACK_OF(CONF_VALUE) *polstrs, int ia5org); | ||
74 | static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, | ||
75 | STACK_OF(CONF_VALUE) *unot, int ia5org); | ||
76 | static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos); | ||
77 | |||
78 | X509V3_EXT_METHOD v3_cpols = { | ||
79 | NID_certificate_policies, 0, | ||
80 | (X509V3_EXT_NEW)CERTIFICATEPOLICIES_new, | ||
81 | (X509V3_EXT_FREE)CERTIFICATEPOLICIES_free, | ||
82 | (X509V3_EXT_D2I)d2i_CERTIFICATEPOLICIES, | ||
83 | (X509V3_EXT_I2D)i2d_CERTIFICATEPOLICIES, | ||
84 | NULL, NULL, | ||
85 | NULL, NULL, | ||
86 | (X509V3_EXT_I2R)i2r_certpol, | ||
87 | (X509V3_EXT_R2I)r2i_certpol, | ||
88 | NULL | ||
89 | }; | ||
90 | |||
91 | |||
92 | static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, | ||
93 | X509V3_CTX *ctx, char *value) | ||
94 | { | ||
95 | STACK_OF(POLICYINFO) *pols = NULL; | ||
96 | char *pstr; | ||
97 | POLICYINFO *pol; | ||
98 | ASN1_OBJECT *pobj; | ||
99 | STACK_OF(CONF_VALUE) *vals; | ||
100 | CONF_VALUE *cnf; | ||
101 | int i, ia5org; | ||
102 | pols = sk_POLICYINFO_new_null(); | ||
103 | vals = X509V3_parse_list(value); | ||
104 | ia5org = 0; | ||
105 | for(i = 0; i < sk_CONF_VALUE_num(vals); i++) { | ||
106 | cnf = sk_CONF_VALUE_value(vals, i); | ||
107 | if(cnf->value || !cnf->name ) { | ||
108 | X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER); | ||
109 | X509V3_conf_err(cnf); | ||
110 | goto err; | ||
111 | } | ||
112 | pstr = cnf->name; | ||
113 | if(!strcmp(pstr,"ia5org")) { | ||
114 | ia5org = 1; | ||
115 | continue; | ||
116 | } else if(*pstr == '@') { | ||
117 | STACK_OF(CONF_VALUE) *polsect; | ||
118 | polsect = X509V3_get_section(ctx, pstr + 1); | ||
119 | if(!polsect) { | ||
120 | X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION); | ||
121 | |||
122 | X509V3_conf_err(cnf); | ||
123 | goto err; | ||
124 | } | ||
125 | pol = policy_section(ctx, polsect, ia5org); | ||
126 | X509V3_section_free(ctx, polsect); | ||
127 | if(!pol) goto err; | ||
128 | } else { | ||
129 | if(!(pobj = OBJ_txt2obj(cnf->name, 0))) { | ||
130 | X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER); | ||
131 | X509V3_conf_err(cnf); | ||
132 | goto err; | ||
133 | } | ||
134 | pol = POLICYINFO_new(); | ||
135 | pol->policyid = pobj; | ||
136 | } | ||
137 | sk_POLICYINFO_push(pols, pol); | ||
138 | } | ||
139 | sk_CONF_VALUE_pop_free(vals, X509V3_conf_free); | ||
140 | return pols; | ||
141 | err: | ||
142 | sk_POLICYINFO_pop_free(pols, POLICYINFO_free); | ||
143 | return NULL; | ||
144 | } | ||
145 | |||
146 | static POLICYINFO *policy_section(X509V3_CTX *ctx, | ||
147 | STACK_OF(CONF_VALUE) *polstrs, int ia5org) | ||
148 | { | ||
149 | int i; | ||
150 | CONF_VALUE *cnf; | ||
151 | POLICYINFO *pol; | ||
152 | POLICYQUALINFO *qual; | ||
153 | if(!(pol = POLICYINFO_new())) goto merr; | ||
154 | for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) { | ||
155 | cnf = sk_CONF_VALUE_value(polstrs, i); | ||
156 | if(!strcmp(cnf->name, "policyIdentifier")) { | ||
157 | ASN1_OBJECT *pobj; | ||
158 | if(!(pobj = OBJ_txt2obj(cnf->value, 0))) { | ||
159 | X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER); | ||
160 | X509V3_conf_err(cnf); | ||
161 | goto err; | ||
162 | } | ||
163 | pol->policyid = pobj; | ||
164 | |||
165 | } else if(!name_cmp(cnf->name, "CPS")) { | ||
166 | if(!pol->qualifiers) pol->qualifiers = | ||
167 | sk_POLICYQUALINFO_new_null(); | ||
168 | if(!(qual = POLICYQUALINFO_new())) goto merr; | ||
169 | if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) | ||
170 | goto merr; | ||
171 | qual->pqualid = OBJ_nid2obj(NID_id_qt_cps); | ||
172 | qual->d.cpsuri = ASN1_IA5STRING_new(); | ||
173 | if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value, | ||
174 | strlen(cnf->value))) goto merr; | ||
175 | } else if(!name_cmp(cnf->name, "userNotice")) { | ||
176 | STACK_OF(CONF_VALUE) *unot; | ||
177 | if(*cnf->value != '@') { | ||
178 | X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME); | ||
179 | X509V3_conf_err(cnf); | ||
180 | goto err; | ||
181 | } | ||
182 | unot = X509V3_get_section(ctx, cnf->value + 1); | ||
183 | if(!unot) { | ||
184 | X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION); | ||
185 | |||
186 | X509V3_conf_err(cnf); | ||
187 | goto err; | ||
188 | } | ||
189 | qual = notice_section(ctx, unot, ia5org); | ||
190 | X509V3_section_free(ctx, unot); | ||
191 | if(!qual) goto err; | ||
192 | if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) | ||
193 | goto merr; | ||
194 | } else { | ||
195 | X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION); | ||
196 | |||
197 | X509V3_conf_err(cnf); | ||
198 | goto err; | ||
199 | } | ||
200 | } | ||
201 | if(!pol->policyid) { | ||
202 | X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER); | ||
203 | goto err; | ||
204 | } | ||
205 | |||
206 | return pol; | ||
207 | |||
208 | merr: | ||
209 | X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE); | ||
210 | |||
211 | err: | ||
212 | POLICYINFO_free(pol); | ||
213 | return NULL; | ||
214 | |||
215 | |||
216 | } | ||
217 | |||
218 | static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, | ||
219 | STACK_OF(CONF_VALUE) *unot, int ia5org) | ||
220 | { | ||
221 | int i; | ||
222 | CONF_VALUE *cnf; | ||
223 | USERNOTICE *not; | ||
224 | POLICYQUALINFO *qual; | ||
225 | if(!(qual = POLICYQUALINFO_new())) goto merr; | ||
226 | qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice); | ||
227 | if(!(not = USERNOTICE_new())) goto merr; | ||
228 | qual->d.usernotice = not; | ||
229 | for(i = 0; i < sk_CONF_VALUE_num(unot); i++) { | ||
230 | cnf = sk_CONF_VALUE_value(unot, i); | ||
231 | if(!strcmp(cnf->name, "explicitText")) { | ||
232 | not->exptext = ASN1_VISIBLESTRING_new(); | ||
233 | if(!ASN1_STRING_set(not->exptext, cnf->value, | ||
234 | strlen(cnf->value))) goto merr; | ||
235 | } else if(!strcmp(cnf->name, "organization")) { | ||
236 | NOTICEREF *nref; | ||
237 | if(!not->noticeref) { | ||
238 | if(!(nref = NOTICEREF_new())) goto merr; | ||
239 | not->noticeref = nref; | ||
240 | } else nref = not->noticeref; | ||
241 | if(ia5org) nref->organization = ASN1_IA5STRING_new(); | ||
242 | else nref->organization = ASN1_VISIBLESTRING_new(); | ||
243 | if(!ASN1_STRING_set(nref->organization, cnf->value, | ||
244 | strlen(cnf->value))) goto merr; | ||
245 | } else if(!strcmp(cnf->name, "noticeNumbers")) { | ||
246 | NOTICEREF *nref; | ||
247 | STACK_OF(CONF_VALUE) *nos; | ||
248 | if(!not->noticeref) { | ||
249 | if(!(nref = NOTICEREF_new())) goto merr; | ||
250 | not->noticeref = nref; | ||
251 | } else nref = not->noticeref; | ||
252 | nos = X509V3_parse_list(cnf->value); | ||
253 | if(!nos || !sk_CONF_VALUE_num(nos)) { | ||
254 | X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS); | ||
255 | X509V3_conf_err(cnf); | ||
256 | goto err; | ||
257 | } | ||
258 | nref->noticenos = nref_nos(nos); | ||
259 | sk_CONF_VALUE_pop_free(nos, X509V3_conf_free); | ||
260 | if(!nref->noticenos) goto err; | ||
261 | } else { | ||
262 | X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION); | ||
263 | |||
264 | X509V3_conf_err(cnf); | ||
265 | goto err; | ||
266 | } | ||
267 | } | ||
268 | |||
269 | if(not->noticeref && | ||
270 | (!not->noticeref->noticenos || !not->noticeref->organization)) { | ||
271 | X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS); | ||
272 | goto err; | ||
273 | } | ||
274 | |||
275 | return qual; | ||
276 | |||
277 | merr: | ||
278 | X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE); | ||
279 | |||
280 | err: | ||
281 | POLICYQUALINFO_free(qual); | ||
282 | return NULL; | ||
283 | } | ||
284 | |||
285 | static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos) | ||
286 | { | ||
287 | STACK *nnums; | ||
288 | CONF_VALUE *cnf; | ||
289 | ASN1_INTEGER *aint; | ||
290 | int i; | ||
291 | if(!(nnums = sk_new_null())) goto merr; | ||
292 | for(i = 0; i < sk_CONF_VALUE_num(nos); i++) { | ||
293 | cnf = sk_CONF_VALUE_value(nos, i); | ||
294 | if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) { | ||
295 | X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER); | ||
296 | goto err; | ||
297 | } | ||
298 | if(!sk_push(nnums, (char *)aint)) goto merr; | ||
299 | } | ||
300 | return nnums; | ||
301 | |||
302 | merr: | ||
303 | X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE); | ||
304 | |||
305 | err: | ||
306 | sk_pop_free(nnums, ASN1_STRING_free); | ||
307 | return NULL; | ||
308 | } | ||
309 | |||
310 | |||
311 | static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, | ||
312 | BIO *out, int indent) | ||
313 | { | ||
314 | int i; | ||
315 | POLICYINFO *pinfo; | ||
316 | /* First print out the policy OIDs */ | ||
317 | for(i = 0; i < sk_POLICYINFO_num(pol); i++) { | ||
318 | pinfo = sk_POLICYINFO_value(pol, i); | ||
319 | BIO_printf(out, "%*sPolicy: ", indent, ""); | ||
320 | i2a_ASN1_OBJECT(out, pinfo->policyid); | ||
321 | BIO_puts(out, "\n"); | ||
322 | if(pinfo->qualifiers) | ||
323 | print_qualifiers(out, pinfo->qualifiers, indent + 2); | ||
324 | } | ||
325 | return 1; | ||
326 | } | ||
327 | |||
328 | |||
329 | int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp) | ||
330 | { | ||
331 | |||
332 | return i2d_ASN1_SET_OF_POLICYINFO(a, pp, i2d_POLICYINFO, V_ASN1_SEQUENCE, | ||
333 | V_ASN1_UNIVERSAL, IS_SEQUENCE);} | ||
334 | |||
335 | STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void) | ||
336 | { | ||
337 | return sk_POLICYINFO_new_null(); | ||
338 | } | ||
339 | |||
340 | void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a) | ||
341 | { | ||
342 | sk_POLICYINFO_pop_free(a, POLICYINFO_free); | ||
343 | } | ||
344 | |||
345 | STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a, | ||
346 | unsigned char **pp,long length) | ||
347 | { | ||
348 | return d2i_ASN1_SET_OF_POLICYINFO(a, pp, length, d2i_POLICYINFO, | ||
349 | POLICYINFO_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | ||
350 | |||
351 | } | ||
352 | |||
353 | IMPLEMENT_STACK_OF(POLICYINFO) | ||
354 | IMPLEMENT_ASN1_SET_OF(POLICYINFO) | ||
355 | |||
356 | int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp) | ||
357 | { | ||
358 | M_ASN1_I2D_vars(a); | ||
359 | |||
360 | M_ASN1_I2D_len (a->policyid, i2d_ASN1_OBJECT); | ||
361 | M_ASN1_I2D_len_SEQUENCE_type(POLICYQUALINFO, a->qualifiers, | ||
362 | i2d_POLICYQUALINFO); | ||
363 | |||
364 | M_ASN1_I2D_seq_total(); | ||
365 | |||
366 | M_ASN1_I2D_put (a->policyid, i2d_ASN1_OBJECT); | ||
367 | M_ASN1_I2D_put_SEQUENCE_type(POLICYQUALINFO, a->qualifiers, | ||
368 | i2d_POLICYQUALINFO); | ||
369 | |||
370 | M_ASN1_I2D_finish(); | ||
371 | } | ||
372 | |||
373 | POLICYINFO *POLICYINFO_new(void) | ||
374 | { | ||
375 | POLICYINFO *ret=NULL; | ||
376 | ASN1_CTX c; | ||
377 | M_ASN1_New_Malloc(ret, POLICYINFO); | ||
378 | ret->policyid = NULL; | ||
379 | ret->qualifiers = NULL; | ||
380 | return (ret); | ||
381 | M_ASN1_New_Error(ASN1_F_POLICYINFO_NEW); | ||
382 | } | ||
383 | |||
384 | POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp,long length) | ||
385 | { | ||
386 | M_ASN1_D2I_vars(a,POLICYINFO *,POLICYINFO_new); | ||
387 | M_ASN1_D2I_Init(); | ||
388 | M_ASN1_D2I_start_sequence(); | ||
389 | M_ASN1_D2I_get(ret->policyid, d2i_ASN1_OBJECT); | ||
390 | if(!M_ASN1_D2I_end_sequence()) { | ||
391 | M_ASN1_D2I_get_seq_type (POLICYQUALINFO, ret->qualifiers, | ||
392 | d2i_POLICYQUALINFO, POLICYQUALINFO_free); | ||
393 | } | ||
394 | M_ASN1_D2I_Finish(a, POLICYINFO_free, ASN1_F_D2I_POLICYINFO); | ||
395 | } | ||
396 | |||
397 | void POLICYINFO_free(POLICYINFO *a) | ||
398 | { | ||
399 | if (a == NULL) return; | ||
400 | ASN1_OBJECT_free(a->policyid); | ||
401 | sk_POLICYQUALINFO_pop_free(a->qualifiers, POLICYQUALINFO_free); | ||
402 | Free (a); | ||
403 | } | ||
404 | |||
405 | static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, | ||
406 | int indent) | ||
407 | { | ||
408 | POLICYQUALINFO *qualinfo; | ||
409 | int i; | ||
410 | for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) { | ||
411 | qualinfo = sk_POLICYQUALINFO_value(quals, i); | ||
412 | switch(OBJ_obj2nid(qualinfo->pqualid)) | ||
413 | { | ||
414 | case NID_id_qt_cps: | ||
415 | BIO_printf(out, "%*sCPS: %s\n", indent, "", | ||
416 | qualinfo->d.cpsuri->data); | ||
417 | break; | ||
418 | |||
419 | case NID_id_qt_unotice: | ||
420 | BIO_printf(out, "%*sUser Notice:\n", indent, ""); | ||
421 | print_notice(out, qualinfo->d.usernotice, indent + 2); | ||
422 | break; | ||
423 | |||
424 | default: | ||
425 | BIO_printf(out, "%*sUnknown Qualifier: ", | ||
426 | indent + 2, ""); | ||
427 | |||
428 | i2a_ASN1_OBJECT(out, qualinfo->pqualid); | ||
429 | BIO_puts(out, "\n"); | ||
430 | break; | ||
431 | } | ||
432 | } | ||
433 | } | ||
434 | |||
435 | static void print_notice(BIO *out, USERNOTICE *notice, int indent) | ||
436 | { | ||
437 | int i; | ||
438 | if(notice->noticeref) { | ||
439 | NOTICEREF *ref; | ||
440 | ref = notice->noticeref; | ||
441 | BIO_printf(out, "%*sOrganization: %s\n", indent, "", | ||
442 | ref->organization->data); | ||
443 | BIO_printf(out, "%*sNumber%s: ", indent, "", | ||
444 | (sk_num(ref->noticenos) > 1) ? "s" : ""); | ||
445 | for(i = 0; i < sk_num(ref->noticenos); i++) { | ||
446 | ASN1_INTEGER *num; | ||
447 | char *tmp; | ||
448 | num = (ASN1_INTEGER *)sk_value(ref->noticenos, i); | ||
449 | if(i) BIO_puts(out, ", "); | ||
450 | tmp = i2s_ASN1_INTEGER(NULL, num); | ||
451 | BIO_puts(out, tmp); | ||
452 | Free(tmp); | ||
453 | } | ||
454 | BIO_puts(out, "\n"); | ||
455 | } | ||
456 | if(notice->exptext) | ||
457 | BIO_printf(out, "%*sExplicit Text: %s\n", indent, "", | ||
458 | notice->exptext->data); | ||
459 | } | ||
460 | |||
461 | |||
462 | |||
463 | int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp) | ||
464 | { | ||
465 | M_ASN1_I2D_vars(a); | ||
466 | |||
467 | M_ASN1_I2D_len (a->pqualid, i2d_ASN1_OBJECT); | ||
468 | switch(OBJ_obj2nid(a->pqualid)) { | ||
469 | case NID_id_qt_cps: | ||
470 | M_ASN1_I2D_len(a->d.cpsuri, i2d_ASN1_IA5STRING); | ||
471 | break; | ||
472 | |||
473 | case NID_id_qt_unotice: | ||
474 | M_ASN1_I2D_len(a->d.usernotice, i2d_USERNOTICE); | ||
475 | break; | ||
476 | |||
477 | default: | ||
478 | M_ASN1_I2D_len(a->d.other, i2d_ASN1_TYPE); | ||
479 | break; | ||
480 | } | ||
481 | |||
482 | M_ASN1_I2D_seq_total(); | ||
483 | |||
484 | M_ASN1_I2D_put (a->pqualid, i2d_ASN1_OBJECT); | ||
485 | switch(OBJ_obj2nid(a->pqualid)) { | ||
486 | case NID_id_qt_cps: | ||
487 | M_ASN1_I2D_put(a->d.cpsuri, i2d_ASN1_IA5STRING); | ||
488 | break; | ||
489 | |||
490 | case NID_id_qt_unotice: | ||
491 | M_ASN1_I2D_put(a->d.usernotice, i2d_USERNOTICE); | ||
492 | break; | ||
493 | |||
494 | default: | ||
495 | M_ASN1_I2D_put(a->d.other, i2d_ASN1_TYPE); | ||
496 | break; | ||
497 | } | ||
498 | |||
499 | M_ASN1_I2D_finish(); | ||
500 | } | ||
501 | |||
502 | POLICYQUALINFO *POLICYQUALINFO_new(void) | ||
503 | { | ||
504 | POLICYQUALINFO *ret=NULL; | ||
505 | ASN1_CTX c; | ||
506 | M_ASN1_New_Malloc(ret, POLICYQUALINFO); | ||
507 | ret->pqualid = NULL; | ||
508 | ret->d.other = NULL; | ||
509 | return (ret); | ||
510 | M_ASN1_New_Error(ASN1_F_POLICYQUALINFO_NEW); | ||
511 | } | ||
512 | |||
513 | POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp, | ||
514 | long length) | ||
515 | { | ||
516 | M_ASN1_D2I_vars(a,POLICYQUALINFO *,POLICYQUALINFO_new); | ||
517 | M_ASN1_D2I_Init(); | ||
518 | M_ASN1_D2I_start_sequence(); | ||
519 | M_ASN1_D2I_get (ret->pqualid, d2i_ASN1_OBJECT); | ||
520 | switch(OBJ_obj2nid(ret->pqualid)) { | ||
521 | case NID_id_qt_cps: | ||
522 | M_ASN1_D2I_get(ret->d.cpsuri, d2i_ASN1_IA5STRING); | ||
523 | break; | ||
524 | |||
525 | case NID_id_qt_unotice: | ||
526 | M_ASN1_D2I_get(ret->d.usernotice, d2i_USERNOTICE); | ||
527 | break; | ||
528 | |||
529 | default: | ||
530 | M_ASN1_D2I_get(ret->d.other, d2i_ASN1_TYPE); | ||
531 | break; | ||
532 | } | ||
533 | M_ASN1_D2I_Finish(a, POLICYQUALINFO_free, ASN1_F_D2I_POLICYQUALINFO); | ||
534 | } | ||
535 | |||
536 | void POLICYQUALINFO_free(POLICYQUALINFO *a) | ||
537 | { | ||
538 | if (a == NULL) return; | ||
539 | switch(OBJ_obj2nid(a->pqualid)) { | ||
540 | case NID_id_qt_cps: | ||
541 | ASN1_IA5STRING_free(a->d.cpsuri); | ||
542 | break; | ||
543 | |||
544 | case NID_id_qt_unotice: | ||
545 | USERNOTICE_free(a->d.usernotice); | ||
546 | break; | ||
547 | |||
548 | default: | ||
549 | ASN1_TYPE_free(a->d.other); | ||
550 | break; | ||
551 | } | ||
552 | |||
553 | ASN1_OBJECT_free(a->pqualid); | ||
554 | Free (a); | ||
555 | } | ||
556 | |||
557 | int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp) | ||
558 | { | ||
559 | M_ASN1_I2D_vars(a); | ||
560 | |||
561 | M_ASN1_I2D_len (a->noticeref, i2d_NOTICEREF); | ||
562 | M_ASN1_I2D_len (a->exptext, i2d_DISPLAYTEXT); | ||
563 | |||
564 | M_ASN1_I2D_seq_total(); | ||
565 | |||
566 | M_ASN1_I2D_put (a->noticeref, i2d_NOTICEREF); | ||
567 | M_ASN1_I2D_put (a->exptext, i2d_DISPLAYTEXT); | ||
568 | |||
569 | M_ASN1_I2D_finish(); | ||
570 | } | ||
571 | |||
572 | USERNOTICE *USERNOTICE_new(void) | ||
573 | { | ||
574 | USERNOTICE *ret=NULL; | ||
575 | ASN1_CTX c; | ||
576 | M_ASN1_New_Malloc(ret, USERNOTICE); | ||
577 | ret->noticeref = NULL; | ||
578 | ret->exptext = NULL; | ||
579 | return (ret); | ||
580 | M_ASN1_New_Error(ASN1_F_USERNOTICE_NEW); | ||
581 | } | ||
582 | |||
583 | USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp,long length) | ||
584 | { | ||
585 | M_ASN1_D2I_vars(a,USERNOTICE *,USERNOTICE_new); | ||
586 | M_ASN1_D2I_Init(); | ||
587 | M_ASN1_D2I_start_sequence(); | ||
588 | M_ASN1_D2I_get_opt(ret->noticeref, d2i_NOTICEREF, V_ASN1_SEQUENCE); | ||
589 | if (!M_ASN1_D2I_end_sequence()) { | ||
590 | M_ASN1_D2I_get(ret->exptext, d2i_DISPLAYTEXT); | ||
591 | } | ||
592 | M_ASN1_D2I_Finish(a, USERNOTICE_free, ASN1_F_D2I_USERNOTICE); | ||
593 | } | ||
594 | |||
595 | void USERNOTICE_free(USERNOTICE *a) | ||
596 | { | ||
597 | if (a == NULL) return; | ||
598 | NOTICEREF_free(a->noticeref); | ||
599 | DISPLAYTEXT_free(a->exptext); | ||
600 | Free (a); | ||
601 | } | ||
602 | |||
603 | int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp) | ||
604 | { | ||
605 | M_ASN1_I2D_vars(a); | ||
606 | |||
607 | M_ASN1_I2D_len (a->organization, i2d_DISPLAYTEXT); | ||
608 | M_ASN1_I2D_len_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER); | ||
609 | |||
610 | M_ASN1_I2D_seq_total(); | ||
611 | |||
612 | M_ASN1_I2D_put (a->organization, i2d_DISPLAYTEXT); | ||
613 | M_ASN1_I2D_put_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER); | ||
614 | |||
615 | M_ASN1_I2D_finish(); | ||
616 | } | ||
617 | |||
618 | NOTICEREF *NOTICEREF_new(void) | ||
619 | { | ||
620 | NOTICEREF *ret=NULL; | ||
621 | ASN1_CTX c; | ||
622 | M_ASN1_New_Malloc(ret, NOTICEREF); | ||
623 | ret->organization = NULL; | ||
624 | ret->noticenos = NULL; | ||
625 | return (ret); | ||
626 | M_ASN1_New_Error(ASN1_F_NOTICEREF_NEW); | ||
627 | } | ||
628 | |||
629 | NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length) | ||
630 | { | ||
631 | M_ASN1_D2I_vars(a,NOTICEREF *,NOTICEREF_new); | ||
632 | M_ASN1_D2I_Init(); | ||
633 | M_ASN1_D2I_start_sequence(); | ||
634 | /* This is to cope with some broken encodings that use IA5STRING for | ||
635 | * the organization field | ||
636 | */ | ||
637 | M_ASN1_D2I_get_opt(ret->organization, d2i_ASN1_IA5STRING, | ||
638 | V_ASN1_IA5STRING); | ||
639 | if(!ret->organization) { | ||
640 | M_ASN1_D2I_get(ret->organization, d2i_DISPLAYTEXT); | ||
641 | } | ||
642 | M_ASN1_D2I_get_seq(ret->noticenos, d2i_ASN1_INTEGER, ASN1_STRING_free); | ||
643 | M_ASN1_D2I_Finish(a, NOTICEREF_free, ASN1_F_D2I_NOTICEREF); | ||
644 | } | ||
645 | |||
646 | void NOTICEREF_free(NOTICEREF *a) | ||
647 | { | ||
648 | if (a == NULL) return; | ||
649 | DISPLAYTEXT_free(a->organization); | ||
650 | sk_pop_free(a->noticenos, ASN1_STRING_free); | ||
651 | Free (a); | ||
652 | } | ||
653 | |||
654 | IMPLEMENT_STACK_OF(POLICYQUALINFO) | ||
655 | IMPLEMENT_ASN1_SET_OF(POLICYQUALINFO) | ||