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