]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
454afd98 | 2 | * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. |
2f0eae31 | 3 | * |
4286ca47 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
d2e9e320 RS |
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 | |
2f0eae31 DSH |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
b39fc560 | 11 | #include "internal/cryptlib.h" |
ec577822 BM |
12 | #include <openssl/conf.h> |
13 | #include <openssl/asn1.h> | |
9d6b1ce6 | 14 | #include <openssl/asn1t.h> |
ec577822 | 15 | #include <openssl/x509v3.h> |
df2ee0e2 | 16 | #include "ext_dat.h" |
2f0eae31 DSH |
17 | |
18 | /* Support for Thawte strong extranet extension */ | |
19 | ||
28a98809 DSH |
20 | #define SXNET_TEST |
21 | ||
0f113f3e MC |
22 | static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, |
23 | int indent); | |
28a98809 | 24 | #ifdef SXNET_TEST |
0f113f3e MC |
25 | static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
26 | STACK_OF(CONF_VALUE) *nval); | |
28a98809 | 27 | #endif |
560b79cb | 28 | const X509V3_EXT_METHOD v3_sxnet = { |
0f113f3e MC |
29 | NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET), |
30 | 0, 0, 0, 0, | |
31 | 0, 0, | |
32 | 0, | |
28a98809 | 33 | #ifdef SXNET_TEST |
0f113f3e | 34 | (X509V3_EXT_V2I)sxnet_v2i, |
28a98809 | 35 | #else |
0f113f3e | 36 | 0, |
28a98809 | 37 | #endif |
0f113f3e MC |
38 | (X509V3_EXT_I2R)sxnet_i2r, |
39 | 0, | |
40 | NULL | |
2f0eae31 DSH |
41 | }; |
42 | ||
9d6b1ce6 | 43 | ASN1_SEQUENCE(SXNETID) = { |
0f113f3e MC |
44 | ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER), |
45 | ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING) | |
d339187b | 46 | } ASN1_SEQUENCE_END(SXNETID) |
2f0eae31 | 47 | |
9d6b1ce6 | 48 | IMPLEMENT_ASN1_FUNCTIONS(SXNETID) |
2f0eae31 | 49 | |
9d6b1ce6 | 50 | ASN1_SEQUENCE(SXNET) = { |
0f113f3e MC |
51 | ASN1_SIMPLE(SXNET, version, ASN1_INTEGER), |
52 | ASN1_SEQUENCE_OF(SXNET, ids, SXNETID) | |
d339187b | 53 | } ASN1_SEQUENCE_END(SXNET) |
2f0eae31 | 54 | |
9d6b1ce6 | 55 | IMPLEMENT_ASN1_FUNCTIONS(SXNET) |
2f0eae31 | 56 | |
6b691a5c | 57 | static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, |
0f113f3e | 58 | int indent) |
2f0eae31 | 59 | { |
0f113f3e MC |
60 | long v; |
61 | char *tmp; | |
62 | SXNETID *id; | |
63 | int i; | |
64 | v = ASN1_INTEGER_get(sx->version); | |
65 | BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v); | |
66 | for (i = 0; i < sk_SXNETID_num(sx->ids); i++) { | |
67 | id = sk_SXNETID_value(sx->ids, i); | |
68 | tmp = i2s_ASN1_INTEGER(NULL, id->zone); | |
69 | BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp); | |
70 | OPENSSL_free(tmp); | |
f422a514 | 71 | ASN1_STRING_print(out, id->user); |
0f113f3e MC |
72 | } |
73 | return 1; | |
2f0eae31 | 74 | } |
28a98809 DSH |
75 | |
76 | #ifdef SXNET_TEST | |
77 | ||
0f113f3e MC |
78 | /* |
79 | * NBB: this is used for testing only. It should *not* be used for anything | |
28a98809 DSH |
80 | * else because it will just take static IDs from the configuration file and |
81 | * they should really be separate values for each user. | |
82 | */ | |
83 | ||
0f113f3e MC |
84 | static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
85 | STACK_OF(CONF_VALUE) *nval) | |
28a98809 | 86 | { |
0f113f3e MC |
87 | CONF_VALUE *cnf; |
88 | SXNET *sx = NULL; | |
89 | int i; | |
90 | for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { | |
91 | cnf = sk_CONF_VALUE_value(nval, i); | |
92 | if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1)) | |
93 | return NULL; | |
94 | } | |
95 | return sx; | |
28a98809 | 96 | } |
0f113f3e | 97 | |
28a98809 DSH |
98 | #endif |
99 | ||
100 | /* Strong Extranet utility functions */ | |
101 | ||
102 | /* Add an id given the zone as an ASCII number */ | |
103 | ||
0aa25a68 | 104 | int SXNET_add_id_asc(SXNET **psx, const char *zone, const char *user, int userlen) |
28a98809 | 105 | { |
75ebbd9a RS |
106 | ASN1_INTEGER *izone; |
107 | ||
108 | if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) { | |
9311d0c4 | 109 | ERR_raise(ERR_LIB_X509V3, X509V3_R_ERROR_CONVERTING_ZONE); |
0f113f3e MC |
110 | return 0; |
111 | } | |
112 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); | |
28a98809 DSH |
113 | } |
114 | ||
115 | /* Add an id given the zone as an unsigned long */ | |
116 | ||
0aa25a68 | 117 | int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, const char *user, |
0f113f3e | 118 | int userlen) |
28a98809 | 119 | { |
75ebbd9a RS |
120 | ASN1_INTEGER *izone; |
121 | ||
122 | if ((izone = ASN1_INTEGER_new()) == NULL | |
123 | || !ASN1_INTEGER_set(izone, lzone)) { | |
9311d0c4 | 124 | ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); |
f422a514 | 125 | ASN1_INTEGER_free(izone); |
0f113f3e MC |
126 | return 0; |
127 | } | |
128 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); | |
129 | ||
28a98809 DSH |
130 | } |
131 | ||
0f113f3e MC |
132 | /* |
133 | * Add an id given the zone as an ASN1_INTEGER. Note this version uses the | |
134 | * passed integer and doesn't make a copy so don't free it up afterwards. | |
28a98809 DSH |
135 | */ |
136 | ||
0aa25a68 | 137 | int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, const char *user, |
0f113f3e | 138 | int userlen) |
28a98809 | 139 | { |
0f113f3e MC |
140 | SXNET *sx = NULL; |
141 | SXNETID *id = NULL; | |
12a765a5 RS |
142 | |
143 | if (psx == NULL || zone == NULL || user == NULL) { | |
9311d0c4 | 144 | ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_ARGUMENT); |
0f113f3e MC |
145 | return 0; |
146 | } | |
147 | if (userlen == -1) | |
148 | userlen = strlen(user); | |
149 | if (userlen > 64) { | |
9311d0c4 | 150 | ERR_raise(ERR_LIB_X509V3, X509V3_R_USER_TOO_LONG); |
0f113f3e MC |
151 | return 0; |
152 | } | |
75ebbd9a RS |
153 | if (*psx == NULL) { |
154 | if ((sx = SXNET_new()) == NULL) | |
0f113f3e MC |
155 | goto err; |
156 | if (!ASN1_INTEGER_set(sx->version, 0)) | |
157 | goto err; | |
158 | *psx = sx; | |
159 | } else | |
160 | sx = *psx; | |
161 | if (SXNET_get_id_INTEGER(sx, zone)) { | |
9311d0c4 | 162 | ERR_raise(ERR_LIB_X509V3, X509V3_R_DUPLICATE_ZONE_ID); |
0f113f3e MC |
163 | return 0; |
164 | } | |
28a98809 | 165 | |
75ebbd9a | 166 | if ((id = SXNETID_new()) == NULL) |
0f113f3e MC |
167 | goto err; |
168 | if (userlen == -1) | |
169 | userlen = strlen(user); | |
170 | ||
0aa25a68 | 171 | if (!ASN1_OCTET_STRING_set(id->user, (const unsigned char *)user, userlen)) |
0f113f3e MC |
172 | goto err; |
173 | if (!sk_SXNETID_push(sx->ids, id)) | |
174 | goto err; | |
175 | id->zone = zone; | |
176 | return 1; | |
177 | ||
178 | err: | |
9311d0c4 | 179 | ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); |
0f113f3e MC |
180 | SXNETID_free(id); |
181 | SXNET_free(sx); | |
182 | *psx = NULL; | |
183 | return 0; | |
28a98809 DSH |
184 | } |
185 | ||
0aa25a68 | 186 | ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, const char *zone) |
28a98809 | 187 | { |
75ebbd9a | 188 | ASN1_INTEGER *izone; |
0f113f3e | 189 | ASN1_OCTET_STRING *oct; |
75ebbd9a RS |
190 | |
191 | if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) { | |
9311d0c4 | 192 | ERR_raise(ERR_LIB_X509V3, X509V3_R_ERROR_CONVERTING_ZONE); |
0f113f3e MC |
193 | return NULL; |
194 | } | |
195 | oct = SXNET_get_id_INTEGER(sx, izone); | |
f422a514 | 196 | ASN1_INTEGER_free(izone); |
0f113f3e | 197 | return oct; |
28a98809 DSH |
198 | } |
199 | ||
6b691a5c | 200 | ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) |
28a98809 | 201 | { |
75ebbd9a | 202 | ASN1_INTEGER *izone; |
0f113f3e | 203 | ASN1_OCTET_STRING *oct; |
75ebbd9a RS |
204 | |
205 | if ((izone = ASN1_INTEGER_new()) == NULL | |
206 | || !ASN1_INTEGER_set(izone, lzone)) { | |
9311d0c4 | 207 | ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE); |
f422a514 | 208 | ASN1_INTEGER_free(izone); |
0f113f3e MC |
209 | return NULL; |
210 | } | |
211 | oct = SXNET_get_id_INTEGER(sx, izone); | |
f422a514 | 212 | ASN1_INTEGER_free(izone); |
0f113f3e | 213 | return oct; |
28a98809 DSH |
214 | } |
215 | ||
6b691a5c | 216 | ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone) |
28a98809 | 217 | { |
0f113f3e MC |
218 | SXNETID *id; |
219 | int i; | |
220 | for (i = 0; i < sk_SXNETID_num(sx->ids); i++) { | |
221 | id = sk_SXNETID_value(sx->ids, i); | |
f422a514 | 222 | if (!ASN1_INTEGER_cmp(id->zone, zone)) |
0f113f3e MC |
223 | return id->user; |
224 | } | |
225 | return NULL; | |
28a98809 | 226 | } |