2 * Copyright 1999-2020 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 DEFINE_STACK_OF(SXNETID
)
19 DEFINE_STACK_OF(CONF_VALUE
)
21 /* Support for Thawte strong extranet extension */
25 static int sxnet_i2r(X509V3_EXT_METHOD
*method
, SXNET
*sx
, BIO
*out
,
28 static SXNET
*sxnet_v2i(X509V3_EXT_METHOD
*method
, X509V3_CTX
*ctx
,
29 STACK_OF(CONF_VALUE
) *nval
);
31 const X509V3_EXT_METHOD v3_sxnet
= {
32 NID_sxnet
, X509V3_EXT_MULTILINE
, ASN1_ITEM_ref(SXNET
),
37 (X509V3_EXT_V2I
)sxnet_v2i
,
41 (X509V3_EXT_I2R
)sxnet_i2r
,
46 ASN1_SEQUENCE(SXNETID
) = {
47 ASN1_SIMPLE(SXNETID
, zone
, ASN1_INTEGER
),
48 ASN1_SIMPLE(SXNETID
, user
, ASN1_OCTET_STRING
)
49 } ASN1_SEQUENCE_END(SXNETID
)
51 IMPLEMENT_ASN1_FUNCTIONS(SXNETID
)
53 ASN1_SEQUENCE(SXNET
) = {
54 ASN1_SIMPLE(SXNET
, version
, ASN1_INTEGER
),
55 ASN1_SEQUENCE_OF(SXNET
, ids
, SXNETID
)
56 } ASN1_SEQUENCE_END(SXNET
)
58 IMPLEMENT_ASN1_FUNCTIONS(SXNET
)
60 static int sxnet_i2r(X509V3_EXT_METHOD
*method
, SXNET
*sx
, BIO
*out
,
67 v
= ASN1_INTEGER_get(sx
->version
);
68 BIO_printf(out
, "%*sVersion: %ld (0x%lX)", indent
, "", v
+ 1, v
);
69 for (i
= 0; i
< sk_SXNETID_num(sx
->ids
); i
++) {
70 id
= sk_SXNETID_value(sx
->ids
, i
);
71 tmp
= i2s_ASN1_INTEGER(NULL
, id
->zone
);
72 BIO_printf(out
, "\n%*sZone: %s, User: ", indent
, "", tmp
);
74 ASN1_STRING_print(out
, id
->user
);
82 * NBB: this is used for testing only. It should *not* be used for anything
83 * else because it will just take static IDs from the configuration file and
84 * they should really be separate values for each user.
87 static SXNET
*sxnet_v2i(X509V3_EXT_METHOD
*method
, X509V3_CTX
*ctx
,
88 STACK_OF(CONF_VALUE
) *nval
)
93 for (i
= 0; i
< sk_CONF_VALUE_num(nval
); i
++) {
94 cnf
= sk_CONF_VALUE_value(nval
, i
);
95 if (!SXNET_add_id_asc(&sx
, cnf
->name
, cnf
->value
, -1))
103 /* Strong Extranet utility functions */
105 /* Add an id given the zone as an ASCII number */
107 int SXNET_add_id_asc(SXNET
**psx
, const char *zone
, const char *user
, int userlen
)
111 if ((izone
= s2i_ASN1_INTEGER(NULL
, zone
)) == NULL
) {
112 X509V3err(X509V3_F_SXNET_ADD_ID_ASC
, X509V3_R_ERROR_CONVERTING_ZONE
);
115 return SXNET_add_id_INTEGER(psx
, izone
, user
, userlen
);
118 /* Add an id given the zone as an unsigned long */
120 int SXNET_add_id_ulong(SXNET
**psx
, unsigned long lzone
, const char *user
,
125 if ((izone
= ASN1_INTEGER_new()) == NULL
126 || !ASN1_INTEGER_set(izone
, lzone
)) {
127 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG
, ERR_R_MALLOC_FAILURE
);
128 ASN1_INTEGER_free(izone
);
131 return SXNET_add_id_INTEGER(psx
, izone
, user
, userlen
);
136 * Add an id given the zone as an ASN1_INTEGER. Note this version uses the
137 * passed integer and doesn't make a copy so don't free it up afterwards.
140 int SXNET_add_id_INTEGER(SXNET
**psx
, ASN1_INTEGER
*zone
, const char *user
,
146 if (psx
== NULL
|| zone
== NULL
|| user
== NULL
) {
147 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER
,
148 X509V3_R_INVALID_NULL_ARGUMENT
);
152 userlen
= strlen(user
);
154 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER
, X509V3_R_USER_TOO_LONG
);
158 if ((sx
= SXNET_new()) == NULL
)
160 if (!ASN1_INTEGER_set(sx
->version
, 0))
165 if (SXNET_get_id_INTEGER(sx
, zone
)) {
166 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER
, X509V3_R_DUPLICATE_ZONE_ID
);
170 if ((id
= SXNETID_new()) == NULL
)
173 userlen
= strlen(user
);
175 if (!ASN1_OCTET_STRING_set(id
->user
, (const unsigned char *)user
, userlen
))
177 if (!sk_SXNETID_push(sx
->ids
, id
))
183 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER
, ERR_R_MALLOC_FAILURE
);
190 ASN1_OCTET_STRING
*SXNET_get_id_asc(SXNET
*sx
, const char *zone
)
193 ASN1_OCTET_STRING
*oct
;
195 if ((izone
= s2i_ASN1_INTEGER(NULL
, zone
)) == NULL
) {
196 X509V3err(X509V3_F_SXNET_GET_ID_ASC
, X509V3_R_ERROR_CONVERTING_ZONE
);
199 oct
= SXNET_get_id_INTEGER(sx
, izone
);
200 ASN1_INTEGER_free(izone
);
204 ASN1_OCTET_STRING
*SXNET_get_id_ulong(SXNET
*sx
, unsigned long lzone
)
207 ASN1_OCTET_STRING
*oct
;
209 if ((izone
= ASN1_INTEGER_new()) == NULL
210 || !ASN1_INTEGER_set(izone
, lzone
)) {
211 X509V3err(X509V3_F_SXNET_GET_ID_ULONG
, ERR_R_MALLOC_FAILURE
);
212 ASN1_INTEGER_free(izone
);
215 oct
= SXNET_get_id_INTEGER(sx
, izone
);
216 ASN1_INTEGER_free(izone
);
220 ASN1_OCTET_STRING
*SXNET_get_id_INTEGER(SXNET
*sx
, ASN1_INTEGER
*zone
)
224 for (i
= 0; i
< sk_SXNETID_num(sx
->ids
); i
++) {
225 id
= sk_SXNETID_value(sx
->ids
, i
);
226 if (!ASN1_INTEGER_cmp(id
->zone
, zone
))