diff options
author | Nicola Tuveri <nic.tuv@gmail.com> | 2020-09-28 01:05:27 +0300 |
---|---|---|
committer | Nicola Tuveri <nic.tuv@gmail.com> | 2020-10-14 18:42:58 +0300 |
commit | 32fea070dc679f656a9e3d152aa570f6b658bc8e (patch) | |
tree | f138781e49838205dd92ab87c533e5a5a805a206 /test | |
parent | 47690cd4ceb3a1cfdf097d575cb0d3cf9c6dac13 (diff) |
[test][tls-provider] Group xor_group properties in a struct
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13018)
Diffstat (limited to 'test')
-rw-r--r-- | test/tls-provider.c | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/test/tls-provider.c b/test/tls-provider.c index 924ede501b..1e010d2405 100644 --- a/test/tls-provider.c +++ b/test/tls-provider.c @@ -42,31 +42,43 @@ typedef struct xorkey_st { } XORKEY; /* We define a dummy TLS group called "xorgroup" for test purposes */ +struct tls_group_st { + unsigned int group_id; /* for "tls-group-id", see provider-base(7) */ + unsigned int secbits; + unsigned int mintls; + unsigned int maxtls; + unsigned int mindtls; + unsigned int maxdtls; +}; -static unsigned int group_id = 0; /* IANA reserved for private use */ -static unsigned int secbits = 128; -static unsigned int mintls = TLS1_3_VERSION; -static unsigned int maxtls = 0; -static unsigned int mindtls = -1; -static unsigned int maxdtls = -1; +#define XORGROUP_NAME "xorgroup" +#define XORGROUP_NAME_INTERNAL "xorgroup-int" +static struct tls_group_st xor_group = { + 0, /* group_id, set by randomize_tls_group_id() */ + 128, /* secbits */ + TLS1_3_VERSION, /* mintls */ + 0, /* maxtls */ + -1, /* mindtls */ + -1 /* maxdtls */ +}; -#define GROUP_NAME "xorgroup" -#define GROUP_NAME_INTERNAL "xorgroup-int" #define ALGORITHM "XOR" static const OSSL_PARAM xor_group_params[] = { OSSL_PARAM_utf8_string(OSSL_CAPABILITY_TLS_GROUP_NAME, - GROUP_NAME, sizeof(GROUP_NAME)), + XORGROUP_NAME, sizeof(XORGROUP_NAME)), OSSL_PARAM_utf8_string(OSSL_CAPABILITY_TLS_GROUP_NAME_INTERNAL, - GROUP_NAME_INTERNAL, sizeof(GROUP_NAME_INTERNAL)), + XORGROUP_NAME_INTERNAL, + sizeof(XORGROUP_NAME_INTERNAL)), OSSL_PARAM_utf8_string(OSSL_CAPABILITY_TLS_GROUP_ALG, ALGORITHM, sizeof(ALGORITHM)), - OSSL_PARAM_uint(OSSL_CAPABILITY_TLS_GROUP_ID, &group_id), - OSSL_PARAM_uint(OSSL_CAPABILITY_TLS_GROUP_SECURITY_BITS, &secbits), - OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MIN_TLS, &mintls), - OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MAX_TLS, &maxtls), - OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MIN_DTLS, &mindtls), - OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MAX_DTLS, &maxdtls), + OSSL_PARAM_uint(OSSL_CAPABILITY_TLS_GROUP_ID, &xor_group.group_id), + OSSL_PARAM_uint(OSSL_CAPABILITY_TLS_GROUP_SECURITY_BITS, + &xor_group.secbits), + OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MIN_TLS, &xor_group.mintls), + OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MAX_TLS, &xor_group.maxtls), + OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MIN_DTLS, &xor_group.mindtls), + OSSL_PARAM_int(OSSL_CAPABILITY_TLS_GROUP_MAX_DTLS, &xor_group.maxdtls), OSSL_PARAM_END }; @@ -269,7 +281,7 @@ static ossl_inline int xor_get_params(void *vkey, OSSL_PARAM params[]) return 0; if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_SECURITY_BITS)) != NULL - && !OSSL_PARAM_set_int(p, secbits)) + && !OSSL_PARAM_set_int(p, xor_group.secbits)) return 0; if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_TLS_ENCODED_PT)) != NULL) { @@ -355,7 +367,7 @@ static int xor_gen_set_params(void *genctx, const OSSL_PARAM params[]) p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_GROUP_NAME); if (p != NULL) { if (p->data_type != OSSL_PARAM_UTF8_STRING - || strcmp(p->data, GROUP_NAME_INTERNAL) != 0) + || strcmp(p->data, XORGROUP_NAME_INTERNAL) != 0) return 0; } @@ -447,19 +459,15 @@ static const OSSL_DISPATCH tls_prov_dispatch_table[] = { { 0, NULL } }; -int tls_provider_init(const OSSL_CORE_HANDLE *handle, - const OSSL_DISPATCH *in, - const OSSL_DISPATCH **out, - void **provctx) +static +unsigned int randomize_tls_group_id(OPENSSL_CTX *libctx) { - OPENSSL_CTX *libctx = OPENSSL_CTX_new(); - - *provctx = libctx; - /* * Randomise the group_id we're going to use to ensure we don't interoperate * with anything but ourselves. */ + unsigned int group_id; + if (!RAND_bytes_ex(libctx, (unsigned char *)&group_id, sizeof(group_id))) return 0; /* @@ -469,6 +477,24 @@ int tls_provider_init(const OSSL_CORE_HANDLE *handle, group_id %= 65279 - 65024; group_id += 65024; + return group_id; +} + +int tls_provider_init(const OSSL_CORE_HANDLE *handle, + const OSSL_DISPATCH *in, + const OSSL_DISPATCH **out, + void **provctx) +{ + OPENSSL_CTX *libctx = OPENSSL_CTX_new(); + + *provctx = libctx; + + /* + * Randomise the group_id we're going to use to ensure we don't interoperate + * with anything but ourselves. + */ + xor_group.group_id = randomize_tls_group_id(libctx); + *out = tls_prov_dispatch_table; return 1; } |