Coverage Report

Created: 2026-04-01 06:39

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