1*b077aed3SPierre Pronchery /* 2*b077aed3SPierre Pronchery * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. 3*b077aed3SPierre Pronchery * 4*b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5*b077aed3SPierre Pronchery * this file except in compliance with the License. You can obtain a copy 6*b077aed3SPierre Pronchery * in the file LICENSE in the source distribution or at 7*b077aed3SPierre Pronchery * https://www.openssl.org/source/license.html 8*b077aed3SPierre Pronchery */ 9*b077aed3SPierre Pronchery 10*b077aed3SPierre Pronchery #include <stdio.h> 11*b077aed3SPierre Pronchery #include "internal/cryptlib.h" 12*b077aed3SPierre Pronchery #include <openssl/conf.h> 13*b077aed3SPierre Pronchery #include <openssl/asn1.h> 14*b077aed3SPierre Pronchery #include <openssl/asn1t.h> 15*b077aed3SPierre Pronchery #include <openssl/x509v3.h> 16*b077aed3SPierre Pronchery #include "ext_dat.h" 17*b077aed3SPierre Pronchery 18*b077aed3SPierre Pronchery /* 19*b077aed3SPierre Pronchery * Issuer Sign Tool (1.2.643.100.112) The name of the tool used to signs the subject (ASN1_SEQUENCE) 20*b077aed3SPierre Pronchery * This extention is required to obtain the status of a qualified certificate at Russian Federation. 21*b077aed3SPierre Pronchery * RFC-style description is available here: https://tools.ietf.org/html/draft-deremin-rfc4491-bis-04#section-5 22*b077aed3SPierre Pronchery * Russian Federal Law 63 "Digital Sign" is available here: http://www.consultant.ru/document/cons_doc_LAW_112701/ 23*b077aed3SPierre Pronchery */ 24*b077aed3SPierre Pronchery 25*b077aed3SPierre Pronchery ASN1_SEQUENCE(ISSUER_SIGN_TOOL) = { 26*b077aed3SPierre Pronchery ASN1_SIMPLE(ISSUER_SIGN_TOOL, signTool, ASN1_UTF8STRING), 27*b077aed3SPierre Pronchery ASN1_SIMPLE(ISSUER_SIGN_TOOL, cATool, ASN1_UTF8STRING), 28*b077aed3SPierre Pronchery ASN1_SIMPLE(ISSUER_SIGN_TOOL, signToolCert, ASN1_UTF8STRING), 29*b077aed3SPierre Pronchery ASN1_SIMPLE(ISSUER_SIGN_TOOL, cAToolCert, ASN1_UTF8STRING) 30*b077aed3SPierre Pronchery } ASN1_SEQUENCE_END(ISSUER_SIGN_TOOL) 31*b077aed3SPierre Pronchery 32*b077aed3SPierre Pronchery IMPLEMENT_ASN1_FUNCTIONS(ISSUER_SIGN_TOOL) 33*b077aed3SPierre Pronchery 34*b077aed3SPierre Pronchery 35*b077aed3SPierre Pronchery static ISSUER_SIGN_TOOL *v2i_issuer_sign_tool(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, 36*b077aed3SPierre Pronchery STACK_OF(CONF_VALUE) *nval) 37*b077aed3SPierre Pronchery { 38*b077aed3SPierre Pronchery ISSUER_SIGN_TOOL *ist = ISSUER_SIGN_TOOL_new(); 39*b077aed3SPierre Pronchery int i; 40*b077aed3SPierre Pronchery 41*b077aed3SPierre Pronchery if (ist == NULL) { 42*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 43*b077aed3SPierre Pronchery return NULL; 44*b077aed3SPierre Pronchery } 45*b077aed3SPierre Pronchery for (i = 0; i < sk_CONF_VALUE_num(nval); ++i) { 46*b077aed3SPierre Pronchery CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i); 47*b077aed3SPierre Pronchery 48*b077aed3SPierre Pronchery if (cnf == NULL) { 49*b077aed3SPierre Pronchery continue; 50*b077aed3SPierre Pronchery } 51*b077aed3SPierre Pronchery if (strcmp(cnf->name, "signTool") == 0) { 52*b077aed3SPierre Pronchery ist->signTool = ASN1_UTF8STRING_new(); 53*b077aed3SPierre Pronchery if (ist->signTool == NULL) { 54*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 55*b077aed3SPierre Pronchery ISSUER_SIGN_TOOL_free(ist); 56*b077aed3SPierre Pronchery return NULL; 57*b077aed3SPierre Pronchery } 58*b077aed3SPierre Pronchery ASN1_STRING_set(ist->signTool, cnf->value, strlen(cnf->value)); 59*b077aed3SPierre Pronchery } else if (strcmp(cnf->name, "cATool") == 0) { 60*b077aed3SPierre Pronchery ist->cATool = ASN1_UTF8STRING_new(); 61*b077aed3SPierre Pronchery if (ist->cATool == NULL) { 62*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 63*b077aed3SPierre Pronchery ISSUER_SIGN_TOOL_free(ist); 64*b077aed3SPierre Pronchery return NULL; 65*b077aed3SPierre Pronchery } 66*b077aed3SPierre Pronchery ASN1_STRING_set(ist->cATool, cnf->value, strlen(cnf->value)); 67*b077aed3SPierre Pronchery } else if (strcmp(cnf->name, "signToolCert") == 0) { 68*b077aed3SPierre Pronchery ist->signToolCert = ASN1_UTF8STRING_new(); 69*b077aed3SPierre Pronchery if (ist->signToolCert == NULL) { 70*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 71*b077aed3SPierre Pronchery ISSUER_SIGN_TOOL_free(ist); 72*b077aed3SPierre Pronchery return NULL; 73*b077aed3SPierre Pronchery } 74*b077aed3SPierre Pronchery ASN1_STRING_set(ist->signToolCert, cnf->value, strlen(cnf->value)); 75*b077aed3SPierre Pronchery } else if (strcmp(cnf->name, "cAToolCert") == 0) { 76*b077aed3SPierre Pronchery ist->cAToolCert = ASN1_UTF8STRING_new(); 77*b077aed3SPierre Pronchery if (ist->cAToolCert == NULL) { 78*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 79*b077aed3SPierre Pronchery ISSUER_SIGN_TOOL_free(ist); 80*b077aed3SPierre Pronchery return NULL; 81*b077aed3SPierre Pronchery } 82*b077aed3SPierre Pronchery ASN1_STRING_set(ist->cAToolCert, cnf->value, strlen(cnf->value)); 83*b077aed3SPierre Pronchery } else { 84*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_INVALID_ARGUMENT); 85*b077aed3SPierre Pronchery ISSUER_SIGN_TOOL_free(ist); 86*b077aed3SPierre Pronchery return NULL; 87*b077aed3SPierre Pronchery } 88*b077aed3SPierre Pronchery } 89*b077aed3SPierre Pronchery return ist; 90*b077aed3SPierre Pronchery } 91*b077aed3SPierre Pronchery 92*b077aed3SPierre Pronchery static int i2r_issuer_sign_tool(X509V3_EXT_METHOD *method, 93*b077aed3SPierre Pronchery ISSUER_SIGN_TOOL *ist, BIO *out, 94*b077aed3SPierre Pronchery int indent) 95*b077aed3SPierre Pronchery { 96*b077aed3SPierre Pronchery int new_line = 0; 97*b077aed3SPierre Pronchery 98*b077aed3SPierre Pronchery if (ist == NULL) { 99*b077aed3SPierre Pronchery ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_INVALID_ARGUMENT); 100*b077aed3SPierre Pronchery return 0; 101*b077aed3SPierre Pronchery } 102*b077aed3SPierre Pronchery if (ist->signTool != NULL) { 103*b077aed3SPierre Pronchery if (new_line == 1) { 104*b077aed3SPierre Pronchery BIO_write(out, "\n", 1); 105*b077aed3SPierre Pronchery } 106*b077aed3SPierre Pronchery BIO_printf(out, "%*ssignTool : ", indent, ""); 107*b077aed3SPierre Pronchery BIO_write(out, ist->signTool->data, ist->signTool->length); 108*b077aed3SPierre Pronchery new_line = 1; 109*b077aed3SPierre Pronchery } 110*b077aed3SPierre Pronchery if (ist->cATool != NULL) { 111*b077aed3SPierre Pronchery if (new_line == 1) { 112*b077aed3SPierre Pronchery BIO_write(out, "\n", 1); 113*b077aed3SPierre Pronchery } 114*b077aed3SPierre Pronchery BIO_printf(out, "%*scATool : ", indent, ""); 115*b077aed3SPierre Pronchery BIO_write(out, ist->cATool->data, ist->cATool->length); 116*b077aed3SPierre Pronchery new_line = 1; 117*b077aed3SPierre Pronchery } 118*b077aed3SPierre Pronchery if (ist->signToolCert != NULL) { 119*b077aed3SPierre Pronchery if (new_line == 1) { 120*b077aed3SPierre Pronchery BIO_write(out, "\n", 1); 121*b077aed3SPierre Pronchery } 122*b077aed3SPierre Pronchery BIO_printf(out, "%*ssignToolCert: ", indent, ""); 123*b077aed3SPierre Pronchery BIO_write(out, ist->signToolCert->data, ist->signToolCert->length); 124*b077aed3SPierre Pronchery new_line = 1; 125*b077aed3SPierre Pronchery } 126*b077aed3SPierre Pronchery if (ist->cAToolCert != NULL) { 127*b077aed3SPierre Pronchery if (new_line == 1) { 128*b077aed3SPierre Pronchery BIO_write(out, "\n", 1); 129*b077aed3SPierre Pronchery } 130*b077aed3SPierre Pronchery BIO_printf(out, "%*scAToolCert : ", indent, ""); 131*b077aed3SPierre Pronchery BIO_write(out, ist->cAToolCert->data, ist->cAToolCert->length); 132*b077aed3SPierre Pronchery new_line = 1; 133*b077aed3SPierre Pronchery } 134*b077aed3SPierre Pronchery return 1; 135*b077aed3SPierre Pronchery } 136*b077aed3SPierre Pronchery 137*b077aed3SPierre Pronchery const X509V3_EXT_METHOD ossl_v3_issuer_sign_tool = { 138*b077aed3SPierre Pronchery NID_issuerSignTool, /* nid */ 139*b077aed3SPierre Pronchery X509V3_EXT_MULTILINE, /* flags */ 140*b077aed3SPierre Pronchery ASN1_ITEM_ref(ISSUER_SIGN_TOOL), /* template */ 141*b077aed3SPierre Pronchery 0, 0, 0, 0, /* old functions, ignored */ 142*b077aed3SPierre Pronchery 0, /* i2s */ 143*b077aed3SPierre Pronchery 0, /* s2i */ 144*b077aed3SPierre Pronchery 0, /* i2v */ 145*b077aed3SPierre Pronchery (X509V3_EXT_V2I)v2i_issuer_sign_tool, /* v2i */ 146*b077aed3SPierre Pronchery (X509V3_EXT_I2R)i2r_issuer_sign_tool, /* i2r */ 147*b077aed3SPierre Pronchery 0, /* r2i */ 148*b077aed3SPierre Pronchery NULL /* extension-specific data */ 149*b077aed3SPierre Pronchery }; 150