| 1 |
// Written by Dr Stephen N Henson ([email protected]) for the OpenSSL project. |
| 2 |
// Copyright (c) 2003 The OpenSSL Project. All rights reserved. |
| 3 |
// SPDX-License-Identifier: Apache-2.0 |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
#include <openssl/asn1.h> |
| 9 |
#include <openssl/asn1t.h> |
| 10 |
#include <openssl/conf.h> |
| 11 |
#include <openssl/err.h> |
| 12 |
#include <openssl/obj.h> |
| 13 |
#include <openssl/x509.h> |
| 14 |
|
| 15 |
#include "internal.h" |
| 16 |
|
| 17 |
|
| 18 |
static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS( |
| 19 |
const X509V3_EXT_METHOD *method, void *bcons, |
| 20 |
STACK_OF(CONF_VALUE) *extlist); |
| 21 |
static void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, |
| 22 |
const X509V3_CTX *ctx, |
| 23 |
const STACK_OF(CONF_VALUE) *values); |
| 24 |
|
| 25 |
const X509V3_EXT_METHOD v3_policy_constraints = { |
| 26 |
NID_policy_constraints, |
| 27 |
0, |
| 28 |
ASN1_ITEM_ref(POLICY_CONSTRAINTS), |
| 29 |
0, |
| 30 |
0, |
| 31 |
0, |
| 32 |
0, |
| 33 |
0, |
| 34 |
0, |
| 35 |
i2v_POLICY_CONSTRAINTS, |
| 36 |
v2i_POLICY_CONSTRAINTS, |
| 37 |
NULL, |
| 38 |
NULL, |
| 39 |
NULL}; |
| 40 |
|
| 41 |
ASN1_SEQUENCE(POLICY_CONSTRAINTS) = { |
| 42 |
ASN1_IMP_OPT(POLICY_CONSTRAINTS, requireExplicitPolicy, ASN1_INTEGER, 0), |
| 43 |
ASN1_IMP_OPT(POLICY_CONSTRAINTS, inhibitPolicyMapping, ASN1_INTEGER, 1), |
| 44 |
} ASN1_SEQUENCE_END(POLICY_CONSTRAINTS) |
| 45 |
|
| 46 |
IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) |
| 47 |
|
| 48 |
static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS( |
| 49 |
const X509V3_EXT_METHOD *method, void *a, STACK_OF(CONF_VALUE) *extlist) { |
| 50 |
const POLICY_CONSTRAINTS *pcons = a; |
| 51 |
X509V3_add_value_int("Require Explicit Policy", pcons->requireExplicitPolicy, |
| 52 |
&extlist); |
| 53 |
X509V3_add_value_int("Inhibit Policy Mapping", pcons->inhibitPolicyMapping, |
| 54 |
&extlist); |
| 55 |
return extlist; |
| 56 |
} |
| 57 |
|
| 58 |
static void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, |
| 59 |
const X509V3_CTX *ctx, |
| 60 |
const STACK_OF(CONF_VALUE) *values) { |
| 61 |
POLICY_CONSTRAINTS *pcons = NULL; |
| 62 |
if (!(pcons = POLICY_CONSTRAINTS_new())) { |
| 63 |
return NULL; |
| 64 |
} |
| 65 |
for (size_t i = 0; i < sk_CONF_VALUE_num(values); i++) { |
| 66 |
const CONF_VALUE *val = sk_CONF_VALUE_value(values, i); |
| 67 |
if (!strcmp(val->name, "requireExplicitPolicy")) { |
| 68 |
if (!X509V3_get_value_int(val, &pcons->requireExplicitPolicy)) { |
| 69 |
goto err; |
| 70 |
} |
| 71 |
} else if (!strcmp(val->name, "inhibitPolicyMapping")) { |
| 72 |
if (!X509V3_get_value_int(val, &pcons->inhibitPolicyMapping)) { |
| 73 |
goto err; |
| 74 |
} |
| 75 |
} else { |
| 76 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NAME); |
| 77 |
X509V3_conf_err(val); |
| 78 |
goto err; |
| 79 |
} |
| 80 |
} |
| 81 |
if (!pcons->inhibitPolicyMapping && !pcons->requireExplicitPolicy) { |
| 82 |
OPENSSL_PUT_ERROR(X509V3, X509V3_R_ILLEGAL_EMPTY_EXTENSION); |
| 83 |
goto err; |
| 84 |
} |
| 85 |
|
| 86 |
return pcons; |
| 87 |
err: |
| 88 |
POLICY_CONSTRAINTS_free(pcons); |
| 89 |
return NULL; |
| 90 |
} |