1999-04-19 07:21:03 +08:00
|
|
|
/* v3_cpols.c */
|
|
|
|
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
|
|
|
|
* project 1999.
|
|
|
|
*/
|
|
|
|
/* ====================================================================
|
|
|
|
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* 3. All advertising materials mentioning features or use of this
|
|
|
|
* software must display the following acknowledgment:
|
|
|
|
* "This product includes software developed by the OpenSSL Project
|
|
|
|
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
|
|
|
*
|
|
|
|
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* prior written permission. For written permission, please contact
|
|
|
|
* licensing@OpenSSL.org.
|
|
|
|
*
|
|
|
|
* 5. Products derived from this software may not be called "OpenSSL"
|
|
|
|
* nor may "OpenSSL" appear in their names without prior written
|
|
|
|
* permission of the OpenSSL Project.
|
|
|
|
*
|
|
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
|
|
|
* acknowledgment:
|
|
|
|
* "This product includes software developed by the OpenSSL Project
|
|
|
|
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
|
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
|
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* ====================================================================
|
|
|
|
*
|
|
|
|
* This product includes cryptographic software written by Eric Young
|
|
|
|
* (eay@cryptsoft.com). This product includes software written by Tim
|
|
|
|
* Hudson (tjh@cryptsoft.com).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/asn1.h>
|
|
|
|
#include <openssl/asn1_mac.h>
|
|
|
|
#include <openssl/x509v3.h>
|
1999-04-19 07:21:03 +08:00
|
|
|
|
|
|
|
/* Certificate policies extension support: this one is a bit complex... */
|
|
|
|
|
|
|
|
static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
|
|
|
|
static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value);
|
|
|
|
static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent);
|
|
|
|
static void print_notice(BIO *out, USERNOTICE *notice, int indent);
|
1999-06-21 06:18:16 +08:00
|
|
|
static POLICYINFO *policy_section(X509V3_CTX *ctx,
|
|
|
|
STACK_OF(CONF_VALUE) *polstrs, int ia5org);
|
|
|
|
static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
|
|
|
|
STACK_OF(CONF_VALUE) *unot, int ia5org);
|
2000-05-17 17:13:36 +08:00
|
|
|
static STACK_OF(ASN1_INTEGER) *nref_nos(STACK_OF(CONF_VALUE) *nos);
|
1999-04-19 07:21:03 +08:00
|
|
|
|
|
|
|
X509V3_EXT_METHOD v3_cpols = {
|
|
|
|
NID_certificate_policies, 0,
|
|
|
|
(X509V3_EXT_NEW)CERTIFICATEPOLICIES_new,
|
1999-06-22 07:59:09 +08:00
|
|
|
(X509V3_EXT_FREE)CERTIFICATEPOLICIES_free,
|
1999-04-19 07:21:03 +08:00
|
|
|
(X509V3_EXT_D2I)d2i_CERTIFICATEPOLICIES,
|
1999-06-22 07:59:09 +08:00
|
|
|
(X509V3_EXT_I2D)i2d_CERTIFICATEPOLICIES,
|
1999-04-19 07:21:03 +08:00
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
|
|
|
(X509V3_EXT_I2R)i2r_certpol,
|
|
|
|
(X509V3_EXT_R2I)r2i_certpol,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
|
|
|
|
X509V3_CTX *ctx, char *value)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
STACK_OF(POLICYINFO) *pols = NULL;
|
|
|
|
char *pstr;
|
|
|
|
POLICYINFO *pol;
|
|
|
|
ASN1_OBJECT *pobj;
|
1999-06-21 06:18:16 +08:00
|
|
|
STACK_OF(CONF_VALUE) *vals;
|
1999-04-19 07:21:03 +08:00
|
|
|
CONF_VALUE *cnf;
|
1999-05-08 20:59:50 +08:00
|
|
|
int i, ia5org;
|
1999-04-19 07:21:03 +08:00
|
|
|
pols = sk_POLICYINFO_new_null();
|
|
|
|
vals = X509V3_parse_list(value);
|
1999-05-08 20:59:50 +08:00
|
|
|
ia5org = 0;
|
1999-06-21 06:18:16 +08:00
|
|
|
for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(vals, i);
|
1999-04-19 07:21:03 +08:00
|
|
|
if(cnf->value || !cnf->name ) {
|
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
pstr = cnf->name;
|
1999-05-08 20:59:50 +08:00
|
|
|
if(!strcmp(pstr,"ia5org")) {
|
|
|
|
ia5org = 1;
|
|
|
|
continue;
|
|
|
|
} else if(*pstr == '@') {
|
1999-06-21 06:18:16 +08:00
|
|
|
STACK_OF(CONF_VALUE) *polsect;
|
1999-04-19 07:21:03 +08:00
|
|
|
polsect = X509V3_get_section(ctx, pstr + 1);
|
|
|
|
if(!polsect) {
|
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
|
|
|
|
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
1999-05-08 20:59:50 +08:00
|
|
|
pol = policy_section(ctx, polsect, ia5org);
|
1999-04-19 07:21:03 +08:00
|
|
|
X509V3_section_free(ctx, polsect);
|
|
|
|
if(!pol) goto err;
|
|
|
|
} else {
|
|
|
|
if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
|
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
pol = POLICYINFO_new();
|
|
|
|
pol->policyid = pobj;
|
|
|
|
}
|
|
|
|
sk_POLICYINFO_push(pols, pol);
|
|
|
|
}
|
1999-06-21 06:18:16 +08:00
|
|
|
sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
|
1999-04-19 07:21:03 +08:00
|
|
|
return pols;
|
|
|
|
err:
|
|
|
|
sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-06-21 06:18:16 +08:00
|
|
|
static POLICYINFO *policy_section(X509V3_CTX *ctx,
|
|
|
|
STACK_OF(CONF_VALUE) *polstrs, int ia5org)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CONF_VALUE *cnf;
|
1999-04-20 01:55:11 +08:00
|
|
|
POLICYINFO *pol;
|
|
|
|
POLICYQUALINFO *qual;
|
|
|
|
if(!(pol = POLICYINFO_new())) goto merr;
|
1999-06-21 06:18:16 +08:00
|
|
|
for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(polstrs, i);
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!strcmp(cnf->name, "policyIdentifier")) {
|
|
|
|
ASN1_OBJECT *pobj;
|
|
|
|
if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
|
|
|
|
X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
pol->policyid = pobj;
|
|
|
|
|
|
|
|
} else if(!name_cmp(cnf->name, "CPS")) {
|
|
|
|
if(!pol->qualifiers) pol->qualifiers =
|
|
|
|
sk_POLICYQUALINFO_new_null();
|
|
|
|
if(!(qual = POLICYQUALINFO_new())) goto merr;
|
|
|
|
if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
|
|
|
|
goto merr;
|
|
|
|
qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
|
1999-10-20 09:50:23 +08:00
|
|
|
qual->d.cpsuri = M_ASN1_IA5STRING_new();
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
|
|
|
|
strlen(cnf->value))) goto merr;
|
|
|
|
} else if(!name_cmp(cnf->name, "userNotice")) {
|
1999-06-21 06:18:16 +08:00
|
|
|
STACK_OF(CONF_VALUE) *unot;
|
1999-04-20 01:55:11 +08:00
|
|
|
if(*cnf->value != '@') {
|
|
|
|
X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
unot = X509V3_get_section(ctx, cnf->value + 1);
|
|
|
|
if(!unot) {
|
|
|
|
X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
|
|
|
|
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
1999-05-08 20:59:50 +08:00
|
|
|
qual = notice_section(ctx, unot, ia5org);
|
1999-04-20 01:55:11 +08:00
|
|
|
X509V3_section_free(ctx, unot);
|
|
|
|
if(!qual) goto err;
|
|
|
|
if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
|
|
|
|
goto merr;
|
|
|
|
} else {
|
|
|
|
X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
|
|
|
|
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!pol->policyid) {
|
|
|
|
X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pol;
|
|
|
|
|
|
|
|
merr:
|
|
|
|
X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
|
1999-04-22 01:44:45 +08:00
|
|
|
|
|
|
|
err:
|
1999-04-20 01:55:11 +08:00
|
|
|
POLICYINFO_free(pol);
|
|
|
|
return NULL;
|
|
|
|
|
1999-04-22 01:44:45 +08:00
|
|
|
|
1999-04-20 01:55:11 +08:00
|
|
|
}
|
|
|
|
|
1999-06-21 06:18:16 +08:00
|
|
|
static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
|
|
|
|
STACK_OF(CONF_VALUE) *unot, int ia5org)
|
1999-04-20 01:55:11 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CONF_VALUE *cnf;
|
|
|
|
USERNOTICE *not;
|
|
|
|
POLICYQUALINFO *qual;
|
|
|
|
if(!(qual = POLICYQUALINFO_new())) goto merr;
|
|
|
|
qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
|
|
|
|
if(!(not = USERNOTICE_new())) goto merr;
|
|
|
|
qual->d.usernotice = not;
|
1999-06-21 06:18:16 +08:00
|
|
|
for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(unot, i);
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!strcmp(cnf->name, "explicitText")) {
|
1999-10-20 09:50:23 +08:00
|
|
|
not->exptext = M_ASN1_VISIBLESTRING_new();
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!ASN1_STRING_set(not->exptext, cnf->value,
|
|
|
|
strlen(cnf->value))) goto merr;
|
|
|
|
} else if(!strcmp(cnf->name, "organization")) {
|
|
|
|
NOTICEREF *nref;
|
|
|
|
if(!not->noticeref) {
|
|
|
|
if(!(nref = NOTICEREF_new())) goto merr;
|
|
|
|
not->noticeref = nref;
|
|
|
|
} else nref = not->noticeref;
|
1999-10-20 09:50:23 +08:00
|
|
|
if(ia5org) nref->organization = M_ASN1_IA5STRING_new();
|
|
|
|
else nref->organization = M_ASN1_VISIBLESTRING_new();
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!ASN1_STRING_set(nref->organization, cnf->value,
|
|
|
|
strlen(cnf->value))) goto merr;
|
|
|
|
} else if(!strcmp(cnf->name, "noticeNumbers")) {
|
|
|
|
NOTICEREF *nref;
|
1999-06-21 06:18:16 +08:00
|
|
|
STACK_OF(CONF_VALUE) *nos;
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!not->noticeref) {
|
|
|
|
if(!(nref = NOTICEREF_new())) goto merr;
|
|
|
|
not->noticeref = nref;
|
|
|
|
} else nref = not->noticeref;
|
|
|
|
nos = X509V3_parse_list(cnf->value);
|
1999-06-21 06:18:16 +08:00
|
|
|
if(!nos || !sk_CONF_VALUE_num(nos)) {
|
1999-04-20 01:55:11 +08:00
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
nref->noticenos = nref_nos(nos);
|
1999-06-21 06:18:16 +08:00
|
|
|
sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!nref->noticenos) goto err;
|
|
|
|
} else {
|
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
|
|
|
|
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(not->noticeref &&
|
|
|
|
(!not->noticeref->noticenos || !not->noticeref->organization)) {
|
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
|
|
|
|
goto err;
|
1999-04-19 07:21:03 +08:00
|
|
|
}
|
1999-04-20 01:55:11 +08:00
|
|
|
|
|
|
|
return qual;
|
|
|
|
|
|
|
|
merr:
|
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
|
1999-04-22 01:44:45 +08:00
|
|
|
|
|
|
|
err:
|
1999-04-20 01:55:11 +08:00
|
|
|
POLICYQUALINFO_free(qual);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-17 17:13:36 +08:00
|
|
|
static STACK_OF(ASN1_INTEGER) *nref_nos(STACK_OF(CONF_VALUE) *nos)
|
1999-04-20 01:55:11 +08:00
|
|
|
{
|
2000-05-17 17:13:36 +08:00
|
|
|
STACK_OF(ASN1_INTEGER) *nnums;
|
1999-04-20 01:55:11 +08:00
|
|
|
CONF_VALUE *cnf;
|
|
|
|
ASN1_INTEGER *aint;
|
2000-05-17 17:13:36 +08:00
|
|
|
|
1999-04-20 01:55:11 +08:00
|
|
|
int i;
|
2000-05-17 17:13:36 +08:00
|
|
|
|
|
|
|
if(!(nnums = sk_ASN1_INTEGER_new_null())) goto merr;
|
1999-06-21 06:18:16 +08:00
|
|
|
for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(nos, i);
|
1999-04-20 01:55:11 +08:00
|
|
|
if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
|
|
|
|
X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
|
|
|
|
goto err;
|
|
|
|
}
|
2000-05-17 17:13:36 +08:00
|
|
|
if(!sk_ASN1_INTEGER_push(nnums, aint)) goto merr;
|
1999-04-20 01:55:11 +08:00
|
|
|
}
|
|
|
|
return nnums;
|
|
|
|
|
|
|
|
merr:
|
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
|
1999-04-22 01:44:45 +08:00
|
|
|
|
|
|
|
err:
|
2000-05-17 17:13:36 +08:00
|
|
|
sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
|
1999-04-19 07:21:03 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
|
|
|
|
BIO *out, int indent)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
POLICYINFO *pinfo;
|
|
|
|
/* First print out the policy OIDs */
|
|
|
|
for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
|
|
|
|
pinfo = sk_POLICYINFO_value(pol, i);
|
|
|
|
BIO_printf(out, "%*sPolicy: ", indent, "");
|
|
|
|
i2a_ASN1_OBJECT(out, pinfo->policyid);
|
|
|
|
BIO_puts(out, "\n");
|
|
|
|
if(pinfo->qualifiers)
|
|
|
|
print_qualifiers(out, pinfo->qualifiers, indent + 2);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
return i2d_ASN1_SET_OF_POLICYINFO(a, pp, i2d_POLICYINFO, V_ASN1_SEQUENCE,
|
|
|
|
V_ASN1_UNIVERSAL, IS_SEQUENCE);}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
return sk_POLICYINFO_new_null();
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
sk_POLICYINFO_pop_free(a, POLICYINFO_free);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a,
|
|
|
|
unsigned char **pp,long length)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
return d2i_ASN1_SET_OF_POLICYINFO(a, pp, length, d2i_POLICYINFO,
|
|
|
|
POLICYINFO_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPLEMENT_STACK_OF(POLICYINFO)
|
|
|
|
IMPLEMENT_ASN1_SET_OF(POLICYINFO)
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_I2D_vars(a);
|
|
|
|
|
|
|
|
M_ASN1_I2D_len (a->policyid, i2d_ASN1_OBJECT);
|
|
|
|
M_ASN1_I2D_len_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
|
|
|
|
i2d_POLICYQUALINFO);
|
|
|
|
|
|
|
|
M_ASN1_I2D_seq_total();
|
|
|
|
|
|
|
|
M_ASN1_I2D_put (a->policyid, i2d_ASN1_OBJECT);
|
|
|
|
M_ASN1_I2D_put_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
|
|
|
|
i2d_POLICYQUALINFO);
|
|
|
|
|
|
|
|
M_ASN1_I2D_finish();
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
POLICYINFO *POLICYINFO_new(void)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
POLICYINFO *ret=NULL;
|
|
|
|
ASN1_CTX c;
|
|
|
|
M_ASN1_New_Malloc(ret, POLICYINFO);
|
|
|
|
ret->policyid = NULL;
|
|
|
|
ret->qualifiers = NULL;
|
|
|
|
return (ret);
|
|
|
|
M_ASN1_New_Error(ASN1_F_POLICYINFO_NEW);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp,long length)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_D2I_vars(a,POLICYINFO *,POLICYINFO_new);
|
|
|
|
M_ASN1_D2I_Init();
|
|
|
|
M_ASN1_D2I_start_sequence();
|
|
|
|
M_ASN1_D2I_get(ret->policyid, d2i_ASN1_OBJECT);
|
|
|
|
if(!M_ASN1_D2I_end_sequence()) {
|
|
|
|
M_ASN1_D2I_get_seq_type (POLICYQUALINFO, ret->qualifiers,
|
|
|
|
d2i_POLICYQUALINFO, POLICYQUALINFO_free);
|
|
|
|
}
|
|
|
|
M_ASN1_D2I_Finish(a, POLICYINFO_free, ASN1_F_D2I_POLICYINFO);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
void POLICYINFO_free(POLICYINFO *a)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
if (a == NULL) return;
|
|
|
|
ASN1_OBJECT_free(a->policyid);
|
|
|
|
sk_POLICYQUALINFO_pop_free(a->qualifiers, POLICYQUALINFO_free);
|
|
|
|
Free (a);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
|
|
|
|
int indent)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
POLICYQUALINFO *qualinfo;
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
|
|
|
|
qualinfo = sk_POLICYQUALINFO_value(quals, i);
|
|
|
|
switch(OBJ_obj2nid(qualinfo->pqualid))
|
|
|
|
{
|
|
|
|
case NID_id_qt_cps:
|
|
|
|
BIO_printf(out, "%*sCPS: %s\n", indent, "",
|
|
|
|
qualinfo->d.cpsuri->data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NID_id_qt_unotice:
|
|
|
|
BIO_printf(out, "%*sUser Notice:\n", indent, "");
|
|
|
|
print_notice(out, qualinfo->d.usernotice, indent + 2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BIO_printf(out, "%*sUnknown Qualifier: ",
|
|
|
|
indent + 2, "");
|
|
|
|
|
|
|
|
i2a_ASN1_OBJECT(out, qualinfo->pqualid);
|
|
|
|
BIO_puts(out, "\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static void print_notice(BIO *out, USERNOTICE *notice, int indent)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if(notice->noticeref) {
|
|
|
|
NOTICEREF *ref;
|
|
|
|
ref = notice->noticeref;
|
|
|
|
BIO_printf(out, "%*sOrganization: %s\n", indent, "",
|
|
|
|
ref->organization->data);
|
|
|
|
BIO_printf(out, "%*sNumber%s: ", indent, "",
|
2000-05-17 17:13:36 +08:00
|
|
|
sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
|
|
|
|
for(i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
|
1999-04-19 07:21:03 +08:00
|
|
|
ASN1_INTEGER *num;
|
|
|
|
char *tmp;
|
2000-05-17 17:13:36 +08:00
|
|
|
num = sk_ASN1_INTEGER_value(ref->noticenos, i);
|
1999-04-19 07:21:03 +08:00
|
|
|
if(i) BIO_puts(out, ", ");
|
|
|
|
tmp = i2s_ASN1_INTEGER(NULL, num);
|
|
|
|
BIO_puts(out, tmp);
|
|
|
|
Free(tmp);
|
|
|
|
}
|
|
|
|
BIO_puts(out, "\n");
|
|
|
|
}
|
|
|
|
if(notice->exptext)
|
1999-04-20 01:55:11 +08:00
|
|
|
BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
|
1999-04-19 07:21:03 +08:00
|
|
|
notice->exptext->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_I2D_vars(a);
|
|
|
|
|
|
|
|
M_ASN1_I2D_len (a->pqualid, i2d_ASN1_OBJECT);
|
|
|
|
switch(OBJ_obj2nid(a->pqualid)) {
|
|
|
|
case NID_id_qt_cps:
|
|
|
|
M_ASN1_I2D_len(a->d.cpsuri, i2d_ASN1_IA5STRING);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NID_id_qt_unotice:
|
|
|
|
M_ASN1_I2D_len(a->d.usernotice, i2d_USERNOTICE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
M_ASN1_I2D_len(a->d.other, i2d_ASN1_TYPE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
M_ASN1_I2D_seq_total();
|
|
|
|
|
|
|
|
M_ASN1_I2D_put (a->pqualid, i2d_ASN1_OBJECT);
|
|
|
|
switch(OBJ_obj2nid(a->pqualid)) {
|
|
|
|
case NID_id_qt_cps:
|
|
|
|
M_ASN1_I2D_put(a->d.cpsuri, i2d_ASN1_IA5STRING);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NID_id_qt_unotice:
|
|
|
|
M_ASN1_I2D_put(a->d.usernotice, i2d_USERNOTICE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
M_ASN1_I2D_put(a->d.other, i2d_ASN1_TYPE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
M_ASN1_I2D_finish();
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
POLICYQUALINFO *POLICYQUALINFO_new(void)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
POLICYQUALINFO *ret=NULL;
|
|
|
|
ASN1_CTX c;
|
|
|
|
M_ASN1_New_Malloc(ret, POLICYQUALINFO);
|
|
|
|
ret->pqualid = NULL;
|
|
|
|
ret->d.other = NULL;
|
|
|
|
return (ret);
|
|
|
|
M_ASN1_New_Error(ASN1_F_POLICYQUALINFO_NEW);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp,
|
|
|
|
long length)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_D2I_vars(a,POLICYQUALINFO *,POLICYQUALINFO_new);
|
|
|
|
M_ASN1_D2I_Init();
|
|
|
|
M_ASN1_D2I_start_sequence();
|
|
|
|
M_ASN1_D2I_get (ret->pqualid, d2i_ASN1_OBJECT);
|
|
|
|
switch(OBJ_obj2nid(ret->pqualid)) {
|
|
|
|
case NID_id_qt_cps:
|
|
|
|
M_ASN1_D2I_get(ret->d.cpsuri, d2i_ASN1_IA5STRING);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NID_id_qt_unotice:
|
|
|
|
M_ASN1_D2I_get(ret->d.usernotice, d2i_USERNOTICE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
M_ASN1_D2I_get(ret->d.other, d2i_ASN1_TYPE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
M_ASN1_D2I_Finish(a, POLICYQUALINFO_free, ASN1_F_D2I_POLICYQUALINFO);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
void POLICYQUALINFO_free(POLICYQUALINFO *a)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
if (a == NULL) return;
|
|
|
|
switch(OBJ_obj2nid(a->pqualid)) {
|
|
|
|
case NID_id_qt_cps:
|
1999-10-20 09:50:23 +08:00
|
|
|
M_ASN1_IA5STRING_free(a->d.cpsuri);
|
1999-04-19 07:21:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NID_id_qt_unotice:
|
|
|
|
USERNOTICE_free(a->d.usernotice);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASN1_TYPE_free(a->d.other);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASN1_OBJECT_free(a->pqualid);
|
|
|
|
Free (a);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_I2D_vars(a);
|
|
|
|
|
|
|
|
M_ASN1_I2D_len (a->noticeref, i2d_NOTICEREF);
|
|
|
|
M_ASN1_I2D_len (a->exptext, i2d_DISPLAYTEXT);
|
|
|
|
|
|
|
|
M_ASN1_I2D_seq_total();
|
|
|
|
|
|
|
|
M_ASN1_I2D_put (a->noticeref, i2d_NOTICEREF);
|
|
|
|
M_ASN1_I2D_put (a->exptext, i2d_DISPLAYTEXT);
|
|
|
|
|
|
|
|
M_ASN1_I2D_finish();
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
USERNOTICE *USERNOTICE_new(void)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
USERNOTICE *ret=NULL;
|
|
|
|
ASN1_CTX c;
|
|
|
|
M_ASN1_New_Malloc(ret, USERNOTICE);
|
|
|
|
ret->noticeref = NULL;
|
|
|
|
ret->exptext = NULL;
|
|
|
|
return (ret);
|
|
|
|
M_ASN1_New_Error(ASN1_F_USERNOTICE_NEW);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp,long length)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_D2I_vars(a,USERNOTICE *,USERNOTICE_new);
|
|
|
|
M_ASN1_D2I_Init();
|
|
|
|
M_ASN1_D2I_start_sequence();
|
|
|
|
M_ASN1_D2I_get_opt(ret->noticeref, d2i_NOTICEREF, V_ASN1_SEQUENCE);
|
|
|
|
if (!M_ASN1_D2I_end_sequence()) {
|
|
|
|
M_ASN1_D2I_get(ret->exptext, d2i_DISPLAYTEXT);
|
|
|
|
}
|
|
|
|
M_ASN1_D2I_Finish(a, USERNOTICE_free, ASN1_F_D2I_USERNOTICE);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
void USERNOTICE_free(USERNOTICE *a)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
if (a == NULL) return;
|
|
|
|
NOTICEREF_free(a->noticeref);
|
1999-10-20 09:50:23 +08:00
|
|
|
M_DISPLAYTEXT_free(a->exptext);
|
1999-04-19 07:21:03 +08:00
|
|
|
Free (a);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_I2D_vars(a);
|
|
|
|
|
|
|
|
M_ASN1_I2D_len (a->organization, i2d_DISPLAYTEXT);
|
2000-05-17 17:13:36 +08:00
|
|
|
M_ASN1_I2D_len_SEQUENCE_type(ASN1_INTEGER, a->noticenos,
|
|
|
|
i2d_ASN1_INTEGER);
|
1999-04-19 07:21:03 +08:00
|
|
|
|
|
|
|
M_ASN1_I2D_seq_total();
|
|
|
|
|
|
|
|
M_ASN1_I2D_put (a->organization, i2d_DISPLAYTEXT);
|
2000-05-17 17:13:36 +08:00
|
|
|
M_ASN1_I2D_put_SEQUENCE_type(ASN1_INTEGER, a->noticenos,
|
|
|
|
i2d_ASN1_INTEGER);
|
1999-04-19 07:21:03 +08:00
|
|
|
|
|
|
|
M_ASN1_I2D_finish();
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
NOTICEREF *NOTICEREF_new(void)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
NOTICEREF *ret=NULL;
|
|
|
|
ASN1_CTX c;
|
|
|
|
M_ASN1_New_Malloc(ret, NOTICEREF);
|
|
|
|
ret->organization = NULL;
|
|
|
|
ret->noticenos = NULL;
|
|
|
|
return (ret);
|
|
|
|
M_ASN1_New_Error(ASN1_F_NOTICEREF_NEW);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
M_ASN1_D2I_vars(a,NOTICEREF *,NOTICEREF_new);
|
|
|
|
M_ASN1_D2I_Init();
|
|
|
|
M_ASN1_D2I_start_sequence();
|
|
|
|
/* This is to cope with some broken encodings that use IA5STRING for
|
|
|
|
* the organization field
|
|
|
|
*/
|
|
|
|
M_ASN1_D2I_get_opt(ret->organization, d2i_ASN1_IA5STRING,
|
|
|
|
V_ASN1_IA5STRING);
|
|
|
|
if(!ret->organization) {
|
|
|
|
M_ASN1_D2I_get(ret->organization, d2i_DISPLAYTEXT);
|
|
|
|
}
|
2000-05-17 17:13:36 +08:00
|
|
|
M_ASN1_D2I_get_seq_type(ASN1_INTEGER, ret->noticenos, d2i_ASN1_INTEGER,
|
|
|
|
ASN1_STRING_free);
|
1999-04-19 07:21:03 +08:00
|
|
|
M_ASN1_D2I_Finish(a, NOTICEREF_free, ASN1_F_D2I_NOTICEREF);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
void NOTICEREF_free(NOTICEREF *a)
|
1999-04-19 07:21:03 +08:00
|
|
|
{
|
|
|
|
if (a == NULL) return;
|
1999-10-20 09:50:23 +08:00
|
|
|
M_DISPLAYTEXT_free(a->organization);
|
2000-05-17 17:13:36 +08:00
|
|
|
sk_ASN1_INTEGER_pop_free(a->noticenos, ASN1_STRING_free);
|
1999-04-19 07:21:03 +08:00
|
|
|
Free (a);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPLEMENT_STACK_OF(POLICYQUALINFO)
|
|
|
|
IMPLEMENT_ASN1_SET_OF(POLICYQUALINFO)
|