Coverage Report

Created: 2025-06-13 06:57

/src/openssl/crypto/x509/v3_sda.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2024 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_ITEM_TEMPLATE(OSSL_ATTRIBUTES_SYNTAX) =
16
        ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Attributes, X509_ATTRIBUTE)
17
ASN1_ITEM_TEMPLATE_END(OSSL_ATTRIBUTES_SYNTAX)
18
19
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ATTRIBUTES_SYNTAX)
20
21
static int i2r_ATTRIBUTES_SYNTAX(X509V3_EXT_METHOD *method,
22
                                 OSSL_ATTRIBUTES_SYNTAX *attrlst,
23
                                 BIO *out, int indent)
24
0
{
25
0
    X509_ATTRIBUTE *attr;
26
0
    ASN1_TYPE *av;
27
0
    int i, j, attr_nid;
28
29
0
    if (!attrlst) {
30
0
        if (BIO_printf(out, "<No Attributes>\n") <= 0)
31
0
            return 0;
32
0
        return 1;
33
0
    }
34
0
    if (!sk_X509_ATTRIBUTE_num(attrlst)) {
35
0
        if (BIO_printf(out, "<Empty Attributes>\n") <= 0)
36
0
            return 0;
37
0
        return 1;
38
0
    }
39
40
0
    for (i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {
41
0
        ASN1_OBJECT *attr_obj;
42
0
        attr = sk_X509_ATTRIBUTE_value(attrlst, i);
43
0
        attr_obj = X509_ATTRIBUTE_get0_object(attr);
44
0
        attr_nid = OBJ_obj2nid(attr_obj);
45
0
        if (indent && BIO_printf(out, "%*s", indent, "") <= 0)
46
0
            return 0;
47
0
        if (attr_nid == NID_undef) {
48
0
            if (i2a_ASN1_OBJECT(out, attr_obj) <= 0)
49
0
                return 0;
50
0
            if (BIO_puts(out, ":\n") <= 0)
51
0
                return 0;
52
0
        } else if (BIO_printf(out, "%s:\n", OBJ_nid2ln(attr_nid)) <= 0) {
53
0
            return 0;
54
0
        }
55
56
0
        if (X509_ATTRIBUTE_count(attr)) {
57
0
            for (j = 0; j < X509_ATTRIBUTE_count(attr); j++)
58
0
            {
59
0
                av = X509_ATTRIBUTE_get0_type(attr, j);
60
0
                if (ossl_print_attribute_value(out, attr_nid, av, indent + 4) <= 0)
61
0
                    return 0;
62
0
                if (BIO_puts(out, "\n") <= 0)
63
0
                    return 0;
64
0
            }
65
0
        } else if (BIO_printf(out, "%*s<No Values>\n", indent + 4, "") <= 0) {
66
0
            return 0;
67
0
        }
68
0
    }
69
0
    return 1;
70
0
}
71
72
const X509V3_EXT_METHOD ossl_v3_subj_dir_attrs = {
73
    NID_subject_directory_attributes, X509V3_EXT_MULTILINE,
74
    ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX),
75
    0, 0, 0, 0,
76
    0, 0, 0, 0,
77
    (X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX,
78
    0,
79
    NULL
80
};
81
82
const X509V3_EXT_METHOD ossl_v3_associated_info = {
83
    NID_associated_information, X509V3_EXT_MULTILINE,
84
    ASN1_ITEM_ref(OSSL_ATTRIBUTES_SYNTAX),
85
    0, 0, 0, 0,
86
    0, 0, 0, 0,
87
    (X509V3_EXT_I2R)i2r_ATTRIBUTES_SYNTAX,
88
    0,
89
    NULL
90
};