VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.2/crypto/x509/v3_sxnet.c@ 94483

最後變更 在這個檔案從94483是 94404,由 vboxsync 提交於 3 年 前

libs/openssl: Update to 3.0.2 and switch to it, bugref:10128

檔案大小: 6.3 KB
 
1/*
2 * Copyright 1999-2022 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/conf.h>
13#include <openssl/asn1.h>
14#include <openssl/asn1t.h>
15#include <openssl/x509v3.h>
16#include "ext_dat.h"
17
18/* Support for Thawte strong extranet extension */
19
20#define SXNET_TEST
21
22static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
23 int indent);
24#ifdef SXNET_TEST
25static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
26 STACK_OF(CONF_VALUE) *nval);
27#endif
28const X509V3_EXT_METHOD ossl_v3_sxnet = {
29 NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET),
30 0, 0, 0, 0,
31 0, 0,
32 0,
33#ifdef SXNET_TEST
34 (X509V3_EXT_V2I)sxnet_v2i,
35#else
36 0,
37#endif
38 (X509V3_EXT_I2R)sxnet_i2r,
39 0,
40 NULL
41};
42
43ASN1_SEQUENCE(SXNETID) = {
44 ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER),
45 ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING)
46} ASN1_SEQUENCE_END(SXNETID)
47
48IMPLEMENT_ASN1_FUNCTIONS(SXNETID)
49
50ASN1_SEQUENCE(SXNET) = {
51 ASN1_SIMPLE(SXNET, version, ASN1_INTEGER),
52 ASN1_SEQUENCE_OF(SXNET, ids, SXNETID)
53} ASN1_SEQUENCE_END(SXNET)
54
55IMPLEMENT_ASN1_FUNCTIONS(SXNET)
56
57static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
58 int indent)
59{
60 int64_t v;
61 char *tmp;
62 SXNETID *id;
63 int i;
64
65 /*
66 * Since we add 1 to the version number to display it, we don't support
67 * LONG_MAX since that would cause on overflow.
68 */
69 if (!ASN1_INTEGER_get_int64(&v, sx->version)
70 || v >= LONG_MAX
71 || v < LONG_MIN) {
72 BIO_printf(out, "%*sVersion: <unsupported>", indent, "");
73 } else {
74 long vl = (long)v;
75
76 BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", vl + 1, vl);
77 }
78 for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
79 id = sk_SXNETID_value(sx->ids, i);
80 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
81 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
82 OPENSSL_free(tmp);
83 ASN1_STRING_print(out, id->user);
84 }
85 return 1;
86}
87
88#ifdef SXNET_TEST
89
90/*
91 * NBB: this is used for testing only. It should *not* be used for anything
92 * else because it will just take static IDs from the configuration file and
93 * they should really be separate values for each user.
94 */
95
96static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
97 STACK_OF(CONF_VALUE) *nval)
98{
99 CONF_VALUE *cnf;
100 SXNET *sx = NULL;
101 int i;
102 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
103 cnf = sk_CONF_VALUE_value(nval, i);
104 if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
105 return NULL;
106 }
107 return sx;
108}
109
110#endif
111
112/* Strong Extranet utility functions */
113
114/* Add an id given the zone as an ASCII number */
115
116int SXNET_add_id_asc(SXNET **psx, const char *zone, const char *user, int userlen)
117{
118 ASN1_INTEGER *izone;
119
120 if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) {
121 ERR_raise(ERR_LIB_X509V3, X509V3_R_ERROR_CONVERTING_ZONE);
122 return 0;
123 }
124 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
125}
126
127/* Add an id given the zone as an unsigned long */
128
129int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, const char *user,
130 int userlen)
131{
132 ASN1_INTEGER *izone;
133
134 if ((izone = ASN1_INTEGER_new()) == NULL
135 || !ASN1_INTEGER_set(izone, lzone)) {
136 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
137 ASN1_INTEGER_free(izone);
138 return 0;
139 }
140 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
141
142}
143
144/*
145 * Add an id given the zone as an ASN1_INTEGER. Note this version uses the
146 * passed integer and doesn't make a copy so don't free it up afterwards.
147 */
148
149int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, const char *user,
150 int userlen)
151{
152 SXNET *sx = NULL;
153 SXNETID *id = NULL;
154
155 if (psx == NULL || zone == NULL || user == NULL) {
156 ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
157 return 0;
158 }
159 if (userlen == -1)
160 userlen = strlen(user);
161 if (userlen > 64) {
162 ERR_raise(ERR_LIB_X509V3, X509V3_R_USER_TOO_LONG);
163 return 0;
164 }
165 if (*psx == NULL) {
166 if ((sx = SXNET_new()) == NULL)
167 goto err;
168 if (!ASN1_INTEGER_set(sx->version, 0))
169 goto err;
170 } else
171 sx = *psx;
172 if (SXNET_get_id_INTEGER(sx, zone)) {
173 ERR_raise(ERR_LIB_X509V3, X509V3_R_DUPLICATE_ZONE_ID);
174 if (*psx == NULL)
175 SXNET_free(sx);
176 return 0;
177 }
178
179 if ((id = SXNETID_new()) == NULL)
180 goto err;
181 if (userlen == -1)
182 userlen = strlen(user);
183
184 if (!ASN1_OCTET_STRING_set(id->user, (const unsigned char *)user, userlen))
185 goto err;
186 if (!sk_SXNETID_push(sx->ids, id))
187 goto err;
188 id->zone = zone;
189 *psx = sx;
190 return 1;
191
192 err:
193 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
194 SXNETID_free(id);
195 if (*psx == NULL)
196 SXNET_free(sx);
197 return 0;
198}
199
200ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, const char *zone)
201{
202 ASN1_INTEGER *izone;
203 ASN1_OCTET_STRING *oct;
204
205 if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) {
206 ERR_raise(ERR_LIB_X509V3, X509V3_R_ERROR_CONVERTING_ZONE);
207 return NULL;
208 }
209 oct = SXNET_get_id_INTEGER(sx, izone);
210 ASN1_INTEGER_free(izone);
211 return oct;
212}
213
214ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
215{
216 ASN1_INTEGER *izone;
217 ASN1_OCTET_STRING *oct;
218
219 if ((izone = ASN1_INTEGER_new()) == NULL
220 || !ASN1_INTEGER_set(izone, lzone)) {
221 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
222 ASN1_INTEGER_free(izone);
223 return NULL;
224 }
225 oct = SXNET_get_id_INTEGER(sx, izone);
226 ASN1_INTEGER_free(izone);
227 return oct;
228}
229
230ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
231{
232 SXNETID *id;
233 int i;
234 for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
235 id = sk_SXNETID_value(sx->ids, i);
236 if (!ASN1_INTEGER_cmp(id->zone, zone))
237 return id->user;
238 }
239 return NULL;
240}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette