Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/crypto/x509/v3_attrdesc.c
Line
Count
Source
1
/*
2
 * Copyright 2024-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 <openssl/asn1t.h>
11
#include <openssl/x509v3.h>
12
#include <crypto/x509.h>
13
#include "ext_dat.h"
14
15
ASN1_SEQUENCE(OSSL_HASH) = {
16
    ASN1_SIMPLE(OSSL_HASH, algorithmIdentifier, X509_ALGOR),
17
    ASN1_OPT(OSSL_HASH, hashValue, ASN1_BIT_STRING),
18
10.5k
} ASN1_SEQUENCE_END(OSSL_HASH)
19
10.5k
20
10.5k
ASN1_SEQUENCE(OSSL_INFO_SYNTAX_POINTER) = {
21
10.5k
    ASN1_SIMPLE(OSSL_INFO_SYNTAX_POINTER, name, GENERAL_NAMES),
22
10.5k
    ASN1_OPT(OSSL_INFO_SYNTAX_POINTER, hash, OSSL_HASH),
23
10.5k
} ASN1_SEQUENCE_END(OSSL_INFO_SYNTAX_POINTER)
24
6.82k
25
6.82k
ASN1_CHOICE(OSSL_INFO_SYNTAX) = {
26
6.82k
    ASN1_SIMPLE(OSSL_INFO_SYNTAX, choice.content, DIRECTORYSTRING),
27
6.82k
    ASN1_SIMPLE(OSSL_INFO_SYNTAX, choice.pointer, OSSL_INFO_SYNTAX_POINTER)
28
53.5k
} ASN1_CHOICE_END(OSSL_INFO_SYNTAX)
29
53.5k
30
53.5k
ASN1_SEQUENCE(OSSL_PRIVILEGE_POLICY_ID) = {
31
53.5k
    ASN1_SIMPLE(OSSL_PRIVILEGE_POLICY_ID, privilegePolicy, ASN1_OBJECT),
32
53.5k
    ASN1_SIMPLE(OSSL_PRIVILEGE_POLICY_ID, privPolSyntax, OSSL_INFO_SYNTAX),
33
53.5k
} ASN1_SEQUENCE_END(OSSL_PRIVILEGE_POLICY_ID)
34
27.1k
35
27.1k
ASN1_SEQUENCE(OSSL_ATTRIBUTE_DESCRIPTOR) = {
36
27.1k
    ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, identifier, ASN1_OBJECT),
37
27.1k
    ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, attributeSyntax, ASN1_OCTET_STRING),
38
27.1k
    ASN1_IMP_OPT(OSSL_ATTRIBUTE_DESCRIPTOR, name, ASN1_UTF8STRING, 0),
39
27.1k
    ASN1_IMP_OPT(OSSL_ATTRIBUTE_DESCRIPTOR, description, ASN1_UTF8STRING, 1),
40
27.1k
    ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, dominationRule, OSSL_PRIVILEGE_POLICY_ID),
41
27.1k
} ASN1_SEQUENCE_END(OSSL_ATTRIBUTE_DESCRIPTOR)
42
14.5k
43
14.5k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_HASH)
44
14.5k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_INFO_SYNTAX)
45
14.5k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_INFO_SYNTAX_POINTER)
46
14.5k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_PRIVILEGE_POLICY_ID)
47
14.5k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_DESCRIPTOR)
48
14.5k
49
14.5k
static int i2r_HASH(X509V3_EXT_METHOD *method,
50
14.5k
    OSSL_HASH *hash,
51
14.5k
    BIO *out, int indent)
52
14.5k
{
53
200
    if (BIO_printf(out, "%*sAlgorithm: ", indent, "") <= 0)
54
0
        return 0;
55
200
    if (i2a_ASN1_OBJECT(out, hash->algorithmIdentifier->algorithm) <= 0)
56
0
        return 0;
57
200
    if (BIO_puts(out, "\n") <= 0)
58
0
        return 0;
59
200
    if (hash->algorithmIdentifier->parameter) {
60
11
        if (BIO_printf(out, "%*sParameter: ", indent, "") <= 0)
61
0
            return 0;
62
11
        if (ossl_print_attribute_value(out, 0, hash->algorithmIdentifier->parameter,
63
11
                indent + 4)
64
11
            <= 0)
65
0
            return 0;
66
11
        if (BIO_puts(out, "\n") <= 0)
67
0
            return 0;
68
11
    }
69
200
    if (BIO_printf(out, "%*sHash Value: ", indent, "") <= 0)
70
0
        return 0;
71
200
    if (hash->hashValue == NULL)
72
200
        return 0;
73
0
    return ossl_bio_print_hex(out, hash->hashValue->data, hash->hashValue->length);
74
200
}
75
76
static int i2r_INFO_SYNTAX_POINTER(X509V3_EXT_METHOD *method,
77
    OSSL_INFO_SYNTAX_POINTER *pointer,
78
    BIO *out, int indent)
79
1.23k
{
80
1.23k
    if (BIO_printf(out, "%*sNames:\n", indent, "") <= 0)
81
0
        return 0;
82
1.23k
    if (OSSL_GENERAL_NAMES_print(out, pointer->name, indent) <= 0)
83
0
        return 0;
84
1.23k
    if (BIO_puts(out, "\n") <= 0)
85
0
        return 0;
86
1.23k
    if (pointer->hash != NULL) {
87
200
        if (BIO_printf(out, "%*sHash:\n", indent, "") <= 0)
88
0
            return 0;
89
200
        if (i2r_HASH(method, pointer->hash, out, indent + 4) <= 0)
90
200
            return 0;
91
200
    }
92
1.03k
    return 1;
93
1.23k
}
94
95
static int i2r_OSSL_INFO_SYNTAX(X509V3_EXT_METHOD *method,
96
    OSSL_INFO_SYNTAX *info,
97
    BIO *out, int indent)
98
1.94k
{
99
1.94k
    switch (info->type) {
100
1.01k
    case OSSL_INFO_SYNTAX_TYPE_CONTENT:
101
1.01k
        if (BIO_printf(out, "%*sContent: ", indent, "") <= 0)
102
0
            return 0;
103
1.01k
        if (BIO_printf(out, "%.*s", info->choice.content->length,
104
1.01k
                info->choice.content->length
105
1.01k
                    ? info->choice.content->data
106
1.01k
                    : (const unsigned char *)"")
107
1.01k
            <= 0)
108
312
            return 0;
109
700
        if (BIO_puts(out, "\n") <= 0)
110
0
            return 0;
111
700
        return 1;
112
931
    case OSSL_INFO_SYNTAX_TYPE_POINTER:
113
931
        if (BIO_printf(out, "%*sPointer:\n", indent, "") <= 0)
114
0
            return 0;
115
931
        return i2r_INFO_SYNTAX_POINTER(method, info->choice.pointer, out, indent + 4);
116
0
    default:
117
0
        return 0;
118
1.94k
    }
119
0
    return 0;
120
1.94k
}
121
122
static int i2r_OSSL_PRIVILEGE_POLICY_ID(X509V3_EXT_METHOD *method,
123
    OSSL_PRIVILEGE_POLICY_ID *ppid,
124
    BIO *out, int indent)
125
2.28k
{
126
2.28k
    char buf[80];
127
128
    /* Intentionally display the numeric OID, rather than the textual name. */
