/src/openssl/crypto/x509/v3_ist.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright 2020-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 <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  |  | } ASN1_SEQUENCE_END(ISSUER_SIGN_TOOL)  | 
31  |  |  | 
32  |  | IMPLEMENT_ASN1_FUNCTIONS(ISSUER_SIGN_TOOL)  | 
33  |  |  | 
34  |  |  | 
35  |  | static ISSUER_SIGN_TOOL *v2i_issuer_sign_tool(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,  | 
36  |  |                         STACK_OF(CONF_VALUE) *nval)  | 
37  | 0  | { | 
38  | 0  |     ISSUER_SIGN_TOOL *ist = ISSUER_SIGN_TOOL_new();  | 
39  | 0  |     int i;  | 
40  |  | 
  | 
41  | 0  |     if (ist == NULL) { | 
42  | 0  |         ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);  | 
43  | 0  |         return NULL;  | 
44  | 0  |     }  | 
45  | 0  |     for (i = 0; i < sk_CONF_VALUE_num(nval); ++i) { | 
46  | 0  |         CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i);  | 
47  |  | 
  | 
48  | 0  |         if (cnf == NULL) { | 
49  | 0  |             continue;  | 
50  | 0  |         }  | 
51  | 0  |         if (strcmp(cnf->name, "signTool") == 0) { | 
52  | 0  |             ist->signTool = ASN1_UTF8STRING_new();  | 
53  | 0  |             if (ist->signTool == NULL  | 
54  | 0  |                 || cnf->value == NULL  | 
55  | 0  |                 || !ASN1_STRING_set(ist->signTool, cnf->value, strlen(cnf->value))) { | 
56  | 0  |                 ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);  | 
57  | 0  |                 goto err;  | 
58  | 0  |             }  | 
59  | 0  |         } else if (strcmp(cnf->name, "cATool") == 0) { | 
60  | 0  |             ist->cATool = ASN1_UTF8STRING_new();  | 
61  | 0  |             if (ist->cATool == NULL  | 
62  | 0  |                 || cnf->value == NULL  | 
63  | 0  |                 || !ASN1_STRING_set(ist->cATool, cnf->value, strlen(cnf->value))) { | 
64  | 0  |                 ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);  | 
65  | 0  |                 goto err;  | 
66  | 0  |             }  | 
67  | 0  |         } else if (strcmp(cnf->name, "signToolCert") == 0) { | 
68  | 0  |             ist->signToolCert = ASN1_UTF8STRING_new();  | 
69  | 0  |             if (ist->signToolCert == NULL  | 
70  | 0  |                 || cnf->value == NULL  | 
71  | 0  |                 || !ASN1_STRING_set(ist->signToolCert, cnf->value, strlen(cnf->value))) { | 
72  | 0  |                 ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);  | 
73  | 0  |                 goto err;  | 
74  | 0  |             }  | 
75  | 0  |         } else if (strcmp(cnf->name, "cAToolCert") == 0) { | 
76  | 0  |             ist->cAToolCert = ASN1_UTF8STRING_new();  | 
77  | 0  |             if (ist->cAToolCert == NULL  | 
78  | 0  |                 || cnf->value == NULL  | 
79  | 0  |                 || !ASN1_STRING_set(ist->cAToolCert, cnf->value, strlen(cnf->value))) { | 
80  | 0  |                 ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);  | 
81  | 0  |                 goto err;  | 
82  | 0  |             }  | 
83  | 0  |         } else { | 
84  | 0  |             ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_INVALID_ARGUMENT);  | 
85  | 0  |             goto err;  | 
86  | 0  |         }  | 
87  | 0  |     }  | 
88  | 0  |     return ist;  | 
89  |  |  | 
90  | 0  | err:  | 
91  | 0  |     ISSUER_SIGN_TOOL_free(ist);  | 
92  | 0  |     return NULL;  | 
93  | 0  | }  | 
94  |  |  | 
95  |  | static int i2r_issuer_sign_tool(X509V3_EXT_METHOD *method,  | 
96  |  |                                  ISSUER_SIGN_TOOL *ist, BIO *out,  | 
97  |  |                                  int indent)  | 
98  | 0  | { | 
99  | 0  |     int new_line = 0;  | 
100  |  | 
  | 
101  | 0  |     if (ist == NULL) { | 
102  | 0  |         ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_INVALID_ARGUMENT);  | 
103  | 0  |         return 0;  | 
104  | 0  |     }  | 
105  | 0  |     if (ist->signTool != NULL) { | 
106  | 0  |         BIO_printf(out, "%*ssignTool    : ", indent, "");  | 
107  | 0  |         BIO_write(out, ist->signTool->data, ist->signTool->length);  | 
108  | 0  |         new_line = 1;  | 
109  | 0  |     }  | 
110  | 0  |     if (ist->cATool != NULL) { | 
111  | 0  |         if (new_line == 1) { | 
112  | 0  |             BIO_write(out, "\n", 1);  | 
113  | 0  |         }  | 
114  | 0  |         BIO_printf(out, "%*scATool      : ", indent, "");  | 
115  | 0  |         BIO_write(out, ist->cATool->data, ist->cATool->length);  | 
116  | 0  |         new_line = 1;  | 
117  | 0  |     }  | 
118  | 0  |     if (ist->signToolCert != NULL) { | 
119  | 0  |         if (new_line == 1) { | 
120  | 0  |             BIO_write(out, "\n", 1);  | 
121  | 0  |         }  | 
122  | 0  |         BIO_printf(out, "%*ssignToolCert: ", indent, "");  | 
123  | 0  |         BIO_write(out, ist->signToolCert->data, ist->signToolCert->length);  | 
124  | 0  |         new_line = 1;  | 
125  | 0  |     }  | 
126  | 0  |     if (ist->cAToolCert != NULL) { | 
127  | 0  |         if (new_line == 1) { | 
128  | 0  |             BIO_write(out, "\n", 1);  | 
129  | 0  |         }  | 
130  | 0  |         BIO_printf(out, "%*scAToolCert  : ", indent, "");  | 
131  | 0  |         BIO_write(out, ist->cAToolCert->data, ist->cAToolCert->length);  | 
132  | 0  |         new_line = 1;  | 
133  | 0  |     }  | 
134  | 0  |     return 1;  | 
135  | 0  | }  | 
136  |  |  | 
137  |  | const X509V3_EXT_METHOD ossl_v3_issuer_sign_tool = { | 
138  |  |     NID_issuerSignTool,                   /* nid */  | 
139  |  |     X509V3_EXT_MULTILINE,                 /* flags */  | 
140  |  |     ASN1_ITEM_ref(ISSUER_SIGN_TOOL),      /* template */  | 
141  |  |     0, 0, 0, 0,                           /* old functions, ignored */  | 
142  |  |     0,                                    /* i2s */  | 
143  |  |     0,                                    /* s2i */  | 
144  |  |     0,                                    /* i2v */  | 
145  |  |     (X509V3_EXT_V2I)v2i_issuer_sign_tool, /* v2i */  | 
146  |  |     (X509V3_EXT_I2R)i2r_issuer_sign_tool, /* i2r */  | 
147  |  |     0,                                    /* r2i */  | 
148  |  |     NULL                                  /* extension-specific data */  | 
149  |  | };  |