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/asn1.h> 13e1051a39Sopenharmony_ci#include <openssl/conf.h> 14e1051a39Sopenharmony_ci#include <openssl/x509v3.h> 15e1051a39Sopenharmony_ci#include "ext_dat.h" 16e1051a39Sopenharmony_ci 17e1051a39Sopenharmony_ci/* 18e1051a39Sopenharmony_ci * Subject Sign Tool (1.2.643.100.111) The name of the tool used to signs the subject (UTF8String) 19e1051a39Sopenharmony_ci * This extention is required to obtain the status of a qualified certificate at Russian Federation. 20e1051a39Sopenharmony_ci * RFC-style description is available here: https://tools.ietf.org/html/draft-deremin-rfc4491-bis-04#section-5 21e1051a39Sopenharmony_ci * Russian Federal Law 63 "Digital Sign" is available here: http://www.consultant.ru/document/cons_doc_LAW_112701/ 22e1051a39Sopenharmony_ci */ 23e1051a39Sopenharmony_ci 24e1051a39Sopenharmony_ci 25e1051a39Sopenharmony_ciconst X509V3_EXT_METHOD ossl_v3_utf8_list[1] = { 26e1051a39Sopenharmony_ci EXT_UTF8STRING(NID_subjectSignTool), 27e1051a39Sopenharmony_ci}; 28e1051a39Sopenharmony_ci 29e1051a39Sopenharmony_cichar *i2s_ASN1_UTF8STRING(X509V3_EXT_METHOD *method, 30e1051a39Sopenharmony_ci ASN1_UTF8STRING *utf8) 31e1051a39Sopenharmony_ci{ 32e1051a39Sopenharmony_ci char *tmp; 33e1051a39Sopenharmony_ci 34e1051a39Sopenharmony_ci if (utf8 == NULL || utf8->length == 0) { 35e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_NULL_PARAMETER); 36e1051a39Sopenharmony_ci return NULL; 37e1051a39Sopenharmony_ci } 38e1051a39Sopenharmony_ci if ((tmp = OPENSSL_malloc(utf8->length + 1)) == NULL) { 39e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 40e1051a39Sopenharmony_ci return NULL; 41e1051a39Sopenharmony_ci } 42e1051a39Sopenharmony_ci memcpy(tmp, utf8->data, utf8->length); 43e1051a39Sopenharmony_ci tmp[utf8->length] = 0; 44e1051a39Sopenharmony_ci return tmp; 45e1051a39Sopenharmony_ci} 46e1051a39Sopenharmony_ci 47e1051a39Sopenharmony_ciASN1_UTF8STRING *s2i_ASN1_UTF8STRING(X509V3_EXT_METHOD *method, 48e1051a39Sopenharmony_ci X509V3_CTX *ctx, const char *str) 49e1051a39Sopenharmony_ci{ 50e1051a39Sopenharmony_ci ASN1_UTF8STRING *utf8; 51e1051a39Sopenharmony_ci if (str == NULL) { 52e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_ARGUMENT); 53e1051a39Sopenharmony_ci return NULL; 54e1051a39Sopenharmony_ci } 55e1051a39Sopenharmony_ci if ((utf8 = ASN1_UTF8STRING_new()) == NULL) { 56e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 57e1051a39Sopenharmony_ci return NULL; 58e1051a39Sopenharmony_ci } 59e1051a39Sopenharmony_ci if (!ASN1_STRING_set((ASN1_STRING *)utf8, str, strlen(str))) { 60e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); 61e1051a39Sopenharmony_ci ASN1_UTF8STRING_free(utf8); 62e1051a39Sopenharmony_ci return NULL; 63e1051a39Sopenharmony_ci } 64e1051a39Sopenharmony_ci#ifdef CHARSET_EBCDIC 65e1051a39Sopenharmony_ci ebcdic2ascii(utf8->data, utf8->data, utf8->length); 66e1051a39Sopenharmony_ci#endif /* CHARSET_EBCDIC */ 67e1051a39Sopenharmony_ci return utf8; 68e1051a39Sopenharmony_ci} 69