2008-11-06 02:39:08 +08:00
|
|
|
/*
|
2024-03-20 20:07:54 +08:00
|
|
|
* Copyright 1999-2024 The OpenSSL Project Authors. All Rights Reserved.
|
1999-03-27 22:07:44 +08:00
|
|
|
*
|
2018-12-06 21:00:54 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:26 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1999-03-27 22:07:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/conf.h>
|
|
|
|
#include <openssl/asn1.h>
|
2000-12-09 03:09:35 +08:00
|
|
|
#include <openssl/asn1t.h>
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/x509v3.h>
|
2015-09-05 20:32:58 +08:00
|
|
|
#include "ext_dat.h"
|
1999-03-27 22:07:44 +08:00
|
|
|
|
|
|
|
/* Support for Thawte strong extranet extension */
|
|
|
|
|
1999-04-15 07:44:41 +08:00
|
|
|
#define SXNET_TEST
|
|
|
|
|
1999-03-27 22:07:44 +08:00
|
|
|
static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
|
|
|
|
int indent);
|
1999-04-15 07:44:41 +08:00
|
|
|
#ifdef SXNET_TEST
|
1999-06-22 07:59:09 +08:00
|
|
|
static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
|
|
|
|
STACK_OF(CONF_VALUE) *nval);
|
1999-04-15 07:44:41 +08:00
|
|
|
#endif
|
2021-03-09 08:52:15 +08:00
|
|
|
const X509V3_EXT_METHOD ossl_v3_sxnet = {
|
2001-02-23 11:16:09 +08:00
|
|
|
NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET),
|
2000-12-13 21:47:33 +08:00
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0,
|
|
|
|
0,
|
1999-04-15 07:44:41 +08:00
|
|
|
#ifdef SXNET_TEST
|
|
|
|
(X509V3_EXT_V2I)sxnet_v2i,
|
|
|
|
#else
|
2000-12-13 21:47:33 +08:00
|
|
|
0,
|
1999-04-15 07:44:41 +08:00
|
|
|
#endif
|
1999-03-27 22:07:44 +08:00
|
|
|
(X509V3_EXT_I2R)sxnet_i2r,
|
2000-12-13 21:47:33 +08:00
|
|
|
0,
|
1999-03-27 22:07:44 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
ASN1_SEQUENCE(SXNETID) = {
|
|
|
|
ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER),
|
|
|
|
ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING)
|
2001-02-23 20:47:06 +08:00
|
|
|
} ASN1_SEQUENCE_END(SXNETID)
|
1999-03-27 22:07:44 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(SXNETID)
|
1999-03-27 22:07:44 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
ASN1_SEQUENCE(SXNET) = {
|
|
|
|
ASN1_SIMPLE(SXNET, version, ASN1_INTEGER),
|
|
|
|
ASN1_SEQUENCE_OF(SXNET, ids, SXNETID)
|
2001-02-23 20:47:06 +08:00
|
|
|
} ASN1_SEQUENCE_END(SXNET)
|
1999-03-27 22:07:44 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(SXNET)
|
1999-03-27 22:07:44 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
|
|
|
|
int indent)
|
1999-03-27 22:07:44 +08:00
|
|
|
{
|
2020-11-19 21:58:21 +08:00
|
|
|
int64_t v;
|
1999-03-27 22:07:44 +08:00
|
|
|
char *tmp;
|
|
|
|
SXNETID *id;
|
|
|
|
int i;
|
2020-11-19 21:58:21 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we add 1 to the version number to display it, we don't support
|
|
|
|
* LONG_MAX since that would cause on overflow.
|
|
|
|
*/
|
|
|
|
if (!ASN1_INTEGER_get_int64(&v, sx->version)
|
|
|
|
|| v >= LONG_MAX
|
|
|
|
|| v < LONG_MIN) {
|
|
|
|
BIO_printf(out, "%*sVersion: <unsupported>", indent, "");
|
|
|
|
} else {
|
|
|
|
long vl = (long)v;
|
|
|
|
|
|
|
|
BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", vl + 1, vl);
|
|
|
|
}
|
1999-04-17 18:28:46 +08:00
|
|
|
for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
|
|
|
|
id = sk_SXNETID_value(sx->ids, i);
|
1999-03-27 22:07:44 +08:00
|
|
|
tmp = i2s_ASN1_INTEGER(NULL, id->zone);
|
2022-06-20 17:46:39 +08:00
|
|
|
if (tmp == NULL)
|
|
|
|
return 0;
|
1999-03-27 22:07:44 +08:00
|
|
|
BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
|
2000-06-02 06:19:21 +08:00
|
|
|
OPENSSL_free(tmp);
|
2015-03-14 12:16:42 +08:00
|
|
|
ASN1_STRING_print(out, id->user);
|
1999-03-27 22:07:44 +08:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
1999-04-15 07:44:41 +08:00
|
|
|
|
|
|
|
#ifdef SXNET_TEST
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NBB: this is used for testing only. It should *not* be used for anything
|
|
|
|
* else because it will just take static IDs from the configuration file and
|
|
|
|
* they should really be separate values for each user.
|
|
|
|
*/
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static SXNET *sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
|
1999-06-22 07:59:09 +08:00
|
|
|
STACK_OF(CONF_VALUE) *nval)
|
1999-04-15 07:44:41 +08:00
|
|
|
{
|
|
|
|
CONF_VALUE *cnf;
|
|
|
|
SXNET *sx = NULL;
|
|
|
|
int i;
|
1999-06-22 07:59:09 +08:00
|
|
|
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
|
|
|
|
cnf = sk_CONF_VALUE_value(nval, i);
|
2024-01-08 22:31:32 +08:00
|
|
|
if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1)) {
|
|
|
|
SXNET_free(sx);
|
1999-04-15 07:44:41 +08:00
|
|
|
return NULL;
|
2024-01-08 22:31:32 +08:00
|
|
|
}
|
1999-04-15 07:44:41 +08:00
|
|
|
}
|
|
|
|
return sx;
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
1999-04-15 07:44:41 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Strong Extranet utility functions */
|
|
|
|
|
|
|
|
/* Add an id given the zone as an ASCII number */
|
|
|
|
|
2016-06-20 00:32:47 +08:00
|
|
|
int SXNET_add_id_asc(SXNET **psx, const char *zone, const char *user, int userlen)
|
1999-04-15 07:44:41 +08:00
|
|
|
{
|
2015-05-07 01:43:59 +08:00
|
|
|
ASN1_INTEGER *izone;
|
|
|
|
|
|
|
|
if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, X509V3_R_ERROR_CONVERTING_ZONE);
|
1999-04-15 07:44:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2024-01-05 18:01:34 +08:00
|
|
|
if (!SXNET_add_id_INTEGER(psx, izone, user, userlen)) {
|
|
|
|
ASN1_INTEGER_free(izone);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
1999-04-15 07:44:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add an id given the zone as an unsigned long */
|
|
|
|
|
2016-06-20 00:32:47 +08:00
|
|
|
int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, const char *user,
|
1999-04-20 05:31:43 +08:00
|
|
|
int userlen)
|
1999-04-15 07:44:41 +08:00
|
|
|
{
|
2015-05-07 01:43:59 +08:00
|
|
|
ASN1_INTEGER *izone;
|
|
|
|
|
|
|
|
if ((izone = ASN1_INTEGER_new()) == NULL
|
|
|
|
|| !ASN1_INTEGER_set(izone, lzone)) {
|
2022-09-29 19:57:34 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
|
2015-03-14 12:16:42 +08:00
|
|
|
ASN1_INTEGER_free(izone);
|
1999-04-15 07:44:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2024-01-05 18:01:34 +08:00
|
|
|
if (!SXNET_add_id_INTEGER(psx, izone, user, userlen)) {
|
|
|
|
ASN1_INTEGER_free(izone);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
1999-04-15 07:44:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add an id given the zone as an ASN1_INTEGER. Note this version uses the
|
|
|
|
* passed integer and doesn't make a copy so don't free it up afterwards.
|
|
|
|
*/
|
|
|
|
|
2016-06-20 00:32:47 +08:00
|
|
|
int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, const char *user,
|
1999-04-20 05:31:43 +08:00
|
|
|
int userlen)
|
1999-04-15 07:44:41 +08:00
|
|
|
{
|
|
|
|
SXNET *sx = NULL;
|
|
|
|
SXNETID *id = NULL;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
|
|
|
if (psx == NULL || zone == NULL || user == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, X509V3_R_INVALID_NULL_ARGUMENT);
|
1999-04-15 07:44:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (userlen == -1)
|
|
|
|
userlen = strlen(user);
|
|
|
|
if (userlen > 64) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, X509V3_R_USER_TOO_LONG);
|
1999-04-15 07:44:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-07 01:43:59 +08:00
|
|
|
if (*psx == NULL) {
|
2022-09-29 19:57:34 +08:00
|
|
|
if ((sx = SXNET_new()) == NULL) {
|
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
|
1999-04-15 07:44:41 +08:00
|
|
|
goto err;
|
2022-09-29 19:57:34 +08:00
|
|
|
}
|
|
|
|
if (!ASN1_INTEGER_set(sx->version, 0)) {
|
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
|
1999-04-15 07:44:41 +08:00
|
|
|
goto err;
|
2022-09-29 19:57:34 +08:00
|
|
|
}
|
1999-04-15 07:44:41 +08:00
|
|
|
} else
|
|
|
|
sx = *psx;
|
|
|
|
if (SXNET_get_id_INTEGER(sx, zone)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, X509V3_R_DUPLICATE_ZONE_ID);
|
2022-01-05 23:17:53 +08:00
|
|
|
if (*psx == NULL)
|
|
|
|
SXNET_free(sx);
|
1999-04-15 07:44:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-29 19:57:34 +08:00
|
|
|
if ((id = SXNETID_new()) == NULL) {
|
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
|
1999-04-15 07:44:41 +08:00
|
|
|
goto err;
|
2022-09-29 19:57:34 +08:00
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2022-09-29 19:57:34 +08:00
|
|
|
if (!ASN1_OCTET_STRING_set(id->user, (const unsigned char *)user, userlen)){
|
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
|
1999-04-17 18:28:46 +08:00
|
|
|
goto err;
|
2022-09-29 19:57:34 +08:00
|
|
|
}
|
|
|
|
if (!sk_SXNETID_push(sx->ids, id)) {
|
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_CRYPTO_LIB);
|
1999-10-20 09:50:23 +08:00
|
|
|
goto err;
|
2022-09-29 19:57:34 +08:00
|
|
|
}
|
2024-01-09 22:05:30 +08:00
|
|
|
ASN1_INTEGER_free(id->zone);
|
1999-04-15 07:44:41 +08:00
|
|
|
id->zone = zone;
|
2022-01-05 23:17:53 +08:00
|
|
|
*psx = sx;
|
1999-04-15 07:44:41 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
1999-04-15 07:44:41 +08:00
|
|
|
err:
|
|
|
|
SXNETID_free(id);
|
2022-01-05 23:17:53 +08:00
|
|
|
if (*psx == NULL)
|
|
|
|
SXNET_free(sx);
|
1999-04-15 07:44:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-20 00:32:47 +08:00
|
|
|
ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, const char *zone)
|
1999-04-15 07:44:41 +08:00
|
|
|
{
|
2015-05-07 01:43:59 +08:00
|
|
|
ASN1_INTEGER *izone;
|
1999-04-15 07:44:41 +08:00
|
|
|
ASN1_OCTET_STRING *oct;
|
2015-05-07 01:43:59 +08:00
|
|
|
|
|
|
|
if ((izone = s2i_ASN1_INTEGER(NULL, zone)) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, X509V3_R_ERROR_CONVERTING_ZONE);
|
1999-04-15 07:44:41 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
oct = SXNET_get_id_INTEGER(sx, izone);
|
2015-03-14 12:16:42 +08:00
|
|
|
ASN1_INTEGER_free(izone);
|
1999-04-15 07:44:41 +08:00
|
|
|
return oct;
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
|
1999-04-15 07:44:41 +08:00
|
|
|
{
|
2015-05-07 01:43:59 +08:00
|
|
|
ASN1_INTEGER *izone;
|
1999-04-15 07:44:41 +08:00
|
|
|
ASN1_OCTET_STRING *oct;
|
2015-05-07 01:43:59 +08:00
|
|
|
|
|
|
|
if ((izone = ASN1_INTEGER_new()) == NULL
|
|
|
|
|| !ASN1_INTEGER_set(izone, lzone)) {
|
2022-09-29 19:57:34 +08:00
|
|
|
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
|
2015-03-14 12:16:42 +08:00
|
|
|
ASN1_INTEGER_free(izone);
|
1999-04-15 07:44:41 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
oct = SXNET_get_id_INTEGER(sx, izone);
|
2015-03-14 12:16:42 +08:00
|
|
|
ASN1_INTEGER_free(izone);
|
1999-04-15 07:44:41 +08:00
|
|
|
return oct;
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
|
1999-04-15 07:44:41 +08:00
|
|
|
{
|
|
|
|
SXNETID *id;
|
|
|
|
int i;
|
1999-04-17 18:28:46 +08:00
|
|
|
for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
|
|
|
|
id = sk_SXNETID_value(sx->ids, i);
|
2015-03-14 12:16:42 +08:00
|
|
|
if (!ASN1_INTEGER_cmp(id->zone, zone))
|
1999-10-20 09:50:23 +08:00
|
|
|
return id->user;
|
1999-04-15 07:44:41 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|