2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-05-17 18:51:26 +00:00
|
|
|
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
1999-04-18 23:21:03 +00:00
|
|
|
*
|
2016-05-17 18:51:26 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1999-04-18 23:21:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/asn1.h>
|
2000-12-08 19:09:35 +00:00
|
|
|
#include <openssl/asn1t.h>
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/x509v3.h>
|
1999-04-18 23:21:03 +00:00
|
|
|
|
2004-03-31 12:17:24 +00:00
|
|
|
#include "pcy_int.h"
|
2015-09-05 12:32:58 +00:00
|
|
|
#include "ext_dat.h"
|
2004-03-31 12:17:24 +00:00
|
|
|
|
1999-04-18 23:21:03 +00:00
|
|
|
/* Certificate policies extension support: this one is a bit complex... */
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
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,
|
2016-06-12 16:20:40 +00:00
|
|
|
X509V3_CTX *ctx, const char *value);
|
2015-01-22 03:40:55 +00:00
|
|
|
static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
|
|
|
|
int indent);
|
1999-04-18 23:21:03 +00:00
|
|
|
static void print_notice(BIO *out, USERNOTICE *notice, int indent);
|
1999-06-20 22:18:16 +00:00
|
|
|
static POLICYINFO *policy_section(X509V3_CTX *ctx,
|
2015-01-22 03:40:55 +00:00
|
|
|
STACK_OF(CONF_VALUE) *polstrs, int ia5org);
|
1999-06-20 22:18:16 +00:00
|
|
|
static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
|
2015-01-22 03:40:55 +00:00
|
|
|
STACK_OF(CONF_VALUE) *unot, int ia5org);
|
2003-05-28 17:28:11 +00:00
|
|
|
static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos);
|
2016-01-21 18:43:57 +00:00
|
|
|
static int displaytext_str2tag(const char *tagstr, unsigned int *tag_len);
|
|
|
|
static int displaytext_get_tag_len(const char *tagstr);
|
1999-04-18 23:21:03 +00:00
|
|
|
|
2007-01-21 13:07:17 +00:00
|
|
|
const X509V3_EXT_METHOD v3_cpols = {
|
2015-01-22 03:40:55 +00:00
|
|
|
NID_certificate_policies, 0, ASN1_ITEM_ref(CERTIFICATEPOLICIES),
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0,
|
|
|
|
0, 0,
|
|
|
|
(X509V3_EXT_I2R)i2r_certpol,
|
|
|
|
(X509V3_EXT_R2I)r2i_certpol,
|
|
|
|
NULL
|
1999-04-18 23:21:03 +00:00
|
|
|
};
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) =
|
|
|
|
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO)
|
2001-02-23 12:47:06 +00:00
|
|
|
ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES)
|
2000-12-08 19:09:35 +00:00
|
|
|
|
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES)
|
|
|
|
|
|
|
|
ASN1_SEQUENCE(POLICYINFO) = {
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT),
|
|
|
|
ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO)
|
2001-02-23 12:47:06 +00:00
|
|
|
} ASN1_SEQUENCE_END(POLICYINFO)
|
2000-12-08 19:09:35 +00:00
|
|
|
|
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO)
|
|
|
|
|
|
|
|
ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY);
|
|
|
|
|
|
|
|
ASN1_ADB(POLICYQUALINFO) = {
|
2015-01-22 03:40:55 +00:00
|
|
|
ADB_ENTRY(NID_id_qt_cps, ASN1_SIMPLE(POLICYQUALINFO, d.cpsuri, ASN1_IA5STRING)),
|
|
|
|
ADB_ENTRY(NID_id_qt_unotice, ASN1_SIMPLE(POLICYQUALINFO, d.usernotice, USERNOTICE))
|
2000-12-08 19:09:35 +00:00
|
|
|
} ASN1_ADB_END(POLICYQUALINFO, 0, pqualid, 0, &policydefault_tt, NULL);
|
|
|
|
|
|
|
|
ASN1_SEQUENCE(POLICYQUALINFO) = {
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_SIMPLE(POLICYQUALINFO, pqualid, ASN1_OBJECT),
|
|
|
|
ASN1_ADB_OBJECT(POLICYQUALINFO)
|
2001-02-23 12:47:06 +00:00
|
|
|
} ASN1_SEQUENCE_END(POLICYQUALINFO)
|
2000-12-08 19:09:35 +00:00
|
|
|
|
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO)
|
|
|
|
|
|
|
|
ASN1_SEQUENCE(USERNOTICE) = {
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_OPT(USERNOTICE, noticeref, NOTICEREF),
|
|
|
|
ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT)
|
2001-02-23 12:47:06 +00:00
|
|
|
} ASN1_SEQUENCE_END(USERNOTICE)
|
2000-12-08 19:09:35 +00:00
|
|
|
|
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE)
|
|
|
|
|
|
|
|
ASN1_SEQUENCE(NOTICEREF) = {
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT),
|
|
|
|
ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER)
|
2001-02-23 12:47:06 +00:00
|
|
|
} ASN1_SEQUENCE_END(NOTICEREF)
|
2000-12-08 19:09:35 +00:00
|
|
|
|
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF)
|
1999-04-18 23:21:03 +00:00
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
|
2016-06-12 16:20:40 +00:00
|
|
|
X509V3_CTX *ctx, const char *value)
|
1999-04-18 23:21:03 +00:00
|
|
|
{
|
2017-09-28 21:30:22 +00:00
|
|
|
STACK_OF(POLICYINFO) *pols;
|
2015-01-22 03:40:55 +00:00
|
|
|
char *pstr;
|
|
|
|
POLICYINFO *pol;
|
|
|
|
ASN1_OBJECT *pobj;
|
2017-09-28 21:30:22 +00:00
|
|
|
STACK_OF(CONF_VALUE) *vals = X509V3_parse_list(value);
|
2015-01-22 03:40:55 +00:00
|
|
|
CONF_VALUE *cnf;
|
2017-09-28 21:30:22 +00:00
|
|
|
const int num = sk_CONF_VALUE_num(vals);
|
2015-01-22 03:40:55 +00:00
|
|
|
int i, ia5org;
|
2017-09-28 21:30:22 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (vals == NULL) {
|
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_X509V3_LIB);
|
2017-09-28 21:30:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-26 17:56:14 +00:00
|
|
|
pols = sk_POLICYINFO_new_reserve(NULL, num);
|
|
|
|
if (pols == NULL) {
|
2017-09-28 21:30:22 +00:00
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2017-09-28 21:30:22 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
ia5org = 0;
|
2017-09-28 21:30:22 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2015-01-22 03:40:55 +00:00
|
|
|
cnf = sk_CONF_VALUE_value(vals, i);
|
2017-09-28 21:30:22 +00:00
|
|
|
|
2015-01-22 03:40:55 +00: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;
|
2015-05-06 18:56:14 +00:00
|
|
|
if (strcmp(pstr, "ia5org") == 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
ia5org = 1;
|
|
|
|
continue;
|
|
|
|
} else if (*pstr == '@') {
|
|
|
|
STACK_OF(CONF_VALUE) *polsect;
|
|
|
|
polsect = X509V3_get_section(ctx, pstr + 1);
|
|
|
|
if (!polsect) {
|
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL, X509V3_R_INVALID_SECTION);
|
|
|
|
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
pol = policy_section(ctx, polsect, ia5org);
|
|
|
|
X509V3_section_free(ctx, polsect);
|
2015-05-06 17:43:59 +00:00
|
|
|
if (pol == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
} else {
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((pobj = OBJ_txt2obj(cnf->name, 0)) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL,
|
|
|
|
X509V3_R_INVALID_OBJECT_IDENTIFIER);
|
|
|
|
X509V3_conf_err(cnf);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
pol = POLICYINFO_new();
|
2015-10-30 11:12:26 +00:00
|
|
|
if (pol == NULL) {
|
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
|
2016-04-27 13:17:33 +00:00
|
|
|
ASN1_OBJECT_free(pobj);
|
2015-10-30 11:12:26 +00:00
|
|
|
goto err;
|
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
pol->policyid = pobj;
|
|
|
|
}
|
|
|
|
if (!sk_POLICYINFO_push(pols, pol)) {
|
|
|
|
POLICYINFO_free(pol);
|
|
|
|
X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
|
|
|
|
return pols;
|
|
|
|
err:
|
|
|
|
sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
|
|
|
|
sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
|
|
|
|
return NULL;
|
1999-04-18 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
1999-06-20 22:18:16 +00:00
|
|
|
static POLICYINFO *policy_section(X509V3_CTX *ctx,
|
2015-01-22 03:40:55 +00:00
|
|
|
STACK_OF(CONF_VALUE) *polstrs, int ia5org)
|
1999-04-18 23:21:03 +00:00
|
|
|
{
|
2015-01-22 03:40:55 +00:00
|
|
|
int i;
|
|
|
|
CONF_VALUE *cnf;
|
|
|
|
POLICYINFO *pol;
|
|
|
|
POLICYQUALINFO *qual;
|
2015-05-06 17:43:59 +00:00
|
|
|
|
|
|
|
if ((pol = POLICYINFO_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto merr;
|
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(polstrs, i);
|
2015-05-06 18:56:14 +00:00
|
|
|
if (strcmp(cnf->name, "policyIdentifier") == 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
ASN1_OBJECT *pobj;
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((pobj = OBJ_txt2obj(cnf->value, 0)) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
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")) {
|
2015-05-06 17:43:59 +00:00
|
|
|
if (pol->qualifiers == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
pol->qualifiers = sk_POLICYQUALINFO_new_null();
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((qual = POLICYQUALINFO_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto merr;
|
|
|
|
if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
|
|
|
|
goto merr;
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((qual->pqualid = OBJ_nid2obj(NID_id_qt_cps)) == NULL) {
|
2015-03-11 20:50:20 +00:00
|
|
|
X509V3err(X509V3_F_POLICY_SECTION, ERR_R_INTERNAL_ERROR);
|
|
|
|
goto err;
|
|
|
|
}
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((qual->d.cpsuri = ASN1_IA5STRING_new()) == NULL)
|
2015-03-11 20:50:20 +00:00
|
|
|
goto merr;
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
|
|
|
|
strlen(cnf->value)))
|
|
|
|
goto merr;
|
|
|
|
} else if (!name_cmp(cnf->name, "userNotice")) {
|
|
|
|
STACK_OF(CONF_VALUE) *unot;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
qual = notice_section(ctx, unot, ia5org);
|
|
|
|
X509V3_section_free(ctx, unot);
|
|
|
|
if (!qual)
|
|
|
|
goto err;
|
|
|
|
if (!pol->qualifiers)
|
|
|
|
pol->qualifiers = sk_POLICYQUALINFO_new_null();
|
|
|
|
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);
|
|
|
|
|
|
|
|
err:
|
|
|
|
POLICYINFO_free(pol);
|
|
|
|
return NULL;
|
1999-04-19 17:55:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 18:43:57 +00:00
|
|
|
static int displaytext_get_tag_len(const char *tagstr)
|
|
|
|
{
|
|
|
|
char *colon = strchr(tagstr, ':');
|
|
|
|
|
|
|
|
return (colon == NULL) ? -1 : colon - tagstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int displaytext_str2tag(const char *tagstr, unsigned int *tag_len)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
*tag_len = 0;
|
|
|
|
len = displaytext_get_tag_len(tagstr);
|
|
|
|
|
|
|
|
if (len == -1)
|
|
|
|
return V_ASN1_VISIBLESTRING;
|
|
|
|
*tag_len = len;
|
|
|
|
if (len == sizeof("UTF8") - 1 && strncmp(tagstr, "UTF8", len) == 0)
|
|
|
|
return V_ASN1_UTF8STRING;
|
|
|
|
if (len == sizeof("UTF8String") - 1 && strncmp(tagstr, "UTF8String", len) == 0)
|
|
|
|
return V_ASN1_UTF8STRING;
|
|
|
|
if (len == sizeof("BMP") - 1 && strncmp(tagstr, "BMP", len) == 0)
|
|
|
|
return V_ASN1_BMPSTRING;
|
|
|
|
if (len == sizeof("BMPSTRING") - 1 && strncmp(tagstr, "BMPSTRING", len) == 0)
|
|
|
|
return V_ASN1_BMPSTRING;
|
|
|
|
if (len == sizeof("VISIBLE") - 1 && strncmp(tagstr, "VISIBLE", len) == 0)
|
|
|
|
return V_ASN1_VISIBLESTRING;
|
|
|
|
if (len == sizeof("VISIBLESTRING") - 1 && strncmp(tagstr, "VISIBLESTRING", len) == 0)
|
|
|
|
return V_ASN1_VISIBLESTRING;
|
|
|
|
*tag_len = 0;
|
|
|
|
return V_ASN1_VISIBLESTRING;
|
|
|
|
}
|
|
|
|
|
1999-06-20 22:18:16 +00:00
|
|
|
static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
|
2015-01-22 03:40:55 +00:00
|
|
|
STACK_OF(CONF_VALUE) *unot, int ia5org)
|
1999-04-19 17:55:11 +00:00
|
|
|
{
|
2016-01-21 18:43:57 +00:00
|
|
|
int i, ret, len, tag;
|
|
|
|
unsigned int tag_len;
|
2015-01-22 03:40:55 +00:00
|
|
|
CONF_VALUE *cnf;
|
|
|
|
USERNOTICE *not;
|
|
|
|
POLICYQUALINFO *qual;
|
2016-01-21 18:43:57 +00:00
|
|
|
char *value = NULL;
|
2015-05-06 17:43:59 +00:00
|
|
|
|
|
|
|
if ((qual = POLICYQUALINFO_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto merr;
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice)) == NULL) {
|
2015-03-11 20:50:20 +00:00
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION, ERR_R_INTERNAL_ERROR);
|
|
|
|
goto err;
|
|
|
|
}
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((not = USERNOTICE_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto merr;
|
|
|
|
qual->d.usernotice = not;
|
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(unot); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(unot, i);
|
2016-01-21 18:43:57 +00:00
|
|
|
value = cnf->value;
|
2015-05-06 18:56:14 +00:00
|
|
|
if (strcmp(cnf->name, "explicitText") == 0) {
|
2016-01-21 18:43:57 +00:00
|
|
|
tag = displaytext_str2tag(value, &tag_len);
|
|
|
|
if ((not->exptext = ASN1_STRING_type_new(tag)) == NULL)
|
2015-03-11 20:50:20 +00:00
|
|
|
goto merr;
|
2016-01-21 18:43:57 +00:00
|
|
|
if (tag_len != 0)
|
|
|
|
value += tag_len + 1;
|
|
|
|
len = strlen(value);
|
|
|
|
if (!ASN1_STRING_set(not->exptext, value, len))
|
2015-01-22 03:40:55 +00:00
|
|
|
goto merr;
|
2015-05-06 18:56:14 +00:00
|
|
|
} else if (strcmp(cnf->name, "organization") == 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
NOTICEREF *nref;
|
|
|
|
if (!not->noticeref) {
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((nref = NOTICEREF_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto merr;
|
|
|
|
not->noticeref = nref;
|
|
|
|
} else
|
|
|
|
nref = not->noticeref;
|
|
|
|
if (ia5org)
|
|
|
|
nref->organization->type = V_ASN1_IA5STRING;
|
|
|
|
else
|
|
|
|
nref->organization->type = V_ASN1_VISIBLESTRING;
|
|
|
|
if (!ASN1_STRING_set(nref->organization, cnf->value,
|
|
|
|
strlen(cnf->value)))
|
|
|
|
goto merr;
|
2015-05-06 18:56:14 +00:00
|
|
|
} else if (strcmp(cnf->name, "noticeNumbers") == 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
NOTICEREF *nref;
|
|
|
|
STACK_OF(CONF_VALUE) *nos;
|
|
|
|
if (!not->noticeref) {
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((nref = NOTICEREF_new()) == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto merr;
|
|
|
|
not->noticeref = nref;
|
|
|
|
} else
|
|
|
|
nref = not->noticeref;
|
|
|
|
nos = X509V3_parse_list(cnf->value);
|
|
|
|
if (!nos || !sk_CONF_VALUE_num(nos)) {
|
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION, X509V3_R_INVALID_NUMBERS);
|
|
|
|
X509V3_conf_err(cnf);
|
2016-04-27 15:41:43 +00:00
|
|
|
sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ret = nref_nos(nref->noticenos, nos);
|
|
|
|
sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
|
|
|
|
if (!ret)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qual;
|
|
|
|
|
|
|
|
merr:
|
|
|
|
X509V3err(X509V3_F_NOTICE_SECTION, ERR_R_MALLOC_FAILURE);
|
|
|
|
|
|
|
|
err:
|
|
|
|
POLICYQUALINFO_free(qual);
|
|
|
|
return NULL;
|
1999-04-19 17:55:11 +00:00
|
|
|
}
|
|
|
|
|
2003-05-28 17:28:11 +00:00
|
|
|
static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
|
1999-04-19 17:55:11 +00:00
|
|
|
{
|
2015-01-22 03:40:55 +00:00
|
|
|
CONF_VALUE *cnf;
|
|
|
|
ASN1_INTEGER *aint;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(nos); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(nos, i);
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((aint = s2i_ASN1_INTEGER(NULL, cnf->name)) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
X509V3err(X509V3_F_NREF_NOS, X509V3_R_INVALID_NUMBER);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (!sk_ASN1_INTEGER_push(nnums, aint))
|
|
|
|
goto merr;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
merr:
|
2017-02-02 12:36:10 +00:00
|
|
|
ASN1_INTEGER_free(aint);
|
2015-01-22 03:40:55 +00:00
|
|
|
X509V3err(X509V3_F_NREF_NOS, ERR_R_MALLOC_FAILURE);
|
|
|
|
|
|
|
|
err:
|
|
|
|
return 0;
|
1999-04-18 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
|
2015-01-22 03:40:55 +00:00
|
|
|
BIO *out, int indent)
|
1999-04-18 23:21:03 +00:00
|
|
|
{
|
2015-01-22 03:40:55 +00: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-18 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
|
2015-01-22 03:40:55 +00:00
|
|
|
int indent)
|
1999-04-18 23:21:03 +00:00
|
|
|
{
|
2015-01-22 03:40:55 +00: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-18 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
1999-04-19 21:31:43 +00:00
|
|
|
static void print_notice(BIO *out, USERNOTICE *notice, int indent)
|
1999-04-18 23:21:03 +00:00
|
|
|
{
|
2015-01-22 03:40:55 +00: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, "",
|
|
|
|
sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
|
|
|
|
for (i = 0; i < sk_ASN1_INTEGER_num(ref->noticenos); i++) {
|
|
|
|
ASN1_INTEGER *num;
|
|
|
|
char *tmp;
|
|
|
|
num = sk_ASN1_INTEGER_value(ref->noticenos, i);
|
|
|
|
if (i)
|
|
|
|
BIO_puts(out, ", ");
|
2017-03-14 14:10:52 +00:00
|
|
|
if (num == NULL)
|
|
|
|
BIO_puts(out, "(null)");
|
|
|
|
else {
|
|
|
|
tmp = i2s_ASN1_INTEGER(NULL, num);
|
|
|
|
if (tmp == NULL)
|
|
|
|
return;
|
|
|
|
BIO_puts(out, tmp);
|
|
|
|
OPENSSL_free(tmp);
|
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
BIO_puts(out, "\n");
|
|
|
|
}
|
|
|
|
if (notice->exptext)
|
|
|
|
BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
|
|
|
|
notice->exptext->data);
|
1999-04-18 23:21:03 +00:00
|
|
|
}
|
|
|
|
|
2004-03-31 12:17:24 +00:00
|
|
|
void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
const X509_POLICY_DATA *dat = node->data;
|
|
|
|
|
|
|
|
BIO_printf(out, "%*sPolicy: ", indent, "");
|
|
|
|
|
|
|
|
i2a_ASN1_OBJECT(out, dat->valid_policy);
|
|
|
|
BIO_puts(out, "\n");
|
|
|
|
BIO_printf(out, "%*s%s\n", indent + 2, "",
|
|
|
|
node_data_critical(dat) ? "Critical" : "Non Critical");
|
|
|
|
if (dat->qualifier_set)
|
|
|
|
print_qualifiers(out, dat->qualifier_set, indent + 2);
|
|
|
|
else
|
|
|
|
BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, "");
|
|
|
|
}
|