10Sstevel@tonic-gate /* v3_cpols.c */
20Sstevel@tonic-gate /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
30Sstevel@tonic-gate * project 1999.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate /* ====================================================================
6*2139Sjp161948 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
90Sstevel@tonic-gate * modification, are permitted provided that the following conditions
100Sstevel@tonic-gate * are met:
110Sstevel@tonic-gate *
120Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
130Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
140Sstevel@tonic-gate *
150Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
160Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in
170Sstevel@tonic-gate * the documentation and/or other materials provided with the
180Sstevel@tonic-gate * distribution.
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this
210Sstevel@tonic-gate * software must display the following acknowledgment:
220Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
230Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
240Sstevel@tonic-gate *
250Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
260Sstevel@tonic-gate * endorse or promote products derived from this software without
270Sstevel@tonic-gate * prior written permission. For written permission, please contact
280Sstevel@tonic-gate * licensing@OpenSSL.org.
290Sstevel@tonic-gate *
300Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL"
310Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written
320Sstevel@tonic-gate * permission of the OpenSSL Project.
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following
350Sstevel@tonic-gate * acknowledgment:
360Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
370Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
380Sstevel@tonic-gate *
390Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
400Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
410Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
420Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
430Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
440Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
450Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
460Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
470Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
480Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
490Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
500Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE.
510Sstevel@tonic-gate * ====================================================================
520Sstevel@tonic-gate *
530Sstevel@tonic-gate * This product includes cryptographic software written by Eric Young
540Sstevel@tonic-gate * (eay@cryptsoft.com). This product includes software written by Tim
550Sstevel@tonic-gate * Hudson (tjh@cryptsoft.com).
560Sstevel@tonic-gate *
570Sstevel@tonic-gate */
580Sstevel@tonic-gate
590Sstevel@tonic-gate #include <stdio.h>
600Sstevel@tonic-gate #include "cryptlib.h"
610Sstevel@tonic-gate #include <openssl/conf.h>
620Sstevel@tonic-gate #include <openssl/asn1.h>
630Sstevel@tonic-gate #include <openssl/asn1t.h>
640Sstevel@tonic-gate #include <openssl/x509v3.h>
650Sstevel@tonic-gate
66*2139Sjp161948 #include "pcy_int.h"
67*2139Sjp161948
680Sstevel@tonic-gate /* Certificate policies extension support: this one is a bit complex... */
690Sstevel@tonic-gate
700Sstevel@tonic-gate static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
710Sstevel@tonic-gate static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value);
720Sstevel@tonic-gate static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent);
730Sstevel@tonic-gate static void print_notice(BIO *out, USERNOTICE *notice, int indent);
740Sstevel@tonic-gate static POLICYINFO *policy_section(X509V3_CTX *ctx,
750Sstevel@tonic-gate STACK_OF(CONF_VALUE) *polstrs, int ia5org);
760Sstevel@tonic-gate static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
770Sstevel@tonic-gate STACK_OF(CONF_VALUE) *unot, int ia5org);
780Sstevel@tonic-gate static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos);
790Sstevel@tonic-gate
800Sstevel@tonic-gate X509V3_EXT_METHOD v3_cpols = {
810Sstevel@tonic-gate NID_certificate_policies, 0,ASN1_ITEM_ref(CERTIFICATEPOLICIES),
820Sstevel@tonic-gate 0,0,0,0,
830Sstevel@tonic-gate 0,0,
840Sstevel@tonic-gate 0,0,
850Sstevel@tonic-gate (X509V3_EXT_I2R)i2r_certpol,
860Sstevel@tonic-gate (X509V3_EXT_R2I)r2i_certpol,
870Sstevel@tonic-gate NULL
880Sstevel@tonic-gate };
890Sstevel@tonic-gate
900Sstevel@tonic-gate ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) =
910Sstevel@tonic-gate ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO)
920Sstevel@tonic-gate ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES)
930Sstevel@tonic-gate
940Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
950Sstevel@tonic-gate
960Sstevel@tonic-gate ASN1_SEQUENCE(POLICYINFO) = {
970Sstevel@tonic-gate ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT),
980Sstevel@tonic-gate ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO)
990Sstevel@tonic-gate } ASN1_SEQUENCE_END(POLICYINFO)
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO)
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY);
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate ASN1_ADB(POLICYQUALINFO) = {
1060Sstevel@tonic-gate ADB_ENTRY(NID_id_qt_cps, ASN1_SIMPLE(POLICYQUALINFO, d.cpsuri, ASN1_IA5STRING)),
1070Sstevel@tonic-gate ADB_ENTRY(NID_id_qt_unotice, ASN1_SIMPLE(POLICYQUALINFO, d.usernotice, USERNOTICE))
1080Sstevel@tonic-gate } ASN1_ADB_END(POLICYQUALINFO, 0, pqualid, 0, &policydefault_tt, NULL);
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate ASN1_SEQUENCE(POLICYQUALINFO) = {
1110Sstevel@tonic-gate ASN1_SIMPLE(POLICYQUALINFO, pqualid, ASN1_OBJECT),
1120Sstevel@tonic-gate ASN1_ADB_OBJECT(POLICYQUALINFO)
1130Sstevel@tonic-gate } ASN1_SEQUENCE_END(POLICYQUALINFO)
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO)
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate ASN1_SEQUENCE(USERNOTICE) = {
1180Sstevel@tonic-gate ASN1_OPT(USERNOTICE, noticeref, NOTICEREF),
1190Sstevel@tonic-gate ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT)
1200Sstevel@tonic-gate } ASN1_SEQUENCE_END(USERNOTICE)
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE)
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate ASN1_SEQUENCE(NOTICEREF) = {
1250Sstevel@tonic-gate ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT),
1260Sstevel@tonic-gate ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER)
1270Sstevel@tonic-gate } ASN1_SEQUENCE_END(NOTICEREF)
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF)
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
1320Sstevel@tonic-gate X509V3_CTX *ctx, char *value)
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate STACK_OF(POLICYINFO) *pols = NULL;
1350Sstevel@tonic-gate char *pstr;
1360Sstevel@tonic-gate POLICYINFO *pol;
1370Sstevel@tonic-gate ASN1_OBJECT *pobj;
1380Sstevel@tonic-gate STACK_OF(CONF_VALUE) *vals;
1390Sstevel@tonic-gate CONF_VALUE *cnf;
1400Sstevel@tonic-gate int i, ia5org;
1410Sstevel@tonic-gate pols = sk_POLICYINFO_new_null();
142*2139Sjp161948 if (pols == NULL) {
143*2139Sjp161948 X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
144*2139Sjp161948 return NULL;
145*2139Sjp161948 }
1460Sstevel@tonic-gate vals = X509V3_parse_list(value);
147*2139Sjp161948 if (vals == NULL) {
148*2139Sjp161948 X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_X509V3_LIB);
149*2139Sjp161948 goto err;
150*2139Sjp161948 }
1510Sstevel@tonic-gate ia5org = 0;
1520Sstevel@tonic-gate for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
1530Sstevel@tonic-gate cnf = sk_CONF_VALUE_value(vals, i);
1540Sstevel@tonic-gate if(cnf->value || !cnf->name ) {
1550Sstevel@tonic-gate X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
1560Sstevel@tonic-gate X509V3_conf_err(cnf);
1570Sstevel@tonic-gate goto err;
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate pstr = cnf->name;
1600Sstevel@tonic-gate if(!strcmp(pstr,"ia5org")) {
1610Sstevel@tonic-gate ia5org = 1;
1620Sstevel@tonic-gate continue;
1630Sstevel@tonic-gate } else if(*pstr == '@') {
1640Sstevel@tonic-gate STACK_OF(CONF_VALUE) *polsect;
1650Sstevel@tonic-gate polsect = X509V3_get_section(ctx, pstr + 1);
1660Sstevel@tonic-gate if(!polsect) {
1670Sstevel@tonic-gate X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate X509V3_conf_err(cnf);
1700Sstevel@tonic-gate goto err;
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate pol = policy_section(ctx, polsect, ia5org);
1730Sstevel@tonic-gate X509V3_section_free(ctx, polsect);
1740Sstevel@tonic-gate if(!pol) goto err;
1750Sstevel@tonic-gate } else {
1760Sstevel@tonic-gate if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
1770Sstevel@tonic-gate X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
1780Sstevel@tonic-gate X509V3_conf_err(cnf);
1790Sstevel@tonic-gate goto err;
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate pol = POLICYINFO_new();
1820Sstevel@tonic-gate pol->policyid = pobj;
1830Sstevel@tonic-gate }
1840Sstevel@tonic-gate sk_POLICYINFO_push(pols, pol);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
1870Sstevel@tonic-gate return pols;
1880Sstevel@tonic-gate err:
189*2139Sjp161948 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
1900Sstevel@tonic-gate sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
1910Sstevel@tonic-gate return NULL;
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate
policy_section(X509V3_CTX * ctx,STACK_OF (CONF_VALUE)* polstrs,int ia5org)1940Sstevel@tonic-gate static POLICYINFO *policy_section(X509V3_CTX *ctx,
1950Sstevel@tonic-gate STACK_OF(CONF_VALUE) *polstrs, int ia5org)
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate int i;
1980Sstevel@tonic-gate CONF_VALUE *cnf;
1990Sstevel@tonic-gate POLICYINFO *pol;
2000Sstevel@tonic-gate POLICYQUALINFO *qual;
2010Sstevel@tonic-gate if(!(pol = POLICYINFO_new())) goto merr;
2020Sstevel@tonic-gate for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
2030Sstevel@tonic-gate cnf = sk_CONF_VALUE_value(polstrs, i);
2040Sstevel@tonic-gate if(!strcmp(cnf->name, "policyIdentifier")) {
2050Sstevel@tonic-gate ASN1_OBJECT *pobj;
2060Sstevel@tonic-gate if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
2070Sstevel@tonic-gate X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
2080Sstevel@tonic-gate X509V3_conf_err(cnf);
2090Sstevel@tonic-gate goto err;
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate pol->policyid = pobj;
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate } else if(!name_cmp(cnf->name, "CPS")) {
2140Sstevel@tonic-gate if(!pol->qualifiers) pol->qualifiers =
2150Sstevel@tonic-gate sk_POLICYQUALINFO_new_null();
2160Sstevel@tonic-gate if(!(qual = POLICYQUALINFO_new())) goto merr;
2170Sstevel@tonic-gate if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
2180Sstevel@tonic-gate goto merr;
2190Sstevel@tonic-gate qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
2200Sstevel@tonic-gate qual->d.cpsuri = M_ASN1_IA5STRING_new();
2210Sstevel@tonic-gate if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
2220Sstevel@tonic-gate strlen(cnf->value))) goto merr;
2230Sstevel@tonic-gate } else if(!name_cmp(cnf->name, "userNotice")) {
2240Sstevel@tonic-gate STACK_OF(CONF_VALUE) *unot;
2250Sstevel@tonic-gate if(*cnf->value != '@') {
2260Sstevel@tonic-gate X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
2270Sstevel@tonic-gate X509V3_conf_err(cnf);
2280Sstevel@tonic-gate goto err;
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate unot = X509V3_get_section(ctx, cnf->value + 1);
2310Sstevel@tonic-gate if(!unot) {
2320Sstevel@tonic-gate X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate X509V3_conf_err(cnf);
2350Sstevel@tonic-gate goto err;
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate qual = notice_section(ctx, unot, ia5org);
2380Sstevel@tonic-gate X509V3_section_free(ctx, unot);
2390Sstevel@tonic-gate if(!qual) goto err;
2400Sstevel@tonic-gate if(!pol->qualifiers) pol->qualifiers =
2410Sstevel@tonic-gate sk_POLICYQUALINFO_new_null();
2420Sstevel@tonic-gate if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
2430Sstevel@tonic-gate goto merr;
2440Sstevel@tonic-gate } else {
2450Sstevel@tonic-gate X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate X509V3_conf_err(cnf);
2480Sstevel@tonic-gate goto err;
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate }
2510Sstevel@tonic-gate if(!pol->policyid) {
2520Sstevel@tonic-gate X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
2530Sstevel@tonic-gate goto err;
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate return pol;
2570Sstevel@tonic-gate
2580Sstevel@tonic-gate merr:
2590Sstevel@tonic-gate X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate err:
2620Sstevel@tonic-gate POLICYINFO_free(pol);
2630Sstevel@tonic-gate return NULL;
2640Sstevel@tonic-gate
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate
notice_section(X509V3_CTX * ctx,STACK_OF (CONF_VALUE)* unot,int ia5org)2680Sstevel@tonic-gate static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
2690Sstevel@tonic-gate STACK_OF(CONF_VALUE) *unot, int ia5org)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate int i, ret;
2720Sstevel@tonic-gate CONF_VALUE *cnf;
2730Sstevel@tonic-gate USERNOTICE *not;
2740Sstevel@tonic-gate POLICYQUALINFO *qual;
2750Sstevel@tonic-gate if(!(qual = POLICYQUALINFO_new())) goto merr;
2760Sstevel@tonic-gate qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
2770Sstevel@tonic-gate if(!(not = USERNOTICE_new())) goto merr;
2780Sstevel@tonic-gate qual->d.usernotice = not;
2790Sstevel@tonic-gate for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
2800Sstevel@tonic-gate cnf = sk_CONF_VALUE_value(unot, i);
2810Sstevel@tonic-gate if(!strcmp(cnf->name, "explicitText")) {
2820Sstevel@tonic-gate not->exptext = M_ASN1_VISIBLESTRING_new();
2830Sstevel@tonic-gate if(!ASN1_STRING_set(not->exptext, cnf->value,
2840Sstevel@tonic-gate strlen(cnf->value))) goto merr;
2850Sstevel@tonic-gate } else if(!strcmp(cnf->name, "organization")) {
2860Sstevel@tonic-gate NOTICEREF *nref;
2870Sstevel@tonic-gate if(!not->noticeref) {
2880Sstevel@tonic-gate if(!(nref = NOTICEREF_new())) goto merr;
2890Sstevel@tonic-gate not->noticeref = nref;
2900Sstevel@tonic-gate } else nref = not->noticeref;
2910Sstevel@tonic-gate if(ia5org) nref->organization->type = V_ASN1_IA5STRING;
2920Sstevel@tonic-gate else nref->organization->type = V_ASN1_VISIBLESTRING;
2930Sstevel@tonic-gate if(!ASN1_STRING_set(nref->organization, cnf->value,
2940Sstevel@tonic-gate strlen(cnf->value))) goto merr;
2950Sstevel@tonic-gate } else if(!strcmp(cnf->name, "noticeNumbers")) {
2960Sstevel@tonic-gate NOTICEREF *nref;
2970Sstevel@tonic-gate STACK_OF(CONF_VALUE) *nos;
2980Sstevel@tonic-gate if(!not->noticeref) {
2990Sstevel@tonic-gate if(!(nref = NOTICEREF_new())) goto merr;
3000Sstevel@tonic-gate not->noticeref = nref;
3010Sstevel@tonic-gate } else nref = not->noticeref;
3020Sstevel@tonic-gate nos = X509V3_parse_list(cnf->value);
3030Sstevel@tonic-gate if(!nos || !sk_CONF_VALUE_num(nos)) {
3040Sstevel@tonic-gate X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
3050Sstevel@tonic-gate X509V3_conf_err(cnf);
3060Sstevel@tonic-gate goto err;
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate ret = nref_nos(nref->noticenos, nos);
3090Sstevel@tonic-gate sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
3100Sstevel@tonic-gate if (!ret)
3110Sstevel@tonic-gate goto err;
3120Sstevel@tonic-gate } else {
3130Sstevel@tonic-gate X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
3140Sstevel@tonic-gate X509V3_conf_err(cnf);
3150Sstevel@tonic-gate goto err;
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate }
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate if(not->noticeref &&
3200Sstevel@tonic-gate (!not->noticeref->noticenos || !not->noticeref->organization)) {
3210Sstevel@tonic-gate X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
3220Sstevel@tonic-gate goto err;
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate return qual;
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate merr:
3280Sstevel@tonic-gate X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate err:
3310Sstevel@tonic-gate POLICYQUALINFO_free(qual);
3320Sstevel@tonic-gate return NULL;
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate
nref_nos(STACK_OF (ASN1_INTEGER)* nnums,STACK_OF (CONF_VALUE)* nos)3350Sstevel@tonic-gate static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
3360Sstevel@tonic-gate {
3370Sstevel@tonic-gate CONF_VALUE *cnf;
3380Sstevel@tonic-gate ASN1_INTEGER *aint;
3390Sstevel@tonic-gate
3400Sstevel@tonic-gate int i;
3410Sstevel@tonic-gate
3420Sstevel@tonic-gate for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
3430Sstevel@tonic-gate cnf = sk_CONF_VALUE_value(nos, i);
3440Sstevel@tonic-gate if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
3450Sstevel@tonic-gate X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
3460Sstevel@tonic-gate goto err;
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate if(!sk_ASN1_INTEGER_push(nnums, aint)) goto merr;
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate return 1;
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate merr:
353*2139Sjp161948 X509V3err(X509V3_F_NREF_NOS,ERR_R_MALLOC_FAILURE);
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate err:
3560Sstevel@tonic-gate sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
3570Sstevel@tonic-gate return 0;
3580Sstevel@tonic-gate }
3590Sstevel@tonic-gate
3600Sstevel@tonic-gate
i2r_certpol(X509V3_EXT_METHOD * method,STACK_OF (POLICYINFO)* pol,BIO * out,int indent)3610Sstevel@tonic-gate static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
3620Sstevel@tonic-gate BIO *out, int indent)
3630Sstevel@tonic-gate {
3640Sstevel@tonic-gate int i;
3650Sstevel@tonic-gate POLICYINFO *pinfo;
3660Sstevel@tonic-gate /* First print out the policy OIDs */
3670Sstevel@tonic-gate for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
3680Sstevel@tonic-gate pinfo = sk_POLICYINFO_value(pol, i);
3690Sstevel@tonic-gate BIO_printf(out, "%*sPolicy: ", indent, "");
3700Sstevel@tonic-gate i2a_ASN1_OBJECT(out, pinfo->policyid);
3710Sstevel@tonic-gate BIO_puts(out, "\n");
3720Sstevel@tonic-gate if(pinfo->qualifiers)
3730Sstevel@tonic-gate print_qualifiers(out, pinfo->qualifiers, indent + 2);
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate return 1;
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate
print_qualifiers(BIO * out,STACK_OF (POLICYQUALINFO)* quals,int indent)3780Sstevel@tonic-gate static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
3790Sstevel@tonic-gate int indent)
3800Sstevel@tonic-gate {
3810Sstevel@tonic-gate POLICYQUALINFO *qualinfo;
3820Sstevel@tonic-gate int i;
3830Sstevel@tonic-gate for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
3840Sstevel@tonic-gate qualinfo = sk_POLICYQUALINFO_value(quals, i);
3850Sstevel@tonic-gate switch(OBJ_obj2nid(qualinfo->pqualid))
3860Sstevel@tonic-gate {
3870Sstevel@tonic-gate case NID_id_qt_cps:
3880Sstevel@tonic-gate BIO_printf(out, "%*sCPS: %s\n", indent, "",
3890Sstevel@tonic-gate qualinfo->d.cpsuri->data);
3900Sstevel@tonic-gate break;
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate case NID_id_qt_unotice:
3930Sstevel@tonic-gate BIO_printf(out, "%*sUser Notice:\n", indent, "");
3940Sstevel@tonic-gate print_notice(out, qualinfo->d.usernotice, indent + 2);
3950Sstevel@tonic-gate break;
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate default:
3980Sstevel@tonic-gate BIO_printf(out, "%*sUnknown Qualifier: ",
3990Sstevel@tonic-gate indent + 2, "");
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate i2a_ASN1_OBJECT(out, qualinfo->pqualid);
4020Sstevel@tonic-gate BIO_puts(out, "\n");
4030Sstevel@tonic-gate break;
4040Sstevel@tonic-gate }
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate
print_notice(BIO * out,USERNOTICE * notice,int indent)4080Sstevel@tonic-gate static void print_notice(BIO *out, USERNOTICE *notice, int indent)
4090Sstevel@tonic-gate {
4100Sstevel@tonic-gate int i;
4110Sstevel@tonic-gate if(notice->noticeref) {
4120Sstevel@tonic-gate NOTICEREF *ref;
4130Sstevel@tonic-gate ref = notice->noticeref;
4140Sstevel@tonic-gate BIO_printf(out, "%*sOrganization: %s\n", indent, "",
4150Sstevel@tonic-gate ref->organization->data);
4160Sstevel@tonic-gate BIO_printf(out, "%*sNumber%s: ", indent, "",
4170Sstevel@tonic-gate sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
4180Sstevel@tonic-gate for(i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
4190Sstevel@tonic-gate ASN1_INTEGER *num;
4200Sstevel@tonic-gate char *tmp;
4210Sstevel@tonic-gate num = sk_ASN1_INTEGER_value(ref->noticenos, i);
4220Sstevel@tonic-gate if(i) BIO_puts(out, ", ");
4230Sstevel@tonic-gate tmp = i2s_ASN1_INTEGER(NULL, num);
4240Sstevel@tonic-gate BIO_puts(out, tmp);
4250Sstevel@tonic-gate OPENSSL_free(tmp);
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate BIO_puts(out, "\n");
4280Sstevel@tonic-gate }
4290Sstevel@tonic-gate if(notice->exptext)
4300Sstevel@tonic-gate BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
4310Sstevel@tonic-gate notice->exptext->data);
4320Sstevel@tonic-gate }
4330Sstevel@tonic-gate
X509_POLICY_NODE_print(BIO * out,X509_POLICY_NODE * node,int indent)434*2139Sjp161948 void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent)
435*2139Sjp161948 {
436*2139Sjp161948 const X509_POLICY_DATA *dat = node->data;
437*2139Sjp161948
438*2139Sjp161948 BIO_printf(out, "%*sPolicy: ", indent, "");
439*2139Sjp161948
440*2139Sjp161948 i2a_ASN1_OBJECT(out, dat->valid_policy);
441*2139Sjp161948 BIO_puts(out, "\n");
442*2139Sjp161948 BIO_printf(out, "%*s%s\n", indent + 2, "",
443*2139Sjp161948 node_data_critical(dat) ? "Critical" : "Non Critical");
444*2139Sjp161948 if (dat->qualifier_set)
445*2139Sjp161948 print_qualifiers(out, dat->qualifier_set, indent + 2);
446*2139Sjp161948 else
447*2139Sjp161948 BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, "");
448*2139Sjp161948 }
449*2139Sjp161948
450