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