1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 1999-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_ciconst X509V3_EXT_METHOD ossl_v3_ns_ia5_list[8] = {
18e1051a39Sopenharmony_ci    EXT_IA5STRING(NID_netscape_base_url),
19e1051a39Sopenharmony_ci    EXT_IA5STRING(NID_netscape_revocation_url),
20e1051a39Sopenharmony_ci    EXT_IA5STRING(NID_netscape_ca_revocation_url),
21e1051a39Sopenharmony_ci    EXT_IA5STRING(NID_netscape_renewal_url),
22e1051a39Sopenharmony_ci    EXT_IA5STRING(NID_netscape_ca_policy_url),
23e1051a39Sopenharmony_ci    EXT_IA5STRING(NID_netscape_ssl_server_name),
24e1051a39Sopenharmony_ci    EXT_IA5STRING(NID_netscape_comment),
25e1051a39Sopenharmony_ci    EXT_END
26e1051a39Sopenharmony_ci};
27e1051a39Sopenharmony_ci
28e1051a39Sopenharmony_cichar *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5)
29e1051a39Sopenharmony_ci{
30e1051a39Sopenharmony_ci    char *tmp;
31e1051a39Sopenharmony_ci
32e1051a39Sopenharmony_ci    if (ia5 == NULL || ia5->length <= 0)
33e1051a39Sopenharmony_ci        return NULL;
34e1051a39Sopenharmony_ci    if ((tmp = OPENSSL_malloc(ia5->length + 1)) == NULL) {
35e1051a39Sopenharmony_ci        ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
36e1051a39Sopenharmony_ci        return NULL;
37e1051a39Sopenharmony_ci    }
38e1051a39Sopenharmony_ci    memcpy(tmp, ia5->data, ia5->length);
39e1051a39Sopenharmony_ci    tmp[ia5->length] = 0;
40e1051a39Sopenharmony_ci    return tmp;
41e1051a39Sopenharmony_ci}
42e1051a39Sopenharmony_ci
43e1051a39Sopenharmony_ciASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
44e1051a39Sopenharmony_ci                                   X509V3_CTX *ctx, const char *str)
45e1051a39Sopenharmony_ci{
46e1051a39Sopenharmony_ci    ASN1_IA5STRING *ia5;
47e1051a39Sopenharmony_ci    if (str == NULL) {
48e1051a39Sopenharmony_ci        ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
49e1051a39Sopenharmony_ci        return NULL;
50e1051a39Sopenharmony_ci    }
51e1051a39Sopenharmony_ci    if ((ia5 = ASN1_IA5STRING_new()) == NULL)
52e1051a39Sopenharmony_ci        goto err;
53e1051a39Sopenharmony_ci    if (!ASN1_STRING_set((ASN1_STRING *)ia5, str, strlen(str))) {
54e1051a39Sopenharmony_ci        ASN1_IA5STRING_free(ia5);
55e1051a39Sopenharmony_ci        return NULL;
56e1051a39Sopenharmony_ci    }
57e1051a39Sopenharmony_ci#ifdef CHARSET_EBCDIC
58e1051a39Sopenharmony_ci    ebcdic2ascii(ia5->data, ia5->data, ia5->length);
59e1051a39Sopenharmony_ci#endif                          /* CHARSET_EBCDIC */
60e1051a39Sopenharmony_ci    return ia5;
61e1051a39Sopenharmony_ci err:
62e1051a39Sopenharmony_ci    ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
63e1051a39Sopenharmony_ci    return NULL;
64e1051a39Sopenharmony_ci}
65