xref: /onnv-gate/usr/src/common/openssl/crypto/x509v3/v3_cpols.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /* v3_cpols.c */
2*0Sstevel@tonic-gate /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3*0Sstevel@tonic-gate  * project 1999.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate /* ====================================================================
6*0Sstevel@tonic-gate  * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
7*0Sstevel@tonic-gate  *
8*0Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
9*0Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
10*0Sstevel@tonic-gate  * are met:
11*0Sstevel@tonic-gate  *
12*0Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
13*0Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
14*0Sstevel@tonic-gate  *
15*0Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
16*0Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in
17*0Sstevel@tonic-gate  *    the documentation and/or other materials provided with the
18*0Sstevel@tonic-gate  *    distribution.
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this
21*0Sstevel@tonic-gate  *    software must display the following acknowledgment:
22*0Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
23*0Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24*0Sstevel@tonic-gate  *
25*0Sstevel@tonic-gate  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26*0Sstevel@tonic-gate  *    endorse or promote products derived from this software without
27*0Sstevel@tonic-gate  *    prior written permission. For written permission, please contact
28*0Sstevel@tonic-gate  *    licensing@OpenSSL.org.
29*0Sstevel@tonic-gate  *
30*0Sstevel@tonic-gate  * 5. Products derived from this software may not be called "OpenSSL"
31*0Sstevel@tonic-gate  *    nor may "OpenSSL" appear in their names without prior written
32*0Sstevel@tonic-gate  *    permission of the OpenSSL Project.
33*0Sstevel@tonic-gate  *
34*0Sstevel@tonic-gate  * 6. Redistributions of any form whatsoever must retain the following
35*0Sstevel@tonic-gate  *    acknowledgment:
36*0Sstevel@tonic-gate  *    "This product includes software developed by the OpenSSL Project
37*0Sstevel@tonic-gate  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38*0Sstevel@tonic-gate  *
39*0Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40*0Sstevel@tonic-gate  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41*0Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42*0Sstevel@tonic-gate  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43*0Sstevel@tonic-gate  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44*0Sstevel@tonic-gate  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45*0Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46*0Sstevel@tonic-gate  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47*0Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48*0Sstevel@tonic-gate  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49*0Sstevel@tonic-gate  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50*0Sstevel@tonic-gate  * OF THE POSSIBILITY OF SUCH DAMAGE.
51*0Sstevel@tonic-gate  * ====================================================================
52*0Sstevel@tonic-gate  *
53*0Sstevel@tonic-gate  * This product includes cryptographic software written by Eric Young
54*0Sstevel@tonic-gate  * (eay@cryptsoft.com).  This product includes software written by Tim
55*0Sstevel@tonic-gate  * Hudson (tjh@cryptsoft.com).
56*0Sstevel@tonic-gate  *
57*0Sstevel@tonic-gate  */
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate #include <stdio.h>
60*0Sstevel@tonic-gate #include "cryptlib.h"
61*0Sstevel@tonic-gate #include <openssl/conf.h>
62*0Sstevel@tonic-gate #include <openssl/asn1.h>
63*0Sstevel@tonic-gate #include <openssl/asn1t.h>
64*0Sstevel@tonic-gate #include <openssl/x509v3.h>
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate /* Certificate policies extension support: this one is a bit complex... */
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
69*0Sstevel@tonic-gate static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value);
70*0Sstevel@tonic-gate static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent);
71*0Sstevel@tonic-gate static void print_notice(BIO *out, USERNOTICE *notice, int indent);
72*0Sstevel@tonic-gate static POLICYINFO *policy_section(X509V3_CTX *ctx,
73*0Sstevel@tonic-gate 				 STACK_OF(CONF_VALUE) *polstrs, int ia5org);
74*0Sstevel@tonic-gate static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
75*0Sstevel@tonic-gate 					STACK_OF(CONF_VALUE) *unot, int ia5org);
76*0Sstevel@tonic-gate static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos);
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate X509V3_EXT_METHOD v3_cpols = {
79*0Sstevel@tonic-gate NID_certificate_policies, 0,ASN1_ITEM_ref(CERTIFICATEPOLICIES),
80*0Sstevel@tonic-gate 0,0,0,0,
81*0Sstevel@tonic-gate 0,0,
82*0Sstevel@tonic-gate 0,0,
83*0Sstevel@tonic-gate (X509V3_EXT_I2R)i2r_certpol,
84*0Sstevel@tonic-gate (X509V3_EXT_R2I)r2i_certpol,
85*0Sstevel@tonic-gate NULL
86*0Sstevel@tonic-gate };
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) =
89*0Sstevel@tonic-gate 	ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO)
90*0Sstevel@tonic-gate ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES)
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate ASN1_SEQUENCE(POLICYINFO) = {
95*0Sstevel@tonic-gate 	ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT),
96*0Sstevel@tonic-gate 	ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO)
97*0Sstevel@tonic-gate } ASN1_SEQUENCE_END(POLICYINFO)
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO)
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY);
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate ASN1_ADB(POLICYQUALINFO) = {
104*0Sstevel@tonic-gate 	ADB_ENTRY(NID_id_qt_cps, ASN1_SIMPLE(POLICYQUALINFO, d.cpsuri, ASN1_IA5STRING)),
105*0Sstevel@tonic-gate 	ADB_ENTRY(NID_id_qt_unotice, ASN1_SIMPLE(POLICYQUALINFO, d.usernotice, USERNOTICE))
106*0Sstevel@tonic-gate } ASN1_ADB_END(POLICYQUALINFO, 0, pqualid, 0, &policydefault_tt, NULL);
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate ASN1_SEQUENCE(POLICYQUALINFO) = {
109*0Sstevel@tonic-gate 	ASN1_SIMPLE(POLICYQUALINFO, pqualid, ASN1_OBJECT),
110*0Sstevel@tonic-gate 	ASN1_ADB_OBJECT(POLICYQUALINFO)
111*0Sstevel@tonic-gate } ASN1_SEQUENCE_END(POLICYQUALINFO)
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO)
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate ASN1_SEQUENCE(USERNOTICE) = {
116*0Sstevel@tonic-gate 	ASN1_OPT(USERNOTICE, noticeref, NOTICEREF),
117*0Sstevel@tonic-gate 	ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT)
118*0Sstevel@tonic-gate } ASN1_SEQUENCE_END(USERNOTICE)
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE)
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate ASN1_SEQUENCE(NOTICEREF) = {
123*0Sstevel@tonic-gate 	ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT),
124*0Sstevel@tonic-gate 	ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER)
125*0Sstevel@tonic-gate } ASN1_SEQUENCE_END(NOTICEREF)
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF)
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
130*0Sstevel@tonic-gate 		X509V3_CTX *ctx, char *value)
131*0Sstevel@tonic-gate {
132*0Sstevel@tonic-gate 	STACK_OF(POLICYINFO) *pols = NULL;
133*0Sstevel@tonic-gate 	char *pstr;
134*0Sstevel@tonic-gate 	POLICYINFO *pol;
135*0Sstevel@tonic-gate 	ASN1_OBJECT *pobj;
136*0Sstevel@tonic-gate 	STACK_OF(CONF_VALUE) *vals;
137*0Sstevel@tonic-gate 	CONF_VALUE *cnf;
138*0Sstevel@tonic-gate 	int i, ia5org;
139*0Sstevel@tonic-gate 	pols = sk_POLICYINFO_new_null();
140*0Sstevel@tonic-gate 	vals =  X509V3_parse_list(value);
141*0Sstevel@tonic-gate 	ia5org = 0;
142*0Sstevel@tonic-gate 	for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
143*0Sstevel@tonic-gate 		cnf = sk_CONF_VALUE_value(vals, i);
144*0Sstevel@tonic-gate 		if(cnf->value || !cnf->name ) {
145*0Sstevel@tonic-gate 			X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
146*0Sstevel@tonic-gate 			X509V3_conf_err(cnf);
147*0Sstevel@tonic-gate 			goto err;
148*0Sstevel@tonic-gate 		}
149*0Sstevel@tonic-gate 		pstr = cnf->name;
150*0Sstevel@tonic-gate 		if(!strcmp(pstr,"ia5org")) {
151*0Sstevel@tonic-gate 			ia5org = 1;
152*0Sstevel@tonic-gate 			continue;
153*0Sstevel@tonic-gate 		} else if(*pstr == '@') {
154*0Sstevel@tonic-gate 			STACK_OF(CONF_VALUE) *polsect;
155*0Sstevel@tonic-gate 			polsect = X509V3_get_section(ctx, pstr + 1);
156*0Sstevel@tonic-gate 			if(!polsect) {
157*0Sstevel@tonic-gate 				X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate 				X509V3_conf_err(cnf);
160*0Sstevel@tonic-gate 				goto err;
161*0Sstevel@tonic-gate 			}
162*0Sstevel@tonic-gate 			pol = policy_section(ctx, polsect, ia5org);
163*0Sstevel@tonic-gate 			X509V3_section_free(ctx, polsect);
164*0Sstevel@tonic-gate 			if(!pol) goto err;
165*0Sstevel@tonic-gate 		} else {
166*0Sstevel@tonic-gate 			if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
167*0Sstevel@tonic-gate 				X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
168*0Sstevel@tonic-gate 				X509V3_conf_err(cnf);
169*0Sstevel@tonic-gate 				goto err;
170*0Sstevel@tonic-gate 			}
171*0Sstevel@tonic-gate 			pol = POLICYINFO_new();
172*0Sstevel@tonic-gate 			pol->policyid = pobj;
173*0Sstevel@tonic-gate 		}
174*0Sstevel@tonic-gate 		sk_POLICYINFO_push(pols, pol);
175*0Sstevel@tonic-gate 	}
176*0Sstevel@tonic-gate 	sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
177*0Sstevel@tonic-gate 	return pols;
178*0Sstevel@tonic-gate 	err:
179*0Sstevel@tonic-gate 	sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
180*0Sstevel@tonic-gate 	return NULL;
181*0Sstevel@tonic-gate }
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate static POLICYINFO *policy_section(X509V3_CTX *ctx,
184*0Sstevel@tonic-gate 				STACK_OF(CONF_VALUE) *polstrs, int ia5org)
185*0Sstevel@tonic-gate {
186*0Sstevel@tonic-gate 	int i;
187*0Sstevel@tonic-gate 	CONF_VALUE *cnf;
188*0Sstevel@tonic-gate 	POLICYINFO *pol;
189*0Sstevel@tonic-gate 	POLICYQUALINFO *qual;
190*0Sstevel@tonic-gate 	if(!(pol = POLICYINFO_new())) goto merr;
191*0Sstevel@tonic-gate 	for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
192*0Sstevel@tonic-gate 		cnf = sk_CONF_VALUE_value(polstrs, i);
193*0Sstevel@tonic-gate 		if(!strcmp(cnf->name, "policyIdentifier")) {
194*0Sstevel@tonic-gate 			ASN1_OBJECT *pobj;
195*0Sstevel@tonic-gate 			if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
196*0Sstevel@tonic-gate 				X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
197*0Sstevel@tonic-gate 				X509V3_conf_err(cnf);
198*0Sstevel@tonic-gate 				goto err;
199*0Sstevel@tonic-gate 			}
200*0Sstevel@tonic-gate 			pol->policyid = pobj;
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate 		} else if(!name_cmp(cnf->name, "CPS")) {
203*0Sstevel@tonic-gate 			if(!pol->qualifiers) pol->qualifiers =
204*0Sstevel@tonic-gate 						 sk_POLICYQUALINFO_new_null();
205*0Sstevel@tonic-gate 			if(!(qual = POLICYQUALINFO_new())) goto merr;
206*0Sstevel@tonic-gate 			if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
207*0Sstevel@tonic-gate 								 goto merr;
208*0Sstevel@tonic-gate 			qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
209*0Sstevel@tonic-gate 			qual->d.cpsuri = M_ASN1_IA5STRING_new();
210*0Sstevel@tonic-gate 			if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
211*0Sstevel@tonic-gate 						 strlen(cnf->value))) goto merr;
212*0Sstevel@tonic-gate 		} else if(!name_cmp(cnf->name, "userNotice")) {
213*0Sstevel@tonic-gate 			STACK_OF(CONF_VALUE) *unot;
214*0Sstevel@tonic-gate 			if(*cnf->value != '@') {
215*0Sstevel@tonic-gate 				X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
216*0Sstevel@tonic-gate 				X509V3_conf_err(cnf);
217*0Sstevel@tonic-gate 				goto err;
218*0Sstevel@tonic-gate 			}
219*0Sstevel@tonic-gate 			unot = X509V3_get_section(ctx, cnf->value + 1);
220*0Sstevel@tonic-gate 			if(!unot) {
221*0Sstevel@tonic-gate 				X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate 				X509V3_conf_err(cnf);
224*0Sstevel@tonic-gate 				goto err;
225*0Sstevel@tonic-gate 			}
226*0Sstevel@tonic-gate 			qual = notice_section(ctx, unot, ia5org);
227*0Sstevel@tonic-gate 			X509V3_section_free(ctx, unot);
228*0Sstevel@tonic-gate 			if(!qual) goto err;
229*0Sstevel@tonic-gate 			if(!pol->qualifiers) pol->qualifiers =
230*0Sstevel@tonic-gate 						 sk_POLICYQUALINFO_new_null();
231*0Sstevel@tonic-gate 			if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
232*0Sstevel@tonic-gate 								 goto merr;
233*0Sstevel@tonic-gate 		} else {
234*0Sstevel@tonic-gate 			X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate 			X509V3_conf_err(cnf);
237*0Sstevel@tonic-gate 			goto err;
238*0Sstevel@tonic-gate 		}
239*0Sstevel@tonic-gate 	}
240*0Sstevel@tonic-gate 	if(!pol->policyid) {
241*0Sstevel@tonic-gate 		X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
242*0Sstevel@tonic-gate 		goto err;
243*0Sstevel@tonic-gate 	}
244*0Sstevel@tonic-gate 
245*0Sstevel@tonic-gate 	return pol;
246*0Sstevel@tonic-gate 
247*0Sstevel@tonic-gate 	merr:
248*0Sstevel@tonic-gate 	X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
249*0Sstevel@tonic-gate 
250*0Sstevel@tonic-gate 	err:
251*0Sstevel@tonic-gate 	POLICYINFO_free(pol);
252*0Sstevel@tonic-gate 	return NULL;
253*0Sstevel@tonic-gate 
254*0Sstevel@tonic-gate 
255*0Sstevel@tonic-gate }
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
258*0Sstevel@tonic-gate 					STACK_OF(CONF_VALUE) *unot, int ia5org)
259*0Sstevel@tonic-gate {
260*0Sstevel@tonic-gate 	int i, ret;
261*0Sstevel@tonic-gate 	CONF_VALUE *cnf;
262*0Sstevel@tonic-gate 	USERNOTICE *not;
263*0Sstevel@tonic-gate 	POLICYQUALINFO *qual;
264*0Sstevel@tonic-gate 	if(!(qual = POLICYQUALINFO_new())) goto merr;
265*0Sstevel@tonic-gate 	qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
266*0Sstevel@tonic-gate 	if(!(not = USERNOTICE_new())) goto merr;
267*0Sstevel@tonic-gate 	qual->d.usernotice = not;
268*0Sstevel@tonic-gate 	for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
269*0Sstevel@tonic-gate 		cnf = sk_CONF_VALUE_value(unot, i);
270*0Sstevel@tonic-gate 		if(!strcmp(cnf->name, "explicitText")) {
271*0Sstevel@tonic-gate 			not->exptext = M_ASN1_VISIBLESTRING_new();
272*0Sstevel@tonic-gate 			if(!ASN1_STRING_set(not->exptext, cnf->value,
273*0Sstevel@tonic-gate 						 strlen(cnf->value))) goto merr;
274*0Sstevel@tonic-gate 		} else if(!strcmp(cnf->name, "organization")) {
275*0Sstevel@tonic-gate 			NOTICEREF *nref;
276*0Sstevel@tonic-gate 			if(!not->noticeref) {
277*0Sstevel@tonic-gate 				if(!(nref = NOTICEREF_new())) goto merr;
278*0Sstevel@tonic-gate 				not->noticeref = nref;
279*0Sstevel@tonic-gate 			} else nref = not->noticeref;
280*0Sstevel@tonic-gate 			if(ia5org) nref->organization->type = V_ASN1_IA5STRING;
281*0Sstevel@tonic-gate 			else nref->organization->type = V_ASN1_VISIBLESTRING;
282*0Sstevel@tonic-gate 			if(!ASN1_STRING_set(nref->organization, cnf->value,
283*0Sstevel@tonic-gate 						 strlen(cnf->value))) goto merr;
284*0Sstevel@tonic-gate 		} else if(!strcmp(cnf->name, "noticeNumbers")) {
285*0Sstevel@tonic-gate 			NOTICEREF *nref;
286*0Sstevel@tonic-gate 			STACK_OF(CONF_VALUE) *nos;
287*0Sstevel@tonic-gate 			if(!not->noticeref) {
288*0Sstevel@tonic-gate 				if(!(nref = NOTICEREF_new())) goto merr;
289*0Sstevel@tonic-gate 				not->noticeref = nref;
290*0Sstevel@tonic-gate 			} else nref = not->noticeref;
291*0Sstevel@tonic-gate 			nos = X509V3_parse_list(cnf->value);
292*0Sstevel@tonic-gate 			if(!nos || !sk_CONF_VALUE_num(nos)) {
293*0Sstevel@tonic-gate 				X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
294*0Sstevel@tonic-gate 				X509V3_conf_err(cnf);
295*0Sstevel@tonic-gate 				goto err;
296*0Sstevel@tonic-gate 			}
297*0Sstevel@tonic-gate 			ret = nref_nos(nref->noticenos, nos);
298*0Sstevel@tonic-gate 			sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
299*0Sstevel@tonic-gate 			if (!ret)
300*0Sstevel@tonic-gate 				goto err;
301*0Sstevel@tonic-gate 		} else {
302*0Sstevel@tonic-gate 			X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
303*0Sstevel@tonic-gate 			X509V3_conf_err(cnf);
304*0Sstevel@tonic-gate 			goto err;
305*0Sstevel@tonic-gate 		}
306*0Sstevel@tonic-gate 	}
307*0Sstevel@tonic-gate 
308*0Sstevel@tonic-gate 	if(not->noticeref &&
309*0Sstevel@tonic-gate 	      (!not->noticeref->noticenos || !not->noticeref->organization)) {
310*0Sstevel@tonic-gate 			X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
311*0Sstevel@tonic-gate 			goto err;
312*0Sstevel@tonic-gate 	}
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate 	return qual;
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate 	merr:
317*0Sstevel@tonic-gate 	X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate 	err:
320*0Sstevel@tonic-gate 	POLICYQUALINFO_free(qual);
321*0Sstevel@tonic-gate 	return NULL;
322*0Sstevel@tonic-gate }
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
325*0Sstevel@tonic-gate {
326*0Sstevel@tonic-gate 	CONF_VALUE *cnf;
327*0Sstevel@tonic-gate 	ASN1_INTEGER *aint;
328*0Sstevel@tonic-gate 
329*0Sstevel@tonic-gate 	int i;
330*0Sstevel@tonic-gate 
331*0Sstevel@tonic-gate 	for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
332*0Sstevel@tonic-gate 		cnf = sk_CONF_VALUE_value(nos, i);
333*0Sstevel@tonic-gate 		if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
334*0Sstevel@tonic-gate 			X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
335*0Sstevel@tonic-gate 			goto err;
336*0Sstevel@tonic-gate 		}
337*0Sstevel@tonic-gate 		if(!sk_ASN1_INTEGER_push(nnums, aint)) goto merr;
338*0Sstevel@tonic-gate 	}
339*0Sstevel@tonic-gate 	return 1;
340*0Sstevel@tonic-gate 
341*0Sstevel@tonic-gate 	merr:
342*0Sstevel@tonic-gate 	X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate 	err:
345*0Sstevel@tonic-gate 	sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
346*0Sstevel@tonic-gate 	return 0;
347*0Sstevel@tonic-gate }
348*0Sstevel@tonic-gate 
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
351*0Sstevel@tonic-gate 		BIO *out, int indent)
352*0Sstevel@tonic-gate {
353*0Sstevel@tonic-gate 	int i;
354*0Sstevel@tonic-gate 	POLICYINFO *pinfo;
355*0Sstevel@tonic-gate 	/* First print out the policy OIDs */
356*0Sstevel@tonic-gate 	for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
357*0Sstevel@tonic-gate 		pinfo = sk_POLICYINFO_value(pol, i);
358*0Sstevel@tonic-gate 		BIO_printf(out, "%*sPolicy: ", indent, "");
359*0Sstevel@tonic-gate 		i2a_ASN1_OBJECT(out, pinfo->policyid);
360*0Sstevel@tonic-gate 		BIO_puts(out, "\n");
361*0Sstevel@tonic-gate 		if(pinfo->qualifiers)
362*0Sstevel@tonic-gate 			 print_qualifiers(out, pinfo->qualifiers, indent + 2);
363*0Sstevel@tonic-gate 	}
364*0Sstevel@tonic-gate 	return 1;
365*0Sstevel@tonic-gate }
366*0Sstevel@tonic-gate 
367*0Sstevel@tonic-gate static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
368*0Sstevel@tonic-gate 		int indent)
369*0Sstevel@tonic-gate {
370*0Sstevel@tonic-gate 	POLICYQUALINFO *qualinfo;
371*0Sstevel@tonic-gate 	int i;
372*0Sstevel@tonic-gate 	for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
373*0Sstevel@tonic-gate 		qualinfo = sk_POLICYQUALINFO_value(quals, i);
374*0Sstevel@tonic-gate 		switch(OBJ_obj2nid(qualinfo->pqualid))
375*0Sstevel@tonic-gate 		{
376*0Sstevel@tonic-gate 			case NID_id_qt_cps:
377*0Sstevel@tonic-gate 			BIO_printf(out, "%*sCPS: %s\n", indent, "",
378*0Sstevel@tonic-gate 						qualinfo->d.cpsuri->data);
379*0Sstevel@tonic-gate 			break;
380*0Sstevel@tonic-gate 
381*0Sstevel@tonic-gate 			case NID_id_qt_unotice:
382*0Sstevel@tonic-gate 			BIO_printf(out, "%*sUser Notice:\n", indent, "");
383*0Sstevel@tonic-gate 			print_notice(out, qualinfo->d.usernotice, indent + 2);
384*0Sstevel@tonic-gate 			break;
385*0Sstevel@tonic-gate 
386*0Sstevel@tonic-gate 			default:
387*0Sstevel@tonic-gate 			BIO_printf(out, "%*sUnknown Qualifier: ",
388*0Sstevel@tonic-gate 							 indent + 2, "");
389*0Sstevel@tonic-gate 
390*0Sstevel@tonic-gate 			i2a_ASN1_OBJECT(out, qualinfo->pqualid);
391*0Sstevel@tonic-gate 			BIO_puts(out, "\n");
392*0Sstevel@tonic-gate 			break;
393*0Sstevel@tonic-gate 		}
394*0Sstevel@tonic-gate 	}
395*0Sstevel@tonic-gate }
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate static void print_notice(BIO *out, USERNOTICE *notice, int indent)
398*0Sstevel@tonic-gate {
399*0Sstevel@tonic-gate 	int i;
400*0Sstevel@tonic-gate 	if(notice->noticeref) {
401*0Sstevel@tonic-gate 		NOTICEREF *ref;
402*0Sstevel@tonic-gate 		ref = notice->noticeref;
403*0Sstevel@tonic-gate 		BIO_printf(out, "%*sOrganization: %s\n", indent, "",
404*0Sstevel@tonic-gate 						 ref->organization->data);
405*0Sstevel@tonic-gate 		BIO_printf(out, "%*sNumber%s: ", indent, "",
406*0Sstevel@tonic-gate 			   sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
407*0Sstevel@tonic-gate 		for(i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
408*0Sstevel@tonic-gate 			ASN1_INTEGER *num;
409*0Sstevel@tonic-gate 			char *tmp;
410*0Sstevel@tonic-gate 			num = sk_ASN1_INTEGER_value(ref->noticenos, i);
411*0Sstevel@tonic-gate 			if(i) BIO_puts(out, ", ");
412*0Sstevel@tonic-gate 			tmp = i2s_ASN1_INTEGER(NULL, num);
413*0Sstevel@tonic-gate 			BIO_puts(out, tmp);
414*0Sstevel@tonic-gate 			OPENSSL_free(tmp);
415*0Sstevel@tonic-gate 		}
416*0Sstevel@tonic-gate 		BIO_puts(out, "\n");
417*0Sstevel@tonic-gate 	}
418*0Sstevel@tonic-gate 	if(notice->exptext)
419*0Sstevel@tonic-gate 		BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
420*0Sstevel@tonic-gate 							 notice->exptext->data);
421*0Sstevel@tonic-gate }
422*0Sstevel@tonic-gate 
423