Coverage Report

Created: 2025-12-31 06:58

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