Coverage Report

Created: 2026-10-28 06:28

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