]>
Commit | Line | Data |
---|---|---|
41b731f2 DSH |
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" | |
ec577822 BM |
61 | #include <openssl/conf.h> |
62 | #include <openssl/asn1.h> | |
63 | #include <openssl/asn1_mac.h> | |
64 | #include <openssl/x509v3.h> | |
41b731f2 DSH |
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); | |
ba404b5e DSH |
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); | |
abc9400e | 76 | static STACK_OF(ASN1_INTEGER) *nref_nos(STACK_OF(CONF_VALUE) *nos); |
41b731f2 DSH |
77 | |
78 | X509V3_EXT_METHOD v3_cpols = { | |
79 | NID_certificate_policies, 0, | |
80 | (X509V3_EXT_NEW)CERTIFICATEPOLICIES_new, | |
66ab08b1 | 81 | (X509V3_EXT_FREE)CERTIFICATEPOLICIES_free, |
41b731f2 | 82 | (X509V3_EXT_D2I)d2i_CERTIFICATEPOLICIES, |
66ab08b1 | 83 | (X509V3_EXT_I2D)i2d_CERTIFICATEPOLICIES, |
41b731f2 DSH |
84 | NULL, NULL, |
85 | NULL, NULL, | |
86 | (X509V3_EXT_I2R)i2r_certpol, | |
87 | (X509V3_EXT_R2I)r2i_certpol, | |
88 | NULL | |
89 | }; | |
90 | ||
91 | ||
6b691a5c UM |
92 | static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, |
93 | X509V3_CTX *ctx, char *value) | |
41b731f2 DSH |
94 | { |
95 | STACK_OF(POLICYINFO) *pols = NULL; | |
96 | char *pstr; | |
97 | POLICYINFO *pol; | |
98 | ASN1_OBJECT *pobj; | |
ba404b5e | 99 | STACK_OF(CONF_VALUE) *vals; |
41b731f2 | 100 | CONF_VALUE *cnf; |
e40b7abe | 101 | int i, ia5org; |
41b731f2 DSH |
102 | pols = sk_POLICYINFO_new_null(); |
103 | vals = X509V3_parse_list(value); | |
e40b7abe | 104 | ia5org = 0; |
ba404b5e DSH |
105 | for(i = 0; i < sk_CONF_VALUE_num(vals); i++) { |
106 | cnf = sk_CONF_VALUE_value(vals, i); | |
41b731f2 DSH |
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; | |
e40b7abe DSH |
113 | if(!strcmp(pstr,"ia5org")) { |
114 | ia5org = 1; | |
115 | continue; | |
116 | } else if(*pstr == '@') { | |
ba404b5e | 117 | STACK_OF(CONF_VALUE) *polsect; |
41b731f2 DSH |
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 | } | |
e40b7abe | 125 | pol = policy_section(ctx, polsect, ia5org); |
41b731f2 DSH |
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 | } | |
ba404b5e | 139 | sk_CONF_VALUE_pop_free(vals, X509V3_conf_free); |
41b731f2 DSH |
140 | return pols; |
141 | err: | |
142 | sk_POLICYINFO_pop_free(pols, POLICYINFO_free); | |
143 | return NULL; | |
144 | } | |
145 | ||
ba404b5e DSH |
146 | static POLICYINFO *policy_section(X509V3_CTX *ctx, |
147 | STACK_OF(CONF_VALUE) *polstrs, int ia5org) | |
41b731f2 DSH |
148 | { |
149 | int i; | |
150 | CONF_VALUE *cnf; | |
3edd7ed1 DSH |
151 | POLICYINFO *pol; |
152 | POLICYQUALINFO *qual; | |
153 | if(!(pol = POLICYINFO_new())) goto merr; | |
ba404b5e DSH |
154 | for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) { |
155 | cnf = sk_CONF_VALUE_value(polstrs, i); | |
3edd7ed1 DSH |
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); | |
08e9c1af | 172 | qual->d.cpsuri = M_ASN1_IA5STRING_new(); |
3edd7ed1 DSH |
173 | if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value, |
174 | strlen(cnf->value))) goto merr; | |
175 | } else if(!name_cmp(cnf->name, "userNotice")) { | |
ba404b5e | 176 | STACK_OF(CONF_VALUE) *unot; |
3edd7ed1 DSH |
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 | } | |
e40b7abe | 189 | qual = notice_section(ctx, unot, ia5org); |
3edd7ed1 DSH |
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 | ||
3edd7ed1 DSH |
208 | merr: |
209 | X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE); | |
d943e372 DSH |
210 | |
211 | err: | |
3edd7ed1 DSH |
212 | POLICYINFO_free(pol); |
213 | return NULL; | |
214 | ||
d943e372 | 215 | |
3edd7ed1 DSH |
216 | } |
217 | ||
ba404b5e DSH |
218 | static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, |
219 | STACK_OF(CONF_VALUE) *unot, int ia5org) | |
3edd7ed1 DSH |
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; | |
ba404b5e DSH |
229 | for(i = 0; i < sk_CONF_VALUE_num(unot); i++) { |
230 | cnf = sk_CONF_VALUE_value(unot, i); | |
3edd7ed1 | 231 | if(!strcmp(cnf->name, "explicitText")) { |
08e9c1af | 232 | not->exptext = M_ASN1_VISIBLESTRING_new(); |
3edd7ed1 DSH |
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; | |
08e9c1af DSH |
241 | if(ia5org) nref->organization = M_ASN1_IA5STRING_new(); |
242 | else nref->organization = M_ASN1_VISIBLESTRING_new(); | |
3edd7ed1 DSH |
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; | |
ba404b5e | 247 | STACK_OF(CONF_VALUE) *nos; |
3edd7ed1 DSH |
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); | |
ba404b5e | 253 | if(!nos || !sk_CONF_VALUE_num(nos)) { |
3edd7ed1 DSH |
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); | |
ba404b5e | 259 | sk_CONF_VALUE_pop_free(nos, X509V3_conf_free); |
3edd7ed1 DSH |
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; | |
41b731f2 | 273 | } |
3edd7ed1 DSH |
274 | |
275 | return qual; | |
276 | ||
3edd7ed1 DSH |
277 | merr: |
278 | X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE); | |
d943e372 DSH |
279 | |
280 | err: | |
3edd7ed1 DSH |
281 | POLICYQUALINFO_free(qual); |
282 | return NULL; | |
283 | } | |
284 | ||
abc9400e | 285 | static STACK_OF(ASN1_INTEGER) *nref_nos(STACK_OF(CONF_VALUE) *nos) |
3edd7ed1 | 286 | { |
abc9400e | 287 | STACK_OF(ASN1_INTEGER) *nnums; |
3edd7ed1 DSH |
288 | CONF_VALUE *cnf; |
289 | ASN1_INTEGER *aint; | |
abc9400e | 290 | |
3edd7ed1 | 291 | int i; |
abc9400e BL |
292 | |
293 | if(!(nnums = sk_ASN1_INTEGER_new_null())) goto merr; | |
ba404b5e DSH |
294 | for(i = 0; i < sk_CONF_VALUE_num(nos); i++) { |
295 | cnf = sk_CONF_VALUE_value(nos, i); | |
3edd7ed1 DSH |
296 | if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) { |
297 | X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER); | |
298 | goto err; | |
299 | } | |
abc9400e | 300 | if(!sk_ASN1_INTEGER_push(nnums, aint)) goto merr; |
3edd7ed1 DSH |
301 | } |
302 | return nnums; | |
303 | ||
3edd7ed1 DSH |
304 | merr: |
305 | X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE); | |
d943e372 DSH |
306 | |
307 | err: | |
abc9400e | 308 | sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free); |
41b731f2 DSH |
309 | return NULL; |
310 | } | |
311 | ||
312 | ||
6b691a5c UM |
313 | static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, |
314 | BIO *out, int indent) | |
41b731f2 DSH |
315 | { |
316 | int i; | |
317 | POLICYINFO *pinfo; | |
318 | /* First print out the policy OIDs */ | |
319 | for(i = 0; i < sk_POLICYINFO_num(pol); i++) { | |
320 | pinfo = sk_POLICYINFO_value(pol, i); | |
321 | BIO_printf(out, "%*sPolicy: ", indent, ""); | |
322 | i2a_ASN1_OBJECT(out, pinfo->policyid); | |
323 | BIO_puts(out, "\n"); | |
324 | if(pinfo->qualifiers) | |
325 | print_qualifiers(out, pinfo->qualifiers, indent + 2); | |
326 | } | |
327 | return 1; | |
328 | } | |
329 | ||
330 | ||
6b691a5c | 331 | int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp) |
41b731f2 DSH |
332 | { |
333 | ||
334 | return i2d_ASN1_SET_OF_POLICYINFO(a, pp, i2d_POLICYINFO, V_ASN1_SEQUENCE, | |
335 | V_ASN1_UNIVERSAL, IS_SEQUENCE);} | |
336 | ||
6b691a5c | 337 | STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void) |
41b731f2 DSH |
338 | { |
339 | return sk_POLICYINFO_new_null(); | |
340 | } | |
341 | ||
6b691a5c | 342 | void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a) |
41b731f2 DSH |
343 | { |
344 | sk_POLICYINFO_pop_free(a, POLICYINFO_free); | |
345 | } | |
346 | ||
6b691a5c UM |
347 | STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a, |
348 | unsigned char **pp,long length) | |
41b731f2 DSH |
349 | { |
350 | return d2i_ASN1_SET_OF_POLICYINFO(a, pp, length, d2i_POLICYINFO, | |
351 | POLICYINFO_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | |
352 | ||
353 | } | |
354 | ||
355 | IMPLEMENT_STACK_OF(POLICYINFO) | |
356 | IMPLEMENT_ASN1_SET_OF(POLICYINFO) | |
357 | ||
6b691a5c | 358 | int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp) |
41b731f2 DSH |
359 | { |
360 | M_ASN1_I2D_vars(a); | |
361 | ||
362 | M_ASN1_I2D_len (a->policyid, i2d_ASN1_OBJECT); | |
363 | M_ASN1_I2D_len_SEQUENCE_type(POLICYQUALINFO, a->qualifiers, | |
364 | i2d_POLICYQUALINFO); | |
365 | ||
366 | M_ASN1_I2D_seq_total(); | |
367 | ||
368 | M_ASN1_I2D_put (a->policyid, i2d_ASN1_OBJECT); | |
369 | M_ASN1_I2D_put_SEQUENCE_type(POLICYQUALINFO, a->qualifiers, | |
370 | i2d_POLICYQUALINFO); | |
371 | ||
372 | M_ASN1_I2D_finish(); | |
373 | } | |
374 | ||
6b691a5c | 375 | POLICYINFO *POLICYINFO_new(void) |
41b731f2 DSH |
376 | { |
377 | POLICYINFO *ret=NULL; | |
378 | ASN1_CTX c; | |
379 | M_ASN1_New_Malloc(ret, POLICYINFO); | |
380 | ret->policyid = NULL; | |
381 | ret->qualifiers = NULL; | |
382 | return (ret); | |
383 | M_ASN1_New_Error(ASN1_F_POLICYINFO_NEW); | |
384 | } | |
385 | ||
6b691a5c | 386 | POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp,long length) |
41b731f2 DSH |
387 | { |
388 | M_ASN1_D2I_vars(a,POLICYINFO *,POLICYINFO_new); | |
389 | M_ASN1_D2I_Init(); | |
390 | M_ASN1_D2I_start_sequence(); | |
391 | M_ASN1_D2I_get(ret->policyid, d2i_ASN1_OBJECT); | |
392 | if(!M_ASN1_D2I_end_sequence()) { | |
393 | M_ASN1_D2I_get_seq_type (POLICYQUALINFO, ret->qualifiers, | |
394 | d2i_POLICYQUALINFO, POLICYQUALINFO_free); | |
395 | } | |
396 | M_ASN1_D2I_Finish(a, POLICYINFO_free, ASN1_F_D2I_POLICYINFO); | |
397 | } | |
398 | ||
6b691a5c | 399 | void POLICYINFO_free(POLICYINFO *a) |
41b731f2 DSH |
400 | { |
401 | if (a == NULL) return; | |
402 | ASN1_OBJECT_free(a->policyid); | |
403 | sk_POLICYQUALINFO_pop_free(a->qualifiers, POLICYQUALINFO_free); | |
26a3a48d | 404 | OPENSSL_free (a); |
41b731f2 DSH |
405 | } |
406 | ||
6b691a5c UM |
407 | static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, |
408 | int indent) | |
41b731f2 DSH |
409 | { |
410 | POLICYQUALINFO *qualinfo; | |
411 | int i; | |
412 | for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) { | |
413 | qualinfo = sk_POLICYQUALINFO_value(quals, i); | |
414 | switch(OBJ_obj2nid(qualinfo->pqualid)) | |
415 | { | |
416 | case NID_id_qt_cps: | |
417 | BIO_printf(out, "%*sCPS: %s\n", indent, "", | |
418 | qualinfo->d.cpsuri->data); | |
419 | break; | |
420 | ||
421 | case NID_id_qt_unotice: | |
422 | BIO_printf(out, "%*sUser Notice:\n", indent, ""); | |
423 | print_notice(out, qualinfo->d.usernotice, indent + 2); | |
424 | break; | |
425 | ||
426 | default: | |
427 | BIO_printf(out, "%*sUnknown Qualifier: ", | |
428 | indent + 2, ""); | |
429 | ||
430 | i2a_ASN1_OBJECT(out, qualinfo->pqualid); | |
431 | BIO_puts(out, "\n"); | |
432 | break; | |
433 | } | |
434 | } | |
435 | } | |
436 | ||
6b691a5c | 437 | static void print_notice(BIO *out, USERNOTICE *notice, int indent) |
41b731f2 DSH |
438 | { |
439 | int i; | |
440 | if(notice->noticeref) { | |
441 | NOTICEREF *ref; | |
442 | ref = notice->noticeref; | |
443 | BIO_printf(out, "%*sOrganization: %s\n", indent, "", | |
444 | ref->organization->data); | |
445 | BIO_printf(out, "%*sNumber%s: ", indent, "", | |
abc9400e BL |
446 | sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : ""); |
447 | for(i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) { | |
41b731f2 DSH |
448 | ASN1_INTEGER *num; |
449 | char *tmp; | |
abc9400e | 450 | num = sk_ASN1_INTEGER_value(ref->noticenos, i); |
41b731f2 DSH |
451 | if(i) BIO_puts(out, ", "); |
452 | tmp = i2s_ASN1_INTEGER(NULL, num); | |
453 | BIO_puts(out, tmp); | |
26a3a48d | 454 | OPENSSL_free(tmp); |
41b731f2 DSH |
455 | } |
456 | BIO_puts(out, "\n"); | |
457 | } | |
458 | if(notice->exptext) | |
3edd7ed1 | 459 | BIO_printf(out, "%*sExplicit Text: %s\n", indent, "", |
41b731f2 DSH |
460 | notice->exptext->data); |
461 | } | |
462 | ||
463 | ||
464 | ||
6b691a5c | 465 | int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp) |
41b731f2 DSH |
466 | { |
467 | M_ASN1_I2D_vars(a); | |
468 | ||
469 | M_ASN1_I2D_len (a->pqualid, i2d_ASN1_OBJECT); | |
470 | switch(OBJ_obj2nid(a->pqualid)) { | |
471 | case NID_id_qt_cps: | |
472 | M_ASN1_I2D_len(a->d.cpsuri, i2d_ASN1_IA5STRING); | |
473 | break; | |
474 | ||
475 | case NID_id_qt_unotice: | |
476 | M_ASN1_I2D_len(a->d.usernotice, i2d_USERNOTICE); | |
477 | break; | |
478 | ||
479 | default: | |
480 | M_ASN1_I2D_len(a->d.other, i2d_ASN1_TYPE); | |
481 | break; | |
482 | } | |
483 | ||
484 | M_ASN1_I2D_seq_total(); | |
485 | ||
486 | M_ASN1_I2D_put (a->pqualid, i2d_ASN1_OBJECT); | |
487 | switch(OBJ_obj2nid(a->pqualid)) { | |
488 | case NID_id_qt_cps: | |
489 | M_ASN1_I2D_put(a->d.cpsuri, i2d_ASN1_IA5STRING); | |
490 | break; | |
491 | ||
492 | case NID_id_qt_unotice: | |
493 | M_ASN1_I2D_put(a->d.usernotice, i2d_USERNOTICE); | |
494 | break; | |
495 | ||
496 | default: | |
497 | M_ASN1_I2D_put(a->d.other, i2d_ASN1_TYPE); | |
498 | break; | |
499 | } | |
500 | ||
501 | M_ASN1_I2D_finish(); | |
502 | } | |
503 | ||
6b691a5c | 504 | POLICYQUALINFO *POLICYQUALINFO_new(void) |
41b731f2 DSH |
505 | { |
506 | POLICYQUALINFO *ret=NULL; | |
507 | ASN1_CTX c; | |
508 | M_ASN1_New_Malloc(ret, POLICYQUALINFO); | |
509 | ret->pqualid = NULL; | |
510 | ret->d.other = NULL; | |
511 | return (ret); | |
512 | M_ASN1_New_Error(ASN1_F_POLICYQUALINFO_NEW); | |
513 | } | |
514 | ||
6b691a5c UM |
515 | POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp, |
516 | long length) | |
41b731f2 DSH |
517 | { |
518 | M_ASN1_D2I_vars(a,POLICYQUALINFO *,POLICYQUALINFO_new); | |
519 | M_ASN1_D2I_Init(); | |
520 | M_ASN1_D2I_start_sequence(); | |
521 | M_ASN1_D2I_get (ret->pqualid, d2i_ASN1_OBJECT); | |
522 | switch(OBJ_obj2nid(ret->pqualid)) { | |
523 | case NID_id_qt_cps: | |
524 | M_ASN1_D2I_get(ret->d.cpsuri, d2i_ASN1_IA5STRING); | |
525 | break; | |
526 | ||
527 | case NID_id_qt_unotice: | |
528 | M_ASN1_D2I_get(ret->d.usernotice, d2i_USERNOTICE); | |
529 | break; | |
530 | ||
531 | default: | |
532 | M_ASN1_D2I_get(ret->d.other, d2i_ASN1_TYPE); | |
533 | break; | |
534 | } | |
535 | M_ASN1_D2I_Finish(a, POLICYQUALINFO_free, ASN1_F_D2I_POLICYQUALINFO); | |
536 | } | |
537 | ||
6b691a5c | 538 | void POLICYQUALINFO_free(POLICYQUALINFO *a) |
41b731f2 DSH |
539 | { |
540 | if (a == NULL) return; | |
541 | switch(OBJ_obj2nid(a->pqualid)) { | |
542 | case NID_id_qt_cps: | |
08e9c1af | 543 | M_ASN1_IA5STRING_free(a->d.cpsuri); |
41b731f2 DSH |
544 | break; |
545 | ||
546 | case NID_id_qt_unotice: | |
547 | USERNOTICE_free(a->d.usernotice); | |
548 | break; | |
549 | ||
550 | default: | |
551 | ASN1_TYPE_free(a->d.other); | |
552 | break; | |
553 | } | |
554 | ||
555 | ASN1_OBJECT_free(a->pqualid); | |
26a3a48d | 556 | OPENSSL_free (a); |
41b731f2 DSH |
557 | } |
558 | ||
6b691a5c | 559 | int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp) |
41b731f2 DSH |
560 | { |
561 | M_ASN1_I2D_vars(a); | |
562 | ||
563 | M_ASN1_I2D_len (a->noticeref, i2d_NOTICEREF); | |
564 | M_ASN1_I2D_len (a->exptext, i2d_DISPLAYTEXT); | |
565 | ||
566 | M_ASN1_I2D_seq_total(); | |
567 | ||
568 | M_ASN1_I2D_put (a->noticeref, i2d_NOTICEREF); | |
569 | M_ASN1_I2D_put (a->exptext, i2d_DISPLAYTEXT); | |
570 | ||
571 | M_ASN1_I2D_finish(); | |
572 | } | |
573 | ||
6b691a5c | 574 | USERNOTICE *USERNOTICE_new(void) |
41b731f2 DSH |
575 | { |
576 | USERNOTICE *ret=NULL; | |
577 | ASN1_CTX c; | |
578 | M_ASN1_New_Malloc(ret, USERNOTICE); | |
579 | ret->noticeref = NULL; | |
580 | ret->exptext = NULL; | |
581 | return (ret); | |
582 | M_ASN1_New_Error(ASN1_F_USERNOTICE_NEW); | |
583 | } | |
584 | ||
6b691a5c | 585 | USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp,long length) |
41b731f2 DSH |
586 | { |
587 | M_ASN1_D2I_vars(a,USERNOTICE *,USERNOTICE_new); | |
588 | M_ASN1_D2I_Init(); | |
589 | M_ASN1_D2I_start_sequence(); | |
590 | M_ASN1_D2I_get_opt(ret->noticeref, d2i_NOTICEREF, V_ASN1_SEQUENCE); | |
591 | if (!M_ASN1_D2I_end_sequence()) { | |
592 | M_ASN1_D2I_get(ret->exptext, d2i_DISPLAYTEXT); | |
593 | } | |
594 | M_ASN1_D2I_Finish(a, USERNOTICE_free, ASN1_F_D2I_USERNOTICE); | |
595 | } | |
596 | ||
6b691a5c | 597 | void USERNOTICE_free(USERNOTICE *a) |
41b731f2 DSH |
598 | { |
599 | if (a == NULL) return; | |
600 | NOTICEREF_free(a->noticeref); | |
08e9c1af | 601 | M_DISPLAYTEXT_free(a->exptext); |
26a3a48d | 602 | OPENSSL_free (a); |
41b731f2 DSH |
603 | } |
604 | ||
6b691a5c | 605 | int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp) |
41b731f2 DSH |
606 | { |
607 | M_ASN1_I2D_vars(a); | |
608 | ||
609 | M_ASN1_I2D_len (a->organization, i2d_DISPLAYTEXT); | |
abc9400e BL |
610 | M_ASN1_I2D_len_SEQUENCE_type(ASN1_INTEGER, a->noticenos, |
611 | i2d_ASN1_INTEGER); | |
41b731f2 DSH |
612 | |
613 | M_ASN1_I2D_seq_total(); | |
614 | ||
615 | M_ASN1_I2D_put (a->organization, i2d_DISPLAYTEXT); | |
abc9400e BL |
616 | M_ASN1_I2D_put_SEQUENCE_type(ASN1_INTEGER, a->noticenos, |
617 | i2d_ASN1_INTEGER); | |
41b731f2 DSH |
618 | |
619 | M_ASN1_I2D_finish(); | |
620 | } | |
621 | ||
6b691a5c | 622 | NOTICEREF *NOTICEREF_new(void) |
41b731f2 DSH |
623 | { |
624 | NOTICEREF *ret=NULL; | |
625 | ASN1_CTX c; | |
626 | M_ASN1_New_Malloc(ret, NOTICEREF); | |
627 | ret->organization = NULL; | |
628 | ret->noticenos = NULL; | |
629 | return (ret); | |
630 | M_ASN1_New_Error(ASN1_F_NOTICEREF_NEW); | |
631 | } | |
632 | ||
6b691a5c | 633 | NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length) |
41b731f2 DSH |
634 | { |
635 | M_ASN1_D2I_vars(a,NOTICEREF *,NOTICEREF_new); | |
636 | M_ASN1_D2I_Init(); | |
637 | M_ASN1_D2I_start_sequence(); | |
638 | /* This is to cope with some broken encodings that use IA5STRING for | |
639 | * the organization field | |
640 | */ | |
641 | M_ASN1_D2I_get_opt(ret->organization, d2i_ASN1_IA5STRING, | |
642 | V_ASN1_IA5STRING); | |
643 | if(!ret->organization) { | |
644 | M_ASN1_D2I_get(ret->organization, d2i_DISPLAYTEXT); | |
645 | } | |
abc9400e BL |
646 | M_ASN1_D2I_get_seq_type(ASN1_INTEGER, ret->noticenos, d2i_ASN1_INTEGER, |
647 | ASN1_STRING_free); | |
41b731f2 DSH |
648 | M_ASN1_D2I_Finish(a, NOTICEREF_free, ASN1_F_D2I_NOTICEREF); |
649 | } | |
650 | ||
6b691a5c | 651 | void NOTICEREF_free(NOTICEREF *a) |
41b731f2 DSH |
652 | { |
653 | if (a == NULL) return; | |
08e9c1af | 654 | M_DISPLAYTEXT_free(a->organization); |
abc9400e | 655 | sk_ASN1_INTEGER_pop_free(a->noticenos, ASN1_STRING_free); |
26a3a48d | 656 | OPENSSL_free (a); |
41b731f2 DSH |
657 | } |
658 | ||
659 | IMPLEMENT_STACK_OF(POLICYQUALINFO) | |
660 | IMPLEMENT_ASN1_SET_OF(POLICYQUALINFO) |