Coverage Report

Created: 2025-12-31 06:58

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
2.73k
} ASN1_SEQUENCE_END(OSSL_HASH)
19
2.73k
20
2.73k
ASN1_SEQUENCE(OSSL_INFO_SYNTAX_POINTER) = {
21
2.73k
    ASN1_SIMPLE(OSSL_INFO_SYNTAX_POINTER, name, GENERAL_NAMES),
22
2.73k
    ASN1_OPT(OSSL_INFO_SYNTAX_POINTER, hash, OSSL_HASH),
23
2.73k
} ASN1_SEQUENCE_END(OSSL_INFO_SYNTAX_POINTER)
24
1.47k
25
1.47k
ASN1_CHOICE(OSSL_INFO_SYNTAX) = {
26
1.47k
    ASN1_SIMPLE(OSSL_INFO_SYNTAX, choice.content, DIRECTORYSTRING),
27
1.47k
    ASN1_SIMPLE(OSSL_INFO_SYNTAX, choice.pointer, OSSL_INFO_SYNTAX_POINTER)
28
21.3k
} ASN1_CHOICE_END(OSSL_INFO_SYNTAX)
29
21.3k
30
21.3k
ASN1_SEQUENCE(OSSL_PRIVILEGE_POLICY_ID) = {
31
21.3k
    ASN1_SIMPLE(OSSL_PRIVILEGE_POLICY_ID, privilegePolicy, ASN1_OBJECT),
32
21.3k
    ASN1_SIMPLE(OSSL_PRIVILEGE_POLICY_ID, privPolSyntax, OSSL_INFO_SYNTAX),
33
21.3k
} ASN1_SEQUENCE_END(OSSL_PRIVILEGE_POLICY_ID)
34
10.7k
35
10.7k
ASN1_SEQUENCE(OSSL_ATTRIBUTE_DESCRIPTOR) = {
36
10.7k
    ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, identifier, ASN1_OBJECT),
37
10.7k
    ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, attributeSyntax, ASN1_OCTET_STRING),
38
10.7k
    ASN1_IMP_OPT(OSSL_ATTRIBUTE_DESCRIPTOR, name, ASN1_UTF8STRING, 0),
39
10.7k
    ASN1_IMP_OPT(OSSL_ATTRIBUTE_DESCRIPTOR, description, ASN1_UTF8STRING, 1),
40
10.7k
    ASN1_SIMPLE(OSSL_ATTRIBUTE_DESCRIPTOR, dominationRule, OSSL_PRIVILEGE_POLICY_ID),
41
10.7k
} ASN1_SEQUENCE_END(OSSL_ATTRIBUTE_DESCRIPTOR)
42
6.83k
43
6.83k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_HASH)
44
6.83k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_INFO_SYNTAX)
45
6.83k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_INFO_SYNTAX_POINTER)
46
6.83k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_PRIVILEGE_POLICY_ID)
47
6.83k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTE_DESCRIPTOR)
48
6.83k
49
6.83k
static int i2r_HASH(X509V3_EXT_METHOD *method,
50
6.83k
    OSSL_HASH *hash,
51
6.83k
    BIO *out, int indent)
52
6.83k
{
53
13
    if (BIO_printf(out, "%*sAlgorithm: ", indent, "") <= 0)
54
0
        return 0;
55
13
    if (i2a_ASN1_OBJECT(out, hash->algorithmIdentifier->algorithm) <= 0)
56
0
        return 0;
57
13
    if (BIO_puts(out, "\n") <= 0)
58
0
        return 0;
59
13
    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
13
    if (BIO_printf(out, "%*sHash Value: ", indent, "") <= 0)
70
0
        return 0;
71
13
    if (hash->hashValue == NULL)
72
13
        return 0;
73
0
    return ossl_bio_print_hex(out, hash->hashValue->data, hash->hashValue->length);
74
13
}
75
76
static int i2r_INFO_SYNTAX_POINTER(X509V3_EXT_METHOD *method,
77
    OSSL_INFO_SYNTAX_POINTER *pointer,
78
    BIO *out, int indent)
