]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/v3_utf8.c
Convert all {NAME}err() in crypto/ to their corresponding ERR_raise() call
[thirdparty/openssl.git] / crypto / x509 / v3_utf8.c
CommitLineData
6103f39c
NM
1/*
2 * Copyright 2020 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/asn1.h>
13#include <openssl/conf.h>
14#include <openssl/x509v3.h>
15#include <crypto/x509v3.h>
16#include "ext_dat.h"
17
18/*
19 * Subject Sign Tool (1.2.643.100.111) The name of the tool used to signs the subject (UTF8String)
20 * This extention 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
26const X509V3_EXT_METHOD v3_utf8_list[1] = {
27 EXT_UTF8STRING(NID_subjectSignTool),
28};
29
30char *i2s_ASN1_UTF8STRING(X509V3_EXT_METHOD *method,
31 ASN1_UTF8STRING *utf8)
32{
33 char *tmp;
34
35 if (utf8 == NULL || utf8->length == 0) {
9311d0c4 36 ERR_raise(ERR_LIB_X509V3, ERR_R_PASSED_NULL_PARAMETER);
6103f39c
NM
37 return NULL;
38 }
75e8e225 39 if ((tmp = OPENSSL_malloc(utf8->length + 1)) == NULL) {
9311d0c4 40 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
6103f39c
NM
41 return NULL;
42 }
43 memcpy(tmp, utf8->data, utf8->length);
75e8e225 44 tmp[utf8->length] = 0;
6103f39c
NM
45 return tmp;
46}
47
48ASN1_UTF8STRING *s2i_ASN1_UTF8STRING(X509V3_EXT_METHOD *method,
49 X509V3_CTX *ctx, const char *str)
50{
51 ASN1_UTF8STRING *utf8;
52 if (str == NULL) {
9311d0c4 53 ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
6103f39c
NM
54 return NULL;
55 }
56 if ((utf8 = ASN1_UTF8STRING_new()) == NULL) {
9311d0c4 57 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
6103f39c
NM
58 return NULL;
59 }
60 if (!ASN1_STRING_set((ASN1_STRING *)utf8, str, strlen(str))) {
9311d0c4 61 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
6103f39c
NM
62 ASN1_UTF8STRING_free(utf8);
63 return NULL;
64 }
65#ifdef CHARSET_EBCDIC
66 ebcdic2ascii(utf8->data, utf8->data, utf8->length);
67#endif /* CHARSET_EBCDIC */
68 return utf8;
69}