129
2.28k
    if (OBJ_obj2txt(buf, sizeof(buf), ppid->privilegePolicy, 1) <= 0)
130
0
        return 0;
131
2.28k
    if (BIO_printf(out, "%*sPrivilege Policy Identifier: %s\n", indent, "", buf) <= 0)
132
0
        return 0;
133
2.28k
    if (BIO_printf(out, "%*sPrivilege Policy Syntax:\n", indent, "") <= 0)
134
0
        return 0;
135
2.28k
    return i2r_OSSL_INFO_SYNTAX(method, ppid->privPolSyntax, out, indent + 4);
136
2.28k
}
137
138
static int i2r_OSSL_ATTRIBUTE_DESCRIPTOR(X509V3_EXT_METHOD *method,
139
    OSSL_ATTRIBUTE_DESCRIPTOR *ad,
140
    BIO *out, int indent)
141
1.94k
{
142
1.94k
    char buf[80];
143
144
    /* Intentionally display the numeric OID, rather than the textual name. */
145
1.94k
    if (OBJ_obj2txt(buf, sizeof(buf), ad->identifier, 1) <= 0)
146
0
        return 0;
147
1.94k
    if (BIO_printf(out, "%*sIdentifier: %s\n", indent, "", buf) <= 0)
148
0
        return 0;
149
1.94k
    if (BIO_printf(out, "%*sSyntax:\n", indent, "") <= 0)
150
0
        return 0;
151
1.94k
    if (BIO_printf(out, "%*s%.*s", indent + 4, "",
152
1.94k
            ad->attributeSyntax->length,
153
1.94k
            ad->attributeSyntax->length
154
1.94k
                ? ad->attributeSyntax->data
155
1.94k
                : (const unsigned char *)"")
156
1.94k
        <= 0)
157
0
        return 0;
158
1.94k
    if (BIO_puts(out, "\n\n") <= 0)
159
0
        return 0;
160
1.94k
    if (ad->name != NULL) {
161
184
        if (BIO_printf(out, "%*sName: %.*s\n", indent, "", ad->name->length,
162
184
                ad->name->length
163
184
                    ? ad->name->data
164
184
                    : (const unsigned char *)"")
165
184
            <= 0)
166
0
            return 0;
167
184
    }
168
1.94k
    if (ad->description != NULL) {
169
137
        if (BIO_printf(out, "%*sDescription: %.*s\n", indent, "",
170
137
                ad->description->length,
171
137
                ad->description->length
172
137
                    ? ad->description->data
173
137
                    : (const unsigned char *)"")
174
137
            <= 0)
175
0
            return 0;
176
137
    }
177
1.94k
    if (BIO_printf(out, "%*sDomination Rule:\n", indent, "") <= 0)
178
0
        return 0;
179
1.94k
    return i2r_OSSL_PRIVILEGE_POLICY_ID(method, ad->dominationRule, out, indent + 4);
180
1.94k
}
181
182
const X509V3_EXT_METHOD ossl_v3_attribute_descriptor = {
183
    NID_attribute_descriptor, X509V3_EXT_MULTILINE,
184
    ASN1_ITEM_ref(OSSL_ATTRIBUTE_DESCRIPTOR),
185
    0, 0, 0, 0,
186
    0, 0,
187
    0,
188
    0,
189
    (X509V3_EXT_I2R)i2r_OSSL_ATTRIBUTE_DESCRIPTOR,
190
    NULL,
191
    NULL
192
};