79
174
{
80
174
    if (BIO_printf(out, "%*sNames:\n", indent, "") <= 0)
81
0
        return 0;
82
174
    if (OSSL_GENERAL_NAMES_print(out, pointer->name, indent) <= 0)
83
0
        return 0;
84
174
    if (BIO_puts(out, "\n") <= 0)
85
0
        return 0;
86
174
    if (pointer->hash != NULL) {
87
13
        if (BIO_printf(out, "%*sHash:\n", indent, "") <= 0)
88
0
            return 0;
89
13
        if (i2r_HASH(method, pointer->hash, out, indent + 4) <= 0)
90
13
            return 0;
91
13
    }
92
161
    return 1;
93
174
}
94
95
static int i2r_OSSL_INFO_SYNTAX(X509V3_EXT_METHOD *method,
96
    OSSL_INFO_SYNTAX *info,
97
    BIO *out, int indent)
98
299
{
99
299
    switch (info->type) {
100
125
    case OSSL_INFO_SYNTAX_TYPE_CONTENT:
101
125
        if (BIO_printf(out, "%*sContent: ", indent, "") <= 0)
102
0
            return 0;
103
125
        if (BIO_printf(out, "%.*s", info->choice.content->length, info->choice.content->data) <= 0)
104
52
            return 0;
105
73
        if (BIO_puts(out, "\n") <= 0)
106
0
            return 0;
107
73
        return 1;
108
174
    case OSSL_INFO_SYNTAX_TYPE_POINTER:
109
174
        if (BIO_printf(out, "%*sPointer:\n", indent, "") <= 0)
110
0
            return 0;
111
174
        return i2r_INFO_SYNTAX_POINTER(method, info->choice.pointer, out, indent + 4);
112
0
    default:
113
0
        return 0;
114
299
    }
115
0
    return 0;
116
299
}
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
299
{
122
299
    char buf[80];
123
124
    /* Intentionally display the numeric OID, rather than the textual name. */
125
299
    if (OBJ_obj2txt(buf, sizeof(buf), ppid->privilegePolicy, 1) <= 0)
126
0
        return 0;
127
299
    if (BIO_printf(out, "%*sPrivilege Policy Identifier: %s\n", indent, "", buf) <= 0)
128
0
        return 0;
129
299
    if (BIO_printf(out, "%*sPrivilege Policy Syntax:\n", indent, "") <= 0)
130
0
        return 0;
131
299
    return i2r_OSSL_INFO_SYNTAX(method, ppid->privPolSyntax, out, indent + 4);
132
299
}
133
134
static int i2r_OSSL_ATTRIBUTE_DESCRIPTOR(X509V3_EXT_METHOD *method,
135
    OSSL_ATTRIBUTE_DESCRIPTOR *ad,
136
    BIO *out, int indent)
137
299
{
138
299
    char buf[80];
139
140
    /* Intentionally display the numeric OID, rather than the textual name. */
141
299
    if (OBJ_obj2txt(buf, sizeof(buf), ad->identifier, 1) <= 0)
142
0
        return 0;
143
299
    if (BIO_printf(out, "%*sIdentifier: %s\n", indent, "", buf) <= 0)
144
0
        return 0;
145
299
    if (BIO_printf(out, "%*sSyntax:\n", indent, "") <= 0)
146
0
        return 0;
147
299
    if (BIO_printf(out, "%*s%.*s", indent + 4, "",
148
299
            ad->attributeSyntax->length, ad->attributeSyntax->data)
149
299
        <= 0)
150
0
        return 0;
151
299
    if (BIO_puts(out, "\n\n") <= 0)
152
0
        return 0;
153
299
    if (ad->name != NULL) {
154
52
        if (BIO_printf(out, "%*sName: %.*s\n", indent, "", ad->name->length, ad->name->data) <= 0)
155
0
            return 0;
156
52
    }
157
299
    if (ad->description != NULL) {
158
36
        if (BIO_printf(out, "%*sDescription: %.*s\n", indent, "",
159
36
                ad->description->length, ad->description->data)
160
36
            <= 0)
161
0
            return 0;
162
36
    }
163
299
    if (BIO_printf(out, "%*sDomination Rule:\n", indent, "") <= 0)
164
0
        return 0;
165
299
    return i2r_OSSL_PRIVILEGE_POLICY_ID(method, ad->dominationRule, out, indent + 4);
166
299
}
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
};