Coverage Report

Created: 2025-06-13 06:58

/src/openssl/crypto/x509/v3_rolespec.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_SEQUENCE(OSSL_ROLE_SPEC_CERT_ID) = {
16
    ASN1_EXP(OSSL_ROLE_SPEC_CERT_ID, roleName, GENERAL_NAME, 0),
17
    ASN1_EXP(OSSL_ROLE_SPEC_CERT_ID, roleCertIssuer, GENERAL_NAME, 1),
18
    ASN1_IMP_OPT(OSSL_ROLE_SPEC_CERT_ID, roleCertSerialNumber, ASN1_INTEGER, 2),
19
    ASN1_IMP_SEQUENCE_OF_OPT(OSSL_ROLE_SPEC_CERT_ID, roleCertLocator, GENERAL_NAME, 3),
20
} ASN1_SEQUENCE_END(OSSL_ROLE_SPEC_CERT_ID)
21
22
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID)
23
24
ASN1_ITEM_TEMPLATE(OSSL_ROLE_SPEC_CERT_ID_SYNTAX) =
25
    ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF,
26
                          0, OSSL_ROLE_SPEC_CERT_ID_SYNTAX, OSSL_ROLE_SPEC_CERT_ID)
27
ASN1_ITEM_TEMPLATE_END(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
28
29
IMPLEMENT_ASN1_FUNCTIONS(OSSL_ROLE_SPEC_CERT_ID_SYNTAX)
30
31
static int i2r_OSSL_ROLE_SPEC_CERT_ID(X509V3_EXT_METHOD *method,
32
                                      OSSL_ROLE_SPEC_CERT_ID *rscid,
33
                                      BIO *out, int indent)
34
1
{
35
1
    if (BIO_printf(out, "%*sRole Name: ", indent, "") <= 0)
36
0
        return 0;
37
1
    if (GENERAL_NAME_print(out, rscid->roleName) <= 0)
38
0
        return 0;
39
1
    if (BIO_puts(out, "\n") <= 0)
40
0
        return 0;
41
1
    if (BIO_printf(out, "%*sRole Certificate Issuer: ", indent, "") <= 0)
42
0
        return 0;
43
1
    if (GENERAL_NAME_print(out, rscid->roleCertIssuer) <= 0)
44
0
        return 0;
45
1
    if (rscid->roleCertSerialNumber != NULL) {
46
0
        if (BIO_puts(out, "\n") <= 0)
47
0
            return 0;
48
0
        if (BIO_printf(out, "%*sRole Certificate Serial Number:", indent, "") <= 0)
49
0
            return 0;
50
0
        if (ossl_serial_number_print(out, rscid->roleCertSerialNumber, indent) != 0)
51
0
            return 0;
52
0
    }
53
1
    if (rscid->roleCertLocator != NULL) {
54
0
        if (BIO_puts(out, "\n") <= 0)
55
0
            return 0;
56
0
        if (BIO_printf(out, "%*sRole Certificate Locator:\n", indent, "") <= 0)
57
0
            return 0;
58
0
        if (OSSL_GENERAL_NAMES_print(out, rscid->roleCertLocator, indent) <= 0)
59
0
            return 0;
60
0
    }
61
1
    return BIO_puts(out, "\n");
62
1
}
63
64
static int i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX(X509V3_EXT_METHOD *method,
65
                                             OSSL_ROLE_SPEC_CERT_ID_SYNTAX *rscids,
66
                                             BIO *out, int indent)
67
743
{
68
743
    OSSL_ROLE_SPEC_CERT_ID *rscid;
69
743
    int i;
70
71
744
    for (i = 0; i < sk_OSSL_ROLE_SPEC_CERT_ID_num(rscids); i++) {
72
1
        if (i > 0 && BIO_puts(out, "\n") <= 0)
73
0
            return 0;
74
1
        if (BIO_printf(out,
75
1
                       "%*sRole Specification Certificate Identifier #%d:\n",
76
1
                       indent, "", i + 1) <= 0)
77
0
            return 0;
78
1
        rscid = sk_OSSL_ROLE_SPEC_CERT_ID_value(rscids, i);
79
1
        if (i2r_OSSL_ROLE_SPEC_CERT_ID(method, rscid, out, indent + 4) != 1)
80
0
            return 0;
81
1
    }
82
743
    return 1;
83
743
}
84
85
const X509V3_EXT_METHOD ossl_v3_role_spec_cert_identifier = {
86
    NID_role_spec_cert_identifier, X509V3_EXT_MULTILINE,
87
    ASN1_ITEM_ref(OSSL_ROLE_SPEC_CERT_ID_SYNTAX),
88
    0, 0, 0, 0,
89
    0, 0,
90
    0,
91
    0,
92
    (X509V3_EXT_I2R)i2r_OSSL_ROLE_SPEC_CERT_ID_SYNTAX,
93
    NULL,
94
    NULL
95
};