Coverage Report

Created: 2026-10-28 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/crypto/x509/v3_pcons.c
Line
Count
Source
1
/*
2
 * Copyright 2003-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <stdio.h>
11
#include "internal/cryptlib.h"
12
#include <openssl/asn1.h>
13
#include <openssl/asn1t.h>
14
#include <openssl/conf.h>
15
#include <openssl/x509v3.h>
16
#include "ext_dat.h"
17
18
static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD
19
                                                        *method,
20
    void *bcons, STACK_OF(CONF_VALUE) *extlist);
21
static void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method,
22
    X509V3_CTX *ctx,
23
    STACK_OF(CONF_VALUE) *values);
24
25
const X509V3_EXT_METHOD ossl_v3_policy_constraints = {
26
    NID_policy_constraints, 0,
27
    ASN1_ITEM_ref(POLICY_CONSTRAINTS),
28
    0, 0, 0, 0,
29
    0, 0,
30
    i2v_POLICY_CONSTRAINTS,
31
    v2i_POLICY_CONSTRAINTS,
32
    NULL, NULL,
33
    NULL
34
};
35
36
ASN1_SEQUENCE(POLICY_CONSTRAINTS) = {
37
    ASN1_IMP_OPT(POLICY_CONSTRAINTS, requireExplicitPolicy, ASN1_INTEGER, 0),
38
    ASN1_IMP_OPT(POLICY_CONSTRAINTS, inhibitPolicyMapping, ASN1_INTEGER, 1)
39
87.7k
} ASN1_SEQUENCE_END(POLICY_CONSTRAINTS)
40
87.7k
41
87.7k
IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS)
42
87.7k
43
87.7k
static STACK_OF(CONF_VALUE) *i2v_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD
44
87.7k
                                                        *method,
45
87.7k
    void *a, STACK_OF(CONF_VALUE) *extlist)
46
87.7k
{
47
7.81k
    POLICY_CONSTRAINTS *pcons = a;
48
7.81k
    X509V3_add_value_int("Require Explicit Policy",
49
7.81k
        pcons->requireExplicitPolicy, &extlist);
50
7.81k
    X509V3_add_value_int("Inhibit Policy Mapping",
51
7.81k
        pcons->inhibitPolicyMapping, &extlist);
52
7.81k
    return extlist;
53
7.81k
}
54
55
static void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method,
56
    X509V3_CTX *ctx,
57
    STACK_OF(CONF_VALUE) *values)
58
674
{
59
674
    POLICY_CONSTRAINTS *pcons = NULL;
60
674
    CONF_VALUE *val;
61
674
    int i;
62
63
674
    if ((pcons = POLICY_CONSTRAINTS_new()) == NULL) {
64
0
        ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
65
0
        return NULL;
66
0
    }
67
722
    for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
68
710
        val = sk_CONF_VALUE_value(values, i);
69
710
        if (strcmp(val->name, "requireExplicitPolicy") == 0) {
70
45
            if (pcons->requireExplicitPolicy != NULL) {
71
6
                ERR_raise_data(ERR_LIB_X509V3, X509V3_R_DUPLICATE_FIELD,
72
6
                    "field=%s", val->name);
73
6
                goto err;
74
6
            }
75
39
            if (!X509V3_get_value_int(val, &pcons->requireExplicitPolicy))
76
6
                goto err;
77
665
        } else if (strcmp(val->name, "inhibitPolicyMapping") == 0) {
78
27
            if (pcons->inhibitPolicyMapping != NULL) {
79
6
                ERR_raise_data(ERR_LIB_X509V3, X509V3_R_DUPLICATE_FIELD,
80
6
                    "field=%s", val->name);
81
6
                goto err;
82
6
            }
83
21
            if (!X509V3_get_value_int(val, &pcons->inhibitPolicyMapping))
84
6
                goto err;
85
638
        } else {
86
638
            ERR_raise_data(ERR_LIB_X509V3, X509V3_R_INVALID_NAME,
87
638
                "%s", val->name);
88
638
            goto err;
89
638
        }
90
710
    }
91
12
    if (pcons->inhibitPolicyMapping == NULL
92
6
        && pcons->requireExplicitPolicy == NULL) {
93
0
        ERR_raise(ERR_LIB_X509V3, X509V3_R_ILLEGAL_EMPTY_EXTENSION);
94
0
        goto err;
95
0
    }
96
97
12
    return pcons;
98
662
err:
99
662
    POLICY_CONSTRAINTS_free(pcons);
100
    return NULL;
101
12
}