1 /*
2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (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 <string.h>
12
13 #include <openssl/asn1.h>
14 #include <openssl/conf.h>
15 #include <openssl/err.h>
16 #include <openssl/mem.h>
17 #include <openssl/obj.h>
18 #include <openssl/x509.h>
19
20 #include "../internal.h"
21 #include "ext_dat.h"
22
23
i2s_ASN1_IA5STRING(const X509V3_EXT_METHOD * method,void * ext)24 static char *i2s_ASN1_IA5STRING(const X509V3_EXT_METHOD *method, void *ext) {
25 const ASN1_IA5STRING *ia5 = reinterpret_cast<const ASN1_IA5STRING *>(ext);
26 char *tmp;
27 if (!ia5 || !ia5->length) {
28 return NULL;
29 }
30 if (!(tmp = reinterpret_cast<char *>(OPENSSL_malloc(ia5->length + 1)))) {
31 return NULL;
32 }
33 OPENSSL_memcpy(tmp, ia5->data, ia5->length);
34 tmp[ia5->length] = 0;
35 return tmp;
36 }
37
s2i_ASN1_IA5STRING(const X509V3_EXT_METHOD * method,const X509V3_CTX * ctx,const char * str)38 static void *s2i_ASN1_IA5STRING(const X509V3_EXT_METHOD *method,
39 const X509V3_CTX *ctx, const char *str) {
40 ASN1_IA5STRING *ia5;
41 if (!str) {
42 OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
43 return NULL;
44 }
45 if (!(ia5 = ASN1_IA5STRING_new())) {
46 goto err;
47 }
48 if (!ASN1_STRING_set(ia5, str, strlen(str))) {
49 ASN1_IA5STRING_free(ia5);
50 goto err;
51 }
52 return ia5;
53 err:
54 return NULL;
55 }
56
57 #define EXT_IA5STRING(nid) \
58 { \
59 nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), 0, 0, 0, 0, i2s_ASN1_IA5STRING, \
60 s2i_ASN1_IA5STRING, 0, 0, 0, 0, NULL \
61 }
62
63 #define EXT_END \
64 { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
65
66 const X509V3_EXT_METHOD v3_ns_ia5_list[] = {
67 EXT_IA5STRING(NID_netscape_base_url),
68 EXT_IA5STRING(NID_netscape_revocation_url),
69 EXT_IA5STRING(NID_netscape_ca_revocation_url),
70 EXT_IA5STRING(NID_netscape_renewal_url),
71 EXT_IA5STRING(NID_netscape_ca_policy_url),
72 EXT_IA5STRING(NID_netscape_ssl_server_name),
73 EXT_IA5STRING(NID_netscape_comment),
74 EXT_END};
75