Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl40/crypto/x509/v3_ist.c
Line
Count
Source
1
/*
2
 * Copyright 2020-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 <stdio.h>
11
#include "internal/cryptlib.h"
12
#include <openssl/conf.h>
13
#include <openssl/asn1.h>
14
#include <openssl/asn1t.h>
15
#include <openssl/x509v3.h>
16
#include "ext_dat.h"
17
18
#include <crypto/asn1.h>
19
20
/*
21
 * Issuer Sign Tool (1.2.643.100.112) The name of the tool used to signs the subject (ASN1_SEQUENCE)
22
 * This extension is required to obtain the status of a qualified certificate at Russian Federation.
23
 * RFC-style description is available here: https://tools.ietf.org/html/draft-deremin-rfc4491-bis-04#section-5
24
 * Russian Federal Law 63 "Digital Sign" is available here:  http://www.consultant.ru/document/cons_doc_LAW_112701/
25
 */
26
27
ASN1_SEQUENCE(ISSUER_SIGN_TOOL) = {
28
    ASN1_SIMPLE(ISSUER_SIGN_TOOL, signTool, ASN1_UTF8STRING),
29
    ASN1_SIMPLE(ISSUER_SIGN_TOOL, cATool, ASN1_UTF8STRING),
30
    ASN1_SIMPLE(ISSUER_SIGN_TOOL, signToolCert, ASN1_UTF8STRING),
31
    ASN1_SIMPLE(ISSUER_SIGN_TOOL, cAToolCert, ASN1_UTF8STRING)
32
3.44k
} ASN1_SEQUENCE_END(ISSUER_SIGN_TOOL)
33
3.44k
34
3.44k
IMPLEMENT_ASN1_FUNCTIONS(ISSUER_SIGN_TOOL)
35
3.44k
36
3.44k
static ISSUER_SIGN_TOOL *v2i_issuer_sign_tool(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
37
3.44k
    STACK_OF(CONF_VALUE) *nval)
38
3.44k
{
39
277
    ISSUER_SIGN_TOOL *ist = ISSUER_SIGN_TOOL_new();
40
277
    int i;
41
42
277
    if (ist == NULL) {
43
0
        ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
44
0
        return NULL;
45
0
    }
46
840
    for (i = 0; i < sk_CONF_VALUE_num(nval); ++i) {
47
822
        CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i);
48
49
822
        if (cnf == NULL) {
50
0
            continue;
51
0
        }
52
822
        if (strcmp(cnf->name, "signTool") == 0) {
53
6
            if (ist->signTool == NULL
54
6
                || cnf->value == NULL
55
4
                || !ASN1_STRING_set(ist->signTool, cnf->value, (int)strlen(cnf->value))) {
56
2
                ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
57
2
                goto err;
58
2
            }
59
816
        } else if (strcmp(cnf->name, "cATool") == 0) {
60
560
            if (ist->cATool == NULL
61
560
                || cnf->value == NULL
62
557
                || !ASN1_STRING_set(ist->cATool, cnf->value, (int)strlen(cnf->value))) {
63
3
                ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
64
3
                goto err;
65
3
            }
66
560
        } else if (strcmp(cnf->name, "signToolCert") == 0) {
67
4
            if (ist->signToolCert == NULL
68
4
                || cnf->value == NULL
69
2
                || !ASN1_STRING_set(ist->signToolCert, cnf->value, (int)strlen(cnf->value))) {
70
2
                ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
71
2
                goto err;
72
2
            }
73
252
        } else if (strcmp(cnf->name, "cAToolCert") == 0) {
74
0
            if (ist->cAToolCert == NULL
75
0
                || cnf->value == NULL
76
0
                || !ASN1_STRING_set(ist->cAToolCert, cnf->value, (int)strlen(cnf->value))) {
77
0
                ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
78
0
                goto err;
79
0
            }
80
252
        } else {
81
252
            ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_INVALID_ARGUMENT);
82
252
            goto err;
83
252
        }
84
822
    }
85
18
    return ist;
86
87
259
err:
88
259
    ISSUER_SIGN_TOOL_free(ist);
89
259
    return NULL;
90
277
}
91
92
static int i2r_issuer_sign_tool(X509V3_EXT_METHOD *method,
93
    ISSUER_SIGN_TOOL *ist, BIO *out,
94
    int indent)
95
1.23k
{
96
1.23k
    int new_line = 0;
97
98
1.23k
    if (ist == NULL) {
99
0
        ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_INVALID_ARGUMENT);
100
0
        return 0;
101
0
    }
102
1.23k
    if (ist->signTool != NULL) {
103
1.23k
        BIO_printf(out, "%*ssignTool    : ", indent, "");
104
1.23k
        BIO_write(out, ist->signTool->data, ist->signTool->length);
105
1.23k
        new_line = 1;
106
1.23k
    }
107
1.23k
    if (ist->cATool != NULL) {
108
1.23k
        if (new_line == 1) {
109
1.23k
            BIO_write(out, "\n", 1);
110
1.23k
        }
111
1.23k
        BIO_printf(out, "%*scATool      : ", indent, "");
112
1.23k
        BIO_write(out, ist->cATool->data, ist->cATool->length);
113
1.23k
        new_line = 1;
114
1.23k
    }
115
1.23k
    if (ist->signToolCert != NULL) {
116
1.23k
        if (new_line == 1) {
117
1.23k
            BIO_write(out, "\n", 1);
118
1.23k
        }
119
1.23k
        BIO_printf(out, "%*ssignToolCert: ", indent, "");
120
1.23k
        BIO_write(out, ist->signToolCert->data, ist->signToolCert->length);
121
1.23k
        new_line = 1;
122
1.23k
    }
123
1.23k
    if (ist->cAToolCert != NULL) {
124
1.23k
        if (new_line == 1) {
125
1.23k
            BIO_write(out, "\n", 1);
126
1.23k
        }
127
1.23k
        BIO_printf(out, "%*scAToolCert  : ", indent, "");
128
1.23k
        BIO_write(out, ist->cAToolCert->data, ist->cAToolCert->length);
129
1.23k
        new_line = 1;
130
1.23k
    }
131
1.23k
    return 1;
132
1.23k
}
133
134
const X509V3_EXT_METHOD ossl_v3_issuer_sign_tool = {
135
    NID_issuerSignTool, /* nid */
136
    X509V3_EXT_MULTILINE, /* flags */
137
    ASN1_ITEM_ref(ISSUER_SIGN_TOOL), /* template */
138
    0, 0, 0, 0, /* old functions, ignored */
139
    0, /* i2s */
140
    0, /* s2i */
141
    0, /* i2v */
142
    (X509V3_EXT_V2I)v2i_issuer_sign_tool, /* v2i */
143
    (X509V3_EXT_I2R)i2r_issuer_sign_tool, /* i2r */
144
    0, /* r2i */
145
    NULL /* extension-specific data */
146
};