/src/openssl/crypto/x509/v3_cpols.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 1999-2026 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include <stdio.h> |
11 | | #include "internal/cryptlib.h" |
12 | | #include <openssl/conf.h> |
13 | | #include <openssl/asn1.h> |
14 | | #include <openssl/asn1t.h> |
15 | | #include <openssl/x509v3.h> |
16 | | |
17 | | #include "x509_local.h" |
18 | | #include "pcy_local.h" |
19 | | #include "ext_dat.h" |
20 | | |
21 | | #include <crypto/asn1.h> |
22 | | |
23 | | /* Certificate policies extension support: this one is a bit complex... */ |
24 | | |
25 | | static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, |
26 | | BIO *out, int indent); |
27 | | static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, |
28 | | X509V3_CTX *ctx, const char *value); |
29 | | static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, |
30 | | int indent); |
31 | | static void print_notice(BIO *out, USERNOTICE *notice, int indent); |
32 | | static POLICYINFO *policy_section(X509V3_CTX *ctx, |
33 | | STACK_OF(CONF_VALUE) *polstrs, int ia5org); |
34 | | static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, |
35 | | STACK_OF(CONF_VALUE) *unot, int ia5org); |
36 | | static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos); |
37 | | static int displaytext_str2tag(const char *tagstr, unsigned int *tag_len); |
38 | | static int displaytext_get_tag_len(const char *tagstr); |
39 | | |
40 | | const X509V3_EXT_METHOD ossl_v3_cpols = { |
41 | | NID_certificate_policies, 0, ASN1_ITEM_ref(CERTIFICATEPOLICIES), |
42 | | 0, 0, 0, 0, |
43 | | 0, 0, |
44 | | 0, 0, |
45 | | (X509V3_EXT_I2R)i2r_certpol, |
46 | | (X509V3_EXT_R2I)r2i_certpol, |
47 | | NULL |
48 | | }; |
49 | | |
50 | | ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO) |
51 | 0 | ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES) |
52 | | |
53 | | IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES) |
54 | | |
55 | | ASN1_SEQUENCE(POLICYINFO) = { |
56 | | ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT), |
57 | | ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO) |
58 | 0 | } ASN1_SEQUENCE_END(POLICYINFO) |
59 | 0 |
|
60 | 0 | IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO) |
61 | 0 |
|
62 | 0 | ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY); |
63 | 0 |
|
64 | 0 | ASN1_ADB(POLICYQUALINFO) = { |
65 | 0 | ADB_ENTRY(NID_id_qt_cps, ASN1_SIMPLE(POLICYQUALINFO, d.cpsuri, ASN1_IA5STRING)), |
66 | 0 | ADB_ENTRY(NID_id_qt_unotice, ASN1_SIMPLE(POLICYQUALINFO, d.usernotice, USERNOTICE)) |
67 | 0 | } ASN1_ADB_END(POLICYQUALINFO, 0, pqualid, 0, &policydefault_tt, NULL); |
68 | | |
69 | | ASN1_SEQUENCE(POLICYQUALINFO) = { |
70 | | ASN1_SIMPLE(POLICYQUALINFO, pqualid, ASN1_OBJECT), |
71 | | ASN1_ADB_OBJECT(POLICYQUALINFO) |
72 | 0 | } ASN1_SEQUENCE_END(POLICYQUALINFO) |
73 | 0 |
|
74 | 0 | IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO) |
75 | 0 |
|
76 | 0 | ASN1_SEQUENCE(USERNOTICE) = { |
77 | 0 | ASN1_OPT(USERNOTICE, noticeref, NOTICEREF), |
78 | 0 | ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT) |
79 | 0 | } ASN1_SEQUENCE_END(USERNOTICE) |
80 | 0 |
|
81 | 0 | IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE) |
82 | 0 |
|
83 | 0 | ASN1_SEQUENCE(NOTICEREF) = { |
84 | 0 | ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT), |
85 | 0 | ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER) |
86 | 0 | } ASN1_SEQUENCE_END(NOTICEREF) |
87 | 0 |
|
88 | 0 | IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF) |
89 | 0 |
|
90 | 0 | static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, |
91 | 0 | X509V3_CTX *ctx, const char *value) |
92 | 0 | { |
93 | 0 | STACK_OF(POLICYINFO) *pols; |
94 | 0 | char *pstr; |
95 | 0 | POLICYINFO *pol; |
96 | 0 | ASN1_OBJECT *pobj; |
97 | 0 | STACK_OF(CONF_VALUE) *vals = X509V3_parse_list(value); |
98 | 0 | CONF_VALUE *cnf; |
99 | 0 | const int num = sk_CONF_VALUE_num(vals); |
100 | 0 | int i, ia5org; |
101 | |
|
102 | 0 | if (vals == NULL) { |
103 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_X509V3_LIB); |
104 | 0 | return NULL; |
105 | 0 | } |
106 | | |
107 | 0 | pols = sk_POLICYINFO_new_reserve(NULL, num); |
108 | 0 | if (pols == NULL) { |
109 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
110 | 0 | goto err; |
111 | 0 | } |
112 | | |
113 | 0 | ia5org = 0; |
114 | 0 | for (i = 0; i < num; i++) { |
115 | 0 | cnf = sk_CONF_VALUE_value(vals, i); |
116 | 0 | if (cnf->value != NULL || cnf->name == NULL) { |
117 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_POLICY_IDENTIFIER); |
118 | 0 | X509V3_conf_add_error_name_value(cnf); |
119 | 0 | goto err; |
120 | 0 | } |
121 | 0 | pstr = cnf->name; |
122 | 0 | if (strcmp(pstr, "ia5org") == 0) { |
123 | 0 | ia5org = 1; |
124 | 0 | continue; |
125 | 0 | } else if (*pstr == '@') { |
126 | 0 | STACK_OF(CONF_VALUE) *polsect; |
127 | |
|
128 | 0 | polsect = X509V3_get_section(ctx, pstr + 1); |
129 | 0 | if (polsect == NULL) { |
130 | 0 | ERR_raise_data(ERR_LIB_X509V3, X509V3_R_INVALID_SECTION, |
131 | 0 | "%s", cnf->name); |
132 | 0 | goto err; |
133 | 0 | } |
134 | 0 | pol = policy_section(ctx, polsect, ia5org); |
135 | 0 | X509V3_section_free(ctx, polsect); |
136 | 0 | if (pol == NULL) |
137 | 0 | goto err; |
138 | 0 | } else { |
139 | 0 | if ((pobj = OBJ_txt2obj(cnf->name, 0)) == NULL) { |
140 | 0 | ERR_raise_data(ERR_LIB_X509V3, |
141 | 0 | X509V3_R_INVALID_OBJECT_IDENTIFIER, |
142 | 0 | "%s", cnf->name); |
143 | 0 | goto err; |
144 | 0 | } |
145 | 0 | pol = POLICYINFO_new(); |
146 | 0 | if (pol == NULL) { |
147 | 0 | ASN1_OBJECT_free(pobj); |
148 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
149 | 0 | goto err; |
150 | 0 | } |
151 | 0 | pol->policyid = pobj; |
152 | 0 | } |
153 | 0 | if (!sk_POLICYINFO_push(pols, pol)) { |
154 | 0 | POLICYINFO_free(pol); |
155 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
156 | 0 | goto err; |
157 | 0 | } |
158 | 0 | } |
159 | 0 | sk_CONF_VALUE_pop_free(vals, X509V3_conf_free); |
160 | 0 | return pols; |
161 | 0 | err: |
162 | 0 | sk_CONF_VALUE_pop_free(vals, X509V3_conf_free); |
163 | 0 | sk_POLICYINFO_pop_free(pols, POLICYINFO_free); |
164 | 0 | return NULL; |
165 | 0 | } |
166 | | |
167 | | static POLICYINFO *policy_section(X509V3_CTX *ctx, |
168 | | STACK_OF(CONF_VALUE) *polstrs, int ia5org) |
169 | 0 | { |
170 | 0 | int i; |
171 | 0 | int policyid_seen = 0; |
172 | 0 | CONF_VALUE *cnf; |
173 | 0 | POLICYINFO *pol; |
174 | 0 | POLICYQUALINFO *qual; |
175 | |
|
176 | 0 | if ((pol = POLICYINFO_new()) == NULL) { |
177 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
178 | 0 | goto err; |
179 | 0 | } |
180 | 0 | for (i = 0; i < sk_CONF_VALUE_num(polstrs); i++) { |
181 | 0 | cnf = sk_CONF_VALUE_value(polstrs, i); |
182 | 0 | if (strcmp(cnf->name, "policyIdentifier") == 0) { |
183 | 0 | ASN1_OBJECT *pobj; |
184 | |
|
185 | 0 | if (policyid_seen) { |
186 | 0 | ERR_raise_data(ERR_LIB_X509V3, X509V3_R_DUPLICATE_FIELD, |
187 | 0 | "field=%s", cnf->name); |
188 | 0 | goto err; |
189 | 0 | } |
190 | 0 | if ((pobj = OBJ_txt2obj(cnf->value, 0)) == NULL) { |
191 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_OBJECT_IDENTIFIER); |
192 | 0 | X509V3_conf_err(cnf); |
193 | 0 | goto err; |
194 | 0 | } |
195 | 0 | pol->policyid = pobj; |
196 | 0 | policyid_seen = 1; |
197 | |
|
198 | 0 | } else if (!ossl_v3_name_cmp(cnf->name, "CPS")) { |
199 | 0 | if (pol->qualifiers == NULL) |
200 | 0 | pol->qualifiers = sk_POLICYQUALINFO_new_null(); |
201 | 0 | if ((qual = POLICYQUALINFO_new()) == NULL) { |
202 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
203 | 0 | goto err; |
204 | 0 | } |
205 | 0 | if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) { |
206 | 0 | POLICYQUALINFO_free(qual); |
207 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
208 | 0 | goto err; |
209 | 0 | } |
210 | 0 | if ((qual->pqualid = OBJ_nid2obj(NID_id_qt_cps)) == NULL) { |
211 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_INTERNAL_ERROR); |
212 | 0 | goto err; |
213 | 0 | } |
214 | 0 | if ((qual->d.cpsuri = ASN1_IA5STRING_new()) == NULL) { |
215 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
216 | 0 | goto err; |
217 | 0 | } |
218 | 0 | if (!ossl_asn1_string_set1_string(qual->d.cpsuri, cnf->value)) { |
219 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
220 | 0 | goto err; |
221 | 0 | } |
222 | 0 | } else if (!ossl_v3_name_cmp(cnf->name, "userNotice")) { |
223 | 0 | STACK_OF(CONF_VALUE) *unot; |
224 | 0 | if (*cnf->value != '@') { |
225 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_EXPECTED_A_SECTION_NAME); |
226 | 0 | X509V3_conf_err(cnf); |
227 | 0 | goto err; |
228 | 0 | } |
229 | 0 | unot = X509V3_get_section(ctx, cnf->value + 1); |
230 | 0 | if (!unot) { |
231 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_SECTION); |
232 | |
|
233 | 0 | X509V3_conf_err(cnf); |
234 | 0 | goto err; |
235 | 0 | } |
236 | 0 | qual = notice_section(ctx, unot, ia5org); |
237 | 0 | X509V3_section_free(ctx, unot); |
238 | 0 | if (!qual) |
239 | 0 | goto err; |
240 | 0 | if (pol->qualifiers == NULL) |
241 | 0 | pol->qualifiers = sk_POLICYQUALINFO_new_null(); |
242 | 0 | if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) { |
243 | 0 | POLICYQUALINFO_free(qual); |
244 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
245 | 0 | goto err; |
246 | 0 | } |
247 | 0 | } else { |
248 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_OPTION); |
249 | 0 | X509V3_conf_err(cnf); |
250 | 0 | goto err; |
251 | 0 | } |
252 | 0 | } |
253 | 0 | if (!policyid_seen) { |
254 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_NO_POLICY_IDENTIFIER); |
255 | 0 | goto err; |
256 | 0 | } |
257 | | |
258 | 0 | return pol; |
259 | | |
260 | 0 | err: |
261 | 0 | POLICYINFO_free(pol); |
262 | 0 | return NULL; |
263 | 0 | } |
264 | | |
265 | | static int displaytext_get_tag_len(const char *tagstr) |
266 | 0 | { |
267 | 0 | const char *colon = strchr(tagstr, ':'); |
268 | |
|
269 | 0 | return (colon == NULL) ? -1 : (int)(colon - tagstr); |
270 | 0 | } |
271 | | |
272 | | static int displaytext_str2tag(const char *tagstr, unsigned int *tag_len) |
273 | 0 | { |
274 | 0 | int len; |
275 | |
|
276 | 0 | *tag_len = 0; |
277 | 0 | len = displaytext_get_tag_len(tagstr); |
278 | |
|
279 | 0 | if (len == -1) |
280 | 0 | return V_ASN1_VISIBLESTRING; |
281 | 0 | *tag_len = len; |
282 | 0 | if (len == sizeof("UTF8") - 1 && HAS_PREFIX(tagstr, "UTF8")) |
283 | 0 | return V_ASN1_UTF8STRING; |
284 | 0 | if (len == sizeof("UTF8String") - 1 && HAS_PREFIX(tagstr, "UTF8String")) |
285 | 0 | return V_ASN1_UTF8STRING; |
286 | 0 | if (len == sizeof("BMP") - 1 && HAS_PREFIX(tagstr, "BMP")) |
287 | 0 | return V_ASN1_BMPSTRING; |
288 | 0 | if (len == sizeof("BMPSTRING") - 1 && HAS_PREFIX(tagstr, "BMPSTRING")) |
289 | 0 | return V_ASN1_BMPSTRING; |
290 | 0 | if (len == sizeof("VISIBLE") - 1 && HAS_PREFIX(tagstr, "VISIBLE")) |
291 | 0 | return V_ASN1_VISIBLESTRING; |
292 | 0 | if (len == sizeof("VISIBLESTRING") - 1 && HAS_PREFIX(tagstr, "VISIBLESTRING")) |
293 | 0 | return V_ASN1_VISIBLESTRING; |
294 | 0 | *tag_len = 0; |
295 | 0 | return V_ASN1_VISIBLESTRING; |
296 | 0 | } |
297 | | |
298 | | static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, |
299 | | STACK_OF(CONF_VALUE) *unot, int ia5org) |
300 | 0 | { |
301 | 0 | int i, ret, len, tag; |
302 | 0 | unsigned int tag_len; |
303 | 0 | CONF_VALUE *cnf; |
304 | 0 | USERNOTICE *not; |
305 | 0 | POLICYQUALINFO *qual; |
306 | 0 | char *value = NULL; |
307 | |
|
308 | 0 | if ((qual = POLICYQUALINFO_new()) == NULL) { |
309 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
310 | 0 | goto err; |
311 | 0 | } |
312 | 0 | if ((qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice)) == NULL) { |
313 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_INTERNAL_ERROR); |
314 | 0 | goto err; |
315 | 0 | } |
316 | 0 | if ((not = USERNOTICE_new()) == NULL) { |
317 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
318 | 0 | goto err; |
319 | 0 | } |
320 | 0 | qual->d.usernotice = not; |
321 | 0 | for (i = 0; i < sk_CONF_VALUE_num(unot); i++) { |
322 | 0 | cnf = sk_CONF_VALUE_value(unot, i); |
323 | |
|
324 | 0 | value = cnf->value; |
325 | 0 | if (strcmp(cnf->name, "explicitText") == 0) { |
326 | 0 | if (not->exptext != NULL) { |
327 | 0 | ERR_raise_data(ERR_LIB_X509V3, X509V3_R_DUPLICATE_FIELD, |
328 | 0 | "field=%s", cnf->name); |
329 | 0 | goto err; |
330 | 0 | } |
331 | 0 | tag = displaytext_str2tag(value, &tag_len); |
332 | 0 | if ((not->exptext = ASN1_STRING_type_new(tag)) == NULL) { |
333 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
334 | 0 | goto err; |
335 | 0 | } |
336 | 0 | if (tag_len != 0) |
337 | 0 | value += tag_len + 1; |
338 | 0 | len = (int)strlen(value); |
339 | 0 | if (!ossl_asn1_string_set1_data(not->exptext, (uint8_t *)value, len)) { |
340 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
341 | 0 | goto err; |
342 | 0 | } |
343 | 0 | } else if (strcmp(cnf->name, "organization") == 0) { |
344 | 0 | NOTICEREF *nref; |
345 | |
|
346 | 0 | if (!not->noticeref) { |
347 | 0 | if ((nref = NOTICEREF_new()) == NULL) { |
348 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
349 | 0 | goto err; |
350 | 0 | } |
351 | 0 | not->noticeref = nref; |
352 | 0 | } else |
353 | 0 | nref = not->noticeref; |
354 | 0 | if (ia5org) |
355 | 0 | nref->organization->type = V_ASN1_IA5STRING; |
356 | 0 | else |
357 | 0 | nref->organization->type = V_ASN1_VISIBLESTRING; |
358 | 0 | if (!ossl_asn1_string_set1_string(nref->organization, cnf->value)) { |
359 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
360 | 0 | goto err; |
361 | 0 | } |
362 | 0 | } else if (strcmp(cnf->name, "noticeNumbers") == 0) { |
363 | 0 | NOTICEREF *nref; |
364 | |
|
365 | 0 | STACK_OF(CONF_VALUE) *nos; |
366 | 0 | if (!not->noticeref) { |
367 | 0 | if ((nref = NOTICEREF_new()) == NULL) { |
368 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB); |
369 | 0 | goto err; |
370 | 0 | } |
371 | 0 | not->noticeref = nref; |
372 | 0 | } else |
373 | 0 | nref = not->noticeref; |
374 | 0 | nos = X509V3_parse_list(cnf->value); |
375 | 0 | if (!nos || !sk_CONF_VALUE_num(nos)) { |
376 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NUMBERS); |
377 | 0 | X509V3_conf_add_error_name_value(cnf); |
378 | 0 | sk_CONF_VALUE_pop_free(nos, X509V3_conf_free); |
379 | 0 | goto err; |
380 | 0 | } |
381 | 0 | ret = nref_nos(nref->noticenos, nos); |
382 | 0 | sk_CONF_VALUE_pop_free(nos, X509V3_conf_free); |
383 | 0 | if (!ret) |
384 | 0 | goto err; |
385 | 0 | } else { |
386 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_OPTION); |
387 | 0 | X509V3_conf_add_error_name_value(cnf); |
388 | 0 | goto err; |
389 | 0 | } |
390 | 0 | } |
391 | | |
392 | 0 | if (not->noticeref && (!not->noticeref->noticenos || !not->noticeref->organization)) { |
393 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_NEED_ORGANIZATION_AND_NUMBERS); |
394 | 0 | goto err; |
395 | 0 | } |
396 | | |
397 | 0 | return qual; |
398 | | |
399 | 0 | err: |
400 | 0 | POLICYQUALINFO_free(qual); |
401 | 0 | return NULL; |
402 | 0 | } |
403 | | |
404 | | static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos) |
405 | 0 | { |
406 | 0 | CONF_VALUE *cnf; |
407 | 0 | ASN1_INTEGER *aint; |
408 | |
|
409 | 0 | int i; |
410 | |
|
411 | 0 | for (i = 0; i < sk_CONF_VALUE_num(nos); i++) { |
412 | 0 | cnf = sk_CONF_VALUE_value(nos, i); |
413 | 0 | if ((aint = s2i_ASN1_INTEGER(NULL, cnf->name)) == NULL) { |
414 | 0 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NUMBER); |
415 | 0 | return 0; |
416 | 0 | } |
417 | 0 | if (!sk_ASN1_INTEGER_push(nnums, aint)) { |
418 | 0 | ASN1_INTEGER_free(aint); |
419 | 0 | ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB); |
420 | 0 | return 0; |
421 | 0 | } |
422 | 0 | } |
423 | 0 | return 1; |
424 | 0 | } |
425 | | |
426 | | static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, |
427 | | BIO *out, int indent) |
428 | 0 | { |
429 | 0 | int i; |
430 | 0 | POLICYINFO *pinfo; |
431 | | /* First print out the policy OIDs */ |
432 | 0 | for (i = 0; i < sk_POLICYINFO_num(pol); i++) { |
433 | 0 | if (i > 0) |
434 | 0 | BIO_puts(out, "\n"); |
435 | 0 | pinfo = sk_POLICYINFO_value(pol, i); |
436 | 0 | BIO_printf(out, "%*sPolicy: ", indent, ""); |
437 | 0 | i2a_ASN1_OBJECT(out, pinfo->policyid); |
438 | 0 | if (pinfo->qualifiers) { |
439 | 0 | BIO_puts(out, "\n"); |
440 | 0 | print_qualifiers(out, pinfo->qualifiers, indent + 2); |
441 | 0 | } |
442 | 0 | } |
443 | 0 | return 1; |
444 | 0 | } |
445 | | |
446 | | static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, |
447 | | int indent) |
448 | 0 | { |
449 | 0 | POLICYQUALINFO *qualinfo; |
450 | 0 | int i; |
451 | 0 | for (i = 0; i < sk_POLICYQUALINFO_num(quals); i++) { |
452 | 0 | if (i > 0) |
453 | 0 | BIO_puts(out, "\n"); |
454 | 0 | qualinfo = sk_POLICYQUALINFO_value(quals, i); |
455 | 0 | switch (OBJ_obj2nid(qualinfo->pqualid)) { |
456 | 0 | case NID_id_qt_cps: |
457 | 0 | BIO_printf(out, "%*sCPS: %.*s", indent, "", |
458 | 0 | qualinfo->d.cpsuri->length, |
459 | 0 | qualinfo->d.cpsuri->length |
460 | 0 | ? qualinfo->d.cpsuri->data |
461 | 0 | : (const unsigned char *)""); |
462 | 0 | break; |
463 | | |
464 | 0 | case NID_id_qt_unotice: |
465 | 0 | BIO_printf(out, "%*sUser Notice:\n", indent, ""); |
466 | 0 | print_notice(out, qualinfo->d.usernotice, indent + 2); |
467 | 0 | break; |
468 | | |
469 | 0 | default: |
470 | 0 | BIO_printf(out, "%*sUnknown Qualifier: ", indent + 2, ""); |
471 | |
|
472 | 0 | i2a_ASN1_OBJECT(out, qualinfo->pqualid); |
473 | 0 | break; |
474 | 0 | } |
475 | 0 | } |
476 | 0 | } |
477 | | |
478 | | static void print_notice(BIO *out, USERNOTICE *notice, int indent) |
479 | 0 | { |
480 | 0 | int i; |
481 | 0 | if (notice->noticeref) { |
482 | 0 | NOTICEREF *ref; |
483 | 0 | ref = notice->noticeref; |
484 | 0 | BIO_printf(out, "%*sOrganization: %.*s\n", indent, "", |
485 | 0 | ref->organization->length, |
486 | 0 | ref->organization->length |
487 | 0 | ? ref->organization->data |
488 | 0 | : (const unsigned char *)""); |
489 | 0 | BIO_printf(out, "%*sNumber%s: ", indent, "", |
490 | 0 | sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : ""); |
491 | 0 | for (i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) { |
492 | 0 | ASN1_INTEGER *num; |
493 | 0 | char *tmp; |
494 | 0 | num = sk_ASN1_INTEGER_value(ref->noticenos, i); |
495 | 0 | if (i) |
496 | 0 | BIO_puts(out, ", "); |
497 | 0 | if (num == NULL) |
498 | 0 | BIO_puts(out, "(null)"); |
499 | 0 | else { |
500 | 0 | tmp = i2s_ASN1_INTEGER(NULL, num); |
501 | 0 | if (tmp == NULL) |
502 | 0 | return; |
503 | 0 | BIO_puts(out, tmp); |
504 | 0 | OPENSSL_free(tmp); |
505 | 0 | } |
506 | 0 | } |
507 | 0 | if (notice->exptext) |
508 | 0 | BIO_puts(out, "\n"); |
509 | 0 | } |
510 | 0 | if (notice->exptext) |
511 | 0 | BIO_printf(out, "%*sExplicit Text: %.*s", indent, "", |
512 | 0 | notice->exptext->length, |
513 | 0 | notice->exptext->length |
514 | 0 | ? notice->exptext->data |
515 | 0 | : (const unsigned char *)""); |
516 | 0 | } |
517 | | |
518 | | void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent) |
519 | 0 | { |
520 | 0 | const X509_POLICY_DATA *dat = node->data; |
521 | |
|
522 | 0 | BIO_printf(out, "%*sPolicy: ", indent, ""); |
523 | |
|
524 | 0 | i2a_ASN1_OBJECT(out, dat->valid_policy); |
525 | 0 | BIO_puts(out, "\n"); |
526 | 0 | BIO_printf(out, "%*s%s\n", indent + 2, "", |
527 | 0 | node_data_critical(dat) ? "Critical" : "Non Critical"); |
528 | 0 | if (dat->qualifier_set) { |
529 | 0 | print_qualifiers(out, dat->qualifier_set, indent + 2); |
530 | 0 | BIO_puts(out, "\n"); |
531 | 0 | } else |
532 | 0 | BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, ""); |
533 | 0 | } |