2 * Copyright 1999-2024 The OpenSSL Project Authors. All Rights Reserved.
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
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>
18 /* Support for Thawte strong extranet extension */
22 static int sxnet_i2r(X509V3_EXT_METHOD
*method
, SXNET
*sx
, BIO
*out
,
25 static SXNET
*sxnet_v2i(X509V3_EXT_METHOD
*method
, X509V3_CTX
*ctx
,
26 STACK_OF(CONF_VALUE
) *nval
);
28 const X509V3_EXT_METHOD ossl_v3_sxnet
= {
29 NID_sxnet
, X509V3_EXT_MULTILINE
, ASN1_ITEM_ref(SXNET
),
34 (X509V3_EXT_V2I
)sxnet_v2i
,
38 (X509V3_EXT_I2R
)sxnet_i2r
,
43 ASN1_SEQUENCE(SXNETID
) = {
44 ASN1_SIMPLE(SXNETID
, zone
, ASN1_INTEGER
),
45 ASN1_SIMPLE(SXNETID
, user
, ASN1_OCTET_STRING
)
46 } ASN1_SEQUENCE_END(SXNETID
)
48 IMPLEMENT_ASN1_FUNCTIONS(SXNETID
)
50 ASN1_SEQUENCE(SXNET
) = {
51 ASN1_SIMPLE(SXNET
, version
, ASN1_INTEGER
),
52 ASN1_SEQUENCE_OF(SXNET
, ids
, SXNETID
)
53 } ASN1_SEQUENCE_END(SXNET
)
55 IMPLEMENT_ASN1_FUNCTIONS(SXNET
)
57 static int sxnet_i2r(X509V3_EXT_METHOD
*method
, SXNET
*sx
, BIO
*out
,
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.
69 if (!ASN1_INTEGER_get_int64(&v
, sx
->version
)
72 BIO_printf(out
, "%*sVersion: <unsupported>", indent
, "");
76 BIO_printf(out
, "%*sVersion: %ld (0x%lX)", indent
, "", vl
+ 1, vl
);
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
);
83 BIO_printf(out
, "\n%*sZone: %s, User: ", indent
, "", tmp
);
85 ASN1_STRING_print(out
, id
->user
);
93 * NBB: this is used for testing only. It should *not* be used for anything
94 * else because it will just take static IDs from the configuration file and
95 * they should really be separate values for each user.
98 static SXNET
*sxnet_v2i(X509V3_EXT_METHOD
*method
, X509V3_CTX
*ctx
,
99 STACK_OF(CONF_VALUE
) *nval
)
104 for (i
= 0; i
< sk_CONF_VALUE_num(nval
); i
++) {
105 cnf
= sk_CONF_VALUE_value(nval
, i
);
106 if (!SXNET_add_id_asc(&sx
, cnf
->name
, cnf
->value
, -1)) {
116 /* Strong Extranet utility functions */
118 /* Add an id given the zone as an ASCII number */
120 int SXNET_add_id_asc(SXNET
**psx
, const char *zone
, const char *user
, int userlen
)
124 if ((izone
= s2i_ASN1_INTEGER(NULL
, zone
)) == NULL
) {
125 ERR_raise(ERR_LIB_X509V3
, X509V3_R_ERROR_CONVERTING_ZONE
);
128 if (!SXNET_add_id_INTEGER(psx
, izone
, user
, userlen
)) {
129 ASN1_INTEGER_free(izone
);
135 /* Add an id given the zone as an unsigned long */
137 int SXNET_add_id_ulong(SXNET
**psx
, unsigned long lzone
, const char *user
,
142 if ((izone
= ASN1_INTEGER_new()) == NULL
143 || !ASN1_INTEGER_set(izone
, lzone
)) {
144 ERR_raise(ERR_LIB_X509V3
, ERR_R_ASN1_LIB
);
145 ASN1_INTEGER_free(izone
);
148 if (!SXNET_add_id_INTEGER(psx
, izone
, user
, userlen
)) {
149 ASN1_INTEGER_free(izone
);
156 * Add an id given the zone as an ASN1_INTEGER. Note this version uses the
157 * passed integer and doesn't make a copy so don't free it up afterwards.
160 int SXNET_add_id_INTEGER(SXNET
**psx
, ASN1_INTEGER
*zone
, const char *user
,
166 if (psx
== NULL
|| zone
== NULL
|| user
== NULL
) {
167 ERR_raise(ERR_LIB_X509V3
, X509V3_R_INVALID_NULL_ARGUMENT
);
171 userlen
= strlen(user
);
173 ERR_raise(ERR_LIB_X509V3
, X509V3_R_USER_TOO_LONG
);
177 if ((sx
= SXNET_new()) == NULL
) {
178 ERR_raise(ERR_LIB_X509V3
, ERR_R_ASN1_LIB
);
181 if (!ASN1_INTEGER_set(sx
->version
, 0)) {
182 ERR_raise(ERR_LIB_X509V3
, ERR_R_ASN1_LIB
);
187 if (SXNET_get_id_INTEGER(sx
, zone
)) {
188 ERR_raise(ERR_LIB_X509V3
, X509V3_R_DUPLICATE_ZONE_ID
);
194 if ((id
= SXNETID_new()) == NULL
) {
195 ERR_raise(ERR_LIB_X509V3
, ERR_R_ASN1_LIB
);
199 if (!ASN1_OCTET_STRING_set(id
->user
, (const unsigned char *)user
, userlen
)){
200 ERR_raise(ERR_LIB_X509V3
, ERR_R_ASN1_LIB
);
203 if (!sk_SXNETID_push(sx
->ids
, id
)) {
204 ERR_raise(ERR_LIB_X509V3
, ERR_R_CRYPTO_LIB
);
207 ASN1_INTEGER_free(id
->zone
);
219 ASN1_OCTET_STRING
*SXNET_get_id_asc(SXNET
*sx
, const char *zone
)
222 ASN1_OCTET_STRING
*oct
;
224 if ((izone
= s2i_ASN1_INTEGER(NULL
, zone
)) == NULL
) {
225 ERR_raise(ERR_LIB_X509V3
, X509V3_R_ERROR_CONVERTING_ZONE
);
228 oct
= SXNET_get_id_INTEGER(sx
, izone
);
229 ASN1_INTEGER_free(izone
);
233 ASN1_OCTET_STRING
*SXNET_get_id_ulong(SXNET
*sx
, unsigned long lzone
)
236 ASN1_OCTET_STRING
*oct
;
238 if ((izone
= ASN1_INTEGER_new()) == NULL
239 || !ASN1_INTEGER_set(izone
, lzone
)) {
240 ERR_raise(ERR_LIB_X509V3
, ERR_R_ASN1_LIB
);
241 ASN1_INTEGER_free(izone
);
244 oct
= SXNET_get_id_INTEGER(sx
, izone
);
245 ASN1_INTEGER_free(izone
);
249 ASN1_OCTET_STRING
*SXNET_get_id_INTEGER(SXNET
*sx
, ASN1_INTEGER
*zone
)
253 for (i
= 0; i
< sk_SXNETID_num(sx
->ids
); i
++) {
254 id
= sk_SXNETID_value(sx
->ids
, i
);
255 if (!ASN1_INTEGER_cmp(id
->zone
, zone
))