Import OpenSSL 1.1.1l
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include "internal/numbers.h"
|
||||
#include "testutil.h"
|
||||
|
||||
@@ -195,6 +196,30 @@ static int test_invalid_template(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_reuse_asn1_object(void)
|
||||
{
|
||||
static unsigned char cn_der[] = { 0x06, 0x03, 0x55, 0x04, 0x06 };
|
||||
static unsigned char oid_der[] = {
|
||||
0x06, 0x06, 0x2a, 0x03, 0x04, 0x05, 0x06, 0x07
|
||||
};
|
||||
int ret = 0;
|
||||
ASN1_OBJECT *obj;
|
||||
unsigned char const *p = oid_der;
|
||||
|
||||
/* Create an object that owns dynamically allocated 'sn' and 'ln' fields */
|
||||
|
||||
if (!TEST_ptr(obj = ASN1_OBJECT_create(NID_undef, cn_der, sizeof(cn_der),
|
||||
"C", "countryName")))
|
||||
goto err;
|
||||
/* reuse obj - this should not leak sn and ln */
|
||||
if (!TEST_ptr(d2i_ASN1_OBJECT(&obj, &p, sizeof(oid_der))))
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
ASN1_OBJECT_free(obj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
#if OPENSSL_API_COMPAT < 0x10200000L
|
||||
@@ -205,5 +230,6 @@ int setup_tests(void)
|
||||
ADD_TEST(test_int64);
|
||||
ADD_TEST(test_uint64);
|
||||
ADD_TEST(test_invalid_template);
|
||||
ADD_TEST(test_reuse_asn1_object);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <string.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/pkcs7.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
|
||||
#include "testutil.h"
|
||||
|
||||
@@ -35,7 +37,7 @@ static int test_bio_memleak(void)
|
||||
goto finish;
|
||||
ok = 1;
|
||||
|
||||
finish:
|
||||
finish:
|
||||
BIO_free(bio);
|
||||
return ok;
|
||||
}
|
||||
@@ -62,7 +64,7 @@ static int test_bio_get_mem(void)
|
||||
goto finish;
|
||||
ok = 1;
|
||||
|
||||
finish:
|
||||
finish:
|
||||
BIO_free(bio);
|
||||
BUF_MEM_free(bufmem);
|
||||
return ok;
|
||||
@@ -98,7 +100,7 @@ static int test_bio_new_mem_buf(void)
|
||||
goto finish;
|
||||
ok = 1;
|
||||
|
||||
finish:
|
||||
finish:
|
||||
BIO_free(bio);
|
||||
return ok;
|
||||
}
|
||||
@@ -139,7 +141,7 @@ static int test_bio_rdonly_mem_buf(void)
|
||||
goto finish;
|
||||
ok = 1;
|
||||
|
||||
finish:
|
||||
finish:
|
||||
BIO_free(bio);
|
||||
BIO_free(bio2);
|
||||
return ok;
|
||||
@@ -176,7 +178,7 @@ static int test_bio_rdwr_rdonly(void)
|
||||
|
||||
ok = 1;
|
||||
|
||||
finish:
|
||||
finish:
|
||||
BIO_free(bio);
|
||||
return ok;
|
||||
}
|
||||
@@ -216,11 +218,72 @@ static int test_bio_nonclear_rst(void)
|
||||
|
||||
ok = 1;
|
||||
|
||||
finish:
|
||||
finish:
|
||||
BIO_free(bio);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int error_callback_fired;
|
||||
static long BIO_error_callback(BIO *bio, int cmd, const char *argp,
|
||||
size_t len, int argi,
|
||||
long argl, int ret, size_t *processed)
|
||||
{
|
||||
if ((cmd & (BIO_CB_READ | BIO_CB_RETURN)) != 0) {
|
||||
error_callback_fired = 1;
|
||||
ret = 0; /* fail for read operations to simulate error in input BIO */
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Checks i2d_ASN1_bio_stream() is freeing all memory when input BIO ends unexpectedly. */
|
||||
static int test_bio_i2d_ASN1_mime(void)
|
||||
{
|
||||
int ok = 0;
|
||||
BIO *bio = NULL, *out = NULL;
|
||||
BUF_MEM bufmem;
|
||||
static const char str[] = "BIO mime test\n";
|
||||
PKCS7 *p7 = NULL;
|
||||
|
||||
if (!TEST_ptr(bio = BIO_new(BIO_s_mem())))
|
||||
goto finish;
|
||||
|
||||
bufmem.length = sizeof(str);
|
||||
bufmem.data = (char *) str;
|
||||
bufmem.max = bufmem.length;
|
||||
BIO_set_mem_buf(bio, &bufmem, BIO_NOCLOSE);
|
||||
BIO_set_flags(bio, BIO_FLAGS_MEM_RDONLY);
|
||||
BIO_set_callback_ex(bio, BIO_error_callback);
|
||||
|
||||
if (!TEST_ptr(out = BIO_new(BIO_s_mem())))
|
||||
goto finish;
|
||||
if (!TEST_ptr(p7 = PKCS7_new()))
|
||||
goto finish;
|
||||
if (!TEST_true(PKCS7_set_type(p7, NID_pkcs7_data)))
|
||||
goto finish;
|
||||
|
||||
error_callback_fired = 0;
|
||||
|
||||
/*
|
||||
* The call succeeds even if the input stream ends unexpectedly as
|
||||
* there is no handling for this case in SMIME_crlf_copy().
|
||||
*/
|
||||
if (!TEST_true(i2d_ASN1_bio_stream(out, (ASN1_VALUE*) p7, bio,
|
||||
SMIME_STREAM | SMIME_BINARY,
|
||||
ASN1_ITEM_rptr(PKCS7))))
|
||||
goto finish;
|
||||
|
||||
if (!TEST_int_eq(error_callback_fired, 1))
|
||||
goto finish;
|
||||
|
||||
ok = 1;
|
||||
|
||||
finish:
|
||||
BIO_free(bio);
|
||||
BIO_free(out);
|
||||
PKCS7_free(p7);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int global_init(void)
|
||||
{
|
||||
CRYPTO_set_mem_debug(1);
|
||||
@@ -236,5 +299,6 @@ int setup_tests(void)
|
||||
ADD_TEST(test_bio_rdonly_mem_buf);
|
||||
ADD_TEST(test_bio_rdwr_rdonly);
|
||||
ADD_TEST(test_bio_nonclear_rst);
|
||||
ADD_TEST(test_bio_i2d_ASN1_mime);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -305,6 +305,75 @@ static int test_div_recip(void)
|
||||
return st;
|
||||
}
|
||||
|
||||
static struct {
|
||||
int n, divisor, result, remainder;
|
||||
} signed_mod_tests[] = {
|
||||
{ 10, 3, 3, 1 },
|
||||
{ -10, 3, -3, -1 },
|
||||
{ 10, -3, -3, 1 },
|
||||
{ -10, -3, 3, -1 },
|
||||
};
|
||||
|
||||
static BIGNUM *set_signed_bn(int value)
|
||||
{
|
||||
BIGNUM *bn = BN_new();
|
||||
|
||||
if (bn == NULL)
|
||||
return NULL;
|
||||
if (!BN_set_word(bn, value < 0 ? -value : value)) {
|
||||
BN_free(bn);
|
||||
return NULL;
|
||||
}
|
||||
BN_set_negative(bn, value < 0);
|
||||
return bn;
|
||||
}
|
||||
|
||||
static int test_signed_mod_replace_ab(int n)
|
||||
{
|
||||
BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL;
|
||||
int st = 0;
|
||||
|
||||
if (!TEST_ptr(a = set_signed_bn(signed_mod_tests[n].n))
|
||||
|| !TEST_ptr(b = set_signed_bn(signed_mod_tests[n].divisor))
|
||||
|| !TEST_ptr(c = set_signed_bn(signed_mod_tests[n].result))
|
||||
|| !TEST_ptr(d = set_signed_bn(signed_mod_tests[n].remainder)))
|
||||
goto err;
|
||||
|
||||
if (TEST_true(BN_div(a, b, a, b, ctx))
|
||||
&& TEST_BN_eq(a, c)
|
||||
&& TEST_BN_eq(b, d))
|
||||
st = 1;
|
||||
err:
|
||||
BN_free(a);
|
||||
BN_free(b);
|
||||
BN_free(c);
|
||||
BN_free(d);
|
||||
return st;
|
||||
}
|
||||
|
||||
static int test_signed_mod_replace_ba(int n)
|
||||
{
|
||||
BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL;
|
||||
int st = 0;
|
||||
|
||||
if (!TEST_ptr(a = set_signed_bn(signed_mod_tests[n].n))
|
||||
|| !TEST_ptr(b = set_signed_bn(signed_mod_tests[n].divisor))
|
||||
|| !TEST_ptr(c = set_signed_bn(signed_mod_tests[n].result))
|
||||
|| !TEST_ptr(d = set_signed_bn(signed_mod_tests[n].remainder)))
|
||||
goto err;
|
||||
|
||||
if (TEST_true(BN_div(b, a, a, b, ctx))
|
||||
&& TEST_BN_eq(b, c)
|
||||
&& TEST_BN_eq(a, d))
|
||||
st = 1;
|
||||
err:
|
||||
BN_free(a);
|
||||
BN_free(b);
|
||||
BN_free(c);
|
||||
BN_free(d);
|
||||
return st;
|
||||
}
|
||||
|
||||
static int test_mod(void)
|
||||
{
|
||||
BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL;
|
||||
@@ -326,8 +395,10 @@ static int test_mod(void)
|
||||
BN_set_negative(b, rand_neg());
|
||||
if (!(TEST_true(BN_mod(c, a, b, ctx))
|
||||
&& TEST_true(BN_div(d, e, a, b, ctx))
|
||||
&& TEST_true(BN_sub(e, e, c))
|
||||
&& TEST_BN_eq_zero(e)))
|
||||
&& TEST_BN_eq(e, c)
|
||||
&& TEST_true(BN_mul(c, d, b, ctx))
|
||||
&& TEST_true(BN_add(d, c, e))
|
||||
&& TEST_BN_eq(d, a)))
|
||||
goto err;
|
||||
}
|
||||
st = 1;
|
||||
@@ -2759,6 +2830,8 @@ int setup_tests(void)
|
||||
if (n == 0) {
|
||||
ADD_TEST(test_sub);
|
||||
ADD_TEST(test_div_recip);
|
||||
ADD_ALL_TESTS(test_signed_mod_replace_ab, OSSL_NELEM(signed_mod_tests));
|
||||
ADD_ALL_TESTS(test_signed_mod_replace_ba, OSSL_NELEM(signed_mod_tests));
|
||||
ADD_TEST(test_mod);
|
||||
ADD_TEST(test_modexp_mont5);
|
||||
ADD_TEST(test_kronecker);
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
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
|
||||
WHoc
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -45,10 +45,16 @@
|
||||
|
||||
static const char *sessionfile = NULL;
|
||||
/* Dummy ALPN protocols used to pad out the size of the ClientHello */
|
||||
/* ASCII 'O' = 79 = 0x4F = EBCDIC '|'*/
|
||||
#ifdef CHARSET_EBCDIC
|
||||
static const char alpn_prots[] =
|
||||
"0123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"0123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789";
|
||||
"|1234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"|1234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
||||
#else
|
||||
static const char alpn_prots[] =
|
||||
"O1234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"O1234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
||||
#endif
|
||||
|
||||
static int test_client_hello(int currtest)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@@ -1124,7 +1124,56 @@ err:
|
||||
BN_free(yplusone);
|
||||
return r;
|
||||
}
|
||||
# endif
|
||||
|
||||
static int hybrid_point_encoding_test(void)
|
||||
{
|
||||
BIGNUM *x = NULL, *y = NULL;
|
||||
EC_GROUP *group = NULL;
|
||||
EC_POINT *point = NULL;
|
||||
unsigned char *buf = NULL;
|
||||
size_t len;
|
||||
int r = 0;
|
||||
|
||||
if (!TEST_true(BN_dec2bn(&x, "0"))
|
||||
|| !TEST_true(BN_dec2bn(&y, "1"))
|
||||
|| !TEST_ptr(group = EC_GROUP_new_by_curve_name(NID_sect571k1))
|
||||
|| !TEST_ptr(point = EC_POINT_new(group))
|
||||
|| !TEST_true(EC_POINT_set_affine_coordinates(group, point, x, y, NULL))
|
||||
|| !TEST_size_t_ne(0, (len = EC_POINT_point2oct(group,
|
||||
point,
|
||||
POINT_CONVERSION_HYBRID,
|
||||
NULL,
|
||||
0,
|
||||
NULL)))
|
||||
|| !TEST_ptr(buf = OPENSSL_malloc(len))
|
||||
|| !TEST_size_t_eq(len, EC_POINT_point2oct(group,
|
||||
point,
|
||||
POINT_CONVERSION_HYBRID,
|
||||
buf,
|
||||
len,
|
||||
NULL)))
|
||||
goto err;
|
||||
|
||||
r = 1;
|
||||
|
||||
/* buf contains a valid hybrid point, check that we can decode it. */
|
||||
if (!TEST_true(EC_POINT_oct2point(group, point, buf, len, NULL)))
|
||||
r = 0;
|
||||
|
||||
/* Flip the y_bit and verify that the invalid encoding is rejected. */
|
||||
buf[0] ^= 1;
|
||||
if (!TEST_false(EC_POINT_oct2point(group, point, buf, len, NULL)))
|
||||
r = 0;
|
||||
|
||||
err:
|
||||
BN_free(x);
|
||||
BN_free(y);
|
||||
EC_GROUP_free(group);
|
||||
EC_POINT_free(point);
|
||||
OPENSSL_free(buf);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int internal_curve_test(int n)
|
||||
{
|
||||
@@ -2195,6 +2244,7 @@ int setup_tests(void)
|
||||
ADD_ALL_TESTS(cardinality_test, crv_len);
|
||||
ADD_TEST(prime_field_tests);
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
ADD_TEST(hybrid_point_encoding_test);
|
||||
ADD_TEST(char2_field_tests);
|
||||
ADD_ALL_TESTS(char2_curve_test, OSSL_NELEM(char2_curve_tests));
|
||||
# endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -320,6 +320,96 @@ static const unsigned char pExampleECParamDER[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static const unsigned char kCFBDefaultKey[] = {
|
||||
0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88,
|
||||
0x09, 0xCF, 0x4F, 0x3C
|
||||
};
|
||||
|
||||
static const unsigned char kGCMDefaultKey[32] = { 0 };
|
||||
|
||||
static const unsigned char kGCMResetKey[] = {
|
||||
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94,
|
||||
0x67, 0x30, 0x83, 0x08, 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
|
||||
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
|
||||
};
|
||||
|
||||
static const unsigned char iCFBIV[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
|
||||
0x0C, 0x0D, 0x0E, 0x0F
|
||||
};
|
||||
|
||||
static const unsigned char iGCMDefaultIV[12] = { 0 };
|
||||
|
||||
static const unsigned char iGCMResetIV1[] = {
|
||||
0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad
|
||||
};
|
||||
|
||||
static const unsigned char iGCMResetIV2[] = {
|
||||
0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88
|
||||
};
|
||||
|
||||
static const unsigned char cfbPlaintext[] = {
|
||||
0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11,
|
||||
0x73, 0x93, 0x17, 0x2A
|
||||
};
|
||||
|
||||
static const unsigned char gcmDefaultPlaintext[16] = { 0 };
|
||||
|
||||
static const unsigned char gcmResetPlaintext[] = {
|
||||
0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5,
|
||||
0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
|
||||
0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95,
|
||||
0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
|
||||
0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39
|
||||
};
|
||||
|
||||
static const unsigned char cfbCiphertext[] = {
|
||||
0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, 0x33, 0x34, 0x49, 0xF8,
|
||||
0xE8, 0x3C, 0xFB, 0x4A
|
||||
};
|
||||
|
||||
static const unsigned char gcmDefaultCiphertext[] = {
|
||||
0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e, 0x07, 0x4e, 0xc5, 0xd3,
|
||||
0xba, 0xf3, 0x9d, 0x18
|
||||
};
|
||||
|
||||
static const unsigned char gcmResetCiphertext1[] = {
|
||||
0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32, 0xae, 0x47, 0xc1, 0x3b,
|
||||
0xf1, 0x98, 0x44, 0xcb, 0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa,
|
||||
0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0, 0xfe, 0xb5, 0x82, 0xd3,
|
||||
0x39, 0x34, 0xa4, 0xf0, 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78,
|
||||
0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99, 0xf4, 0x7c, 0x9b, 0x1f
|
||||
};
|
||||
|
||||
static const unsigned char gcmResetCiphertext2[] = {
|
||||
0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, 0xf4, 0x7f, 0x37, 0xa3,
|
||||
0x2a, 0x84, 0x42, 0x7d, 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
|
||||
0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, 0x8c, 0xb0, 0x8e, 0x48,
|
||||
0x59, 0x0d, 0xbb, 0x3d, 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
|
||||
0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, 0xbc, 0xc9, 0xf6, 0x62
|
||||
};
|
||||
|
||||
static const unsigned char gcmAAD[] = {
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed, 0xfa, 0xce,
|
||||
0xde, 0xad, 0xbe, 0xef, 0xab, 0xad, 0xda, 0xd2
|
||||
};
|
||||
|
||||
static const unsigned char gcmDefaultTag[] = {
|
||||
0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0, 0x26, 0x5b, 0x98, 0xb5,
|
||||
0xd4, 0x8a, 0xb9, 0x19
|
||||
};
|
||||
|
||||
static const unsigned char gcmResetTag1[] = {
|
||||
0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4, 0x5e, 0x45, 0x49, 0x13,
|
||||
0xfe, 0x2e, 0xa8, 0xf2
|
||||
};
|
||||
|
||||
static const unsigned char gcmResetTag2[] = {
|
||||
0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68, 0xcd, 0xdf, 0x88, 0x53,
|
||||
0xbb, 0x2d, 0x55, 0x1b
|
||||
};
|
||||
|
||||
|
||||
typedef struct APK_DATA_st {
|
||||
const unsigned char *kder;
|
||||
size_t size;
|
||||
@@ -330,6 +420,494 @@ typedef struct APK_DATA_st {
|
||||
int type; /* 0 for private, 1 for public, 2 for params */
|
||||
} APK_DATA;
|
||||
|
||||
typedef struct {
|
||||
const char *cipher;
|
||||
const unsigned char *key;
|
||||
const unsigned char *iv;
|
||||
const unsigned char *input;
|
||||
const unsigned char *expected;
|
||||
const unsigned char *tag;
|
||||
size_t ivlen; /* 0 if we do not need to set a specific IV len */
|
||||
size_t inlen;
|
||||
size_t expectedlen;
|
||||
size_t taglen;
|
||||
int keyfirst;
|
||||
int initenc;
|
||||
int finalenc;
|
||||
} EVP_INIT_TEST_st;
|
||||
|
||||
static const EVP_INIT_TEST_st evp_init_tests[] = {
|
||||
{
|
||||
"aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext,
|
||||
cfbCiphertext, NULL, 0, sizeof(cfbPlaintext), sizeof(cfbCiphertext),
|
||||
0, 1, 0, 1
|
||||
},
|
||||
{
|
||||
"aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext,
|
||||
gcmDefaultCiphertext, gcmDefaultTag, sizeof(iGCMDefaultIV),
|
||||
sizeof(gcmDefaultPlaintext), sizeof(gcmDefaultCiphertext),
|
||||
sizeof(gcmDefaultTag), 1, 0, 1
|
||||
},
|
||||
{
|
||||
"aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext,
|
||||
cfbCiphertext, NULL, 0, sizeof(cfbPlaintext), sizeof(cfbCiphertext),
|
||||
0, 0, 0, 1
|
||||
},
|
||||
{
|
||||
"aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext,
|
||||
gcmDefaultCiphertext, gcmDefaultTag, sizeof(iGCMDefaultIV),
|
||||
sizeof(gcmDefaultPlaintext), sizeof(gcmDefaultCiphertext),
|
||||
sizeof(gcmDefaultTag), 0, 0, 1
|
||||
},
|
||||
{
|
||||
"aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext,
|
||||
cfbPlaintext, NULL, 0, sizeof(cfbCiphertext), sizeof(cfbPlaintext),
|
||||
0, 1, 1, 0
|
||||
},
|
||||
{
|
||||
"aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext,
|
||||
gcmDefaultPlaintext, gcmDefaultTag, sizeof(iGCMDefaultIV),
|
||||
sizeof(gcmDefaultCiphertext), sizeof(gcmDefaultPlaintext),
|
||||
sizeof(gcmDefaultTag), 1, 1, 0
|
||||
},
|
||||
{
|
||||
"aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext,
|
||||
cfbPlaintext, NULL, 0, sizeof(cfbCiphertext), sizeof(cfbPlaintext),
|
||||
0, 0, 1, 0
|
||||
},
|
||||
{
|
||||
"aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext,
|
||||
gcmDefaultPlaintext, gcmDefaultTag, sizeof(iGCMDefaultIV),
|
||||
sizeof(gcmDefaultCiphertext), sizeof(gcmDefaultPlaintext),
|
||||
sizeof(gcmDefaultTag), 0, 1, 0
|
||||
}
|
||||
};
|
||||
|
||||
static int evp_init_seq_set_iv(EVP_CIPHER_CTX *ctx, const EVP_INIT_TEST_st *t)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (t->ivlen != 0) {
|
||||
if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, t->ivlen, NULL)))
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, t->iv, -1)))
|
||||
goto err;
|
||||
res = 1;
|
||||
err:
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test step-wise cipher initialization via EVP_CipherInit_ex where the
|
||||
* arguments are given one at a time and a final adjustment to the enc
|
||||
* parameter sets the correct operation.
|
||||
*/
|
||||
static int test_evp_init_seq(int idx)
|
||||
{
|
||||
int outlen1, outlen2;
|
||||
int testresult = 0;
|
||||
unsigned char outbuf[1024];
|
||||
unsigned char tag[16];
|
||||
const EVP_INIT_TEST_st *t = &evp_init_tests[idx];
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
const EVP_CIPHER *type = NULL;
|
||||
size_t taglen = sizeof(tag);
|
||||
char *errmsg = NULL;
|
||||
|
||||
ctx = EVP_CIPHER_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
errmsg = "CTX_ALLOC";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_ptr(type = EVP_get_cipherbyname(t->cipher))) {
|
||||
errmsg = "GET_CIPHERBYNAME";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, type, NULL, NULL, NULL, t->initenc))) {
|
||||
errmsg = "EMPTY_ENC_INIT";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CIPHER_CTX_set_padding(ctx, 0))) {
|
||||
errmsg = "PADDING";
|
||||
goto err;
|
||||
}
|
||||
if (t->keyfirst && !TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, t->key, NULL, -1))) {
|
||||
errmsg = "KEY_INIT (before iv)";
|
||||
goto err;
|
||||
}
|
||||
if (!evp_init_seq_set_iv(ctx, t)) {
|
||||
errmsg = "IV_INIT";
|
||||
goto err;
|
||||
}
|
||||
if (t->keyfirst == 0 && !TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, t->key, NULL, -1))) {
|
||||
errmsg = "KEY_INIT (after iv)";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, t->finalenc))) {
|
||||
errmsg = "FINAL_ENC_INIT";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, t->input, t->inlen))) {
|
||||
errmsg = "CIPHER_UPDATE";
|
||||
goto err;
|
||||
}
|
||||
if (t->finalenc == 0 && t->tag != NULL) {
|
||||
/* Set expected tag */
|
||||
if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
|
||||
t->taglen, (void *)t->tag))) {
|
||||
errmsg = "SET_TAG";
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
|
||||
errmsg = "CIPHER_FINAL";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->expected, t->expectedlen, outbuf, outlen1 + outlen2)) {
|
||||
errmsg = "WRONG_RESULT";
|
||||
goto err;
|
||||
}
|
||||
if (t->finalenc != 0 && t->tag != NULL) {
|
||||
if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag))) {
|
||||
errmsg = "GET_TAG";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->tag, t->taglen, tag, taglen)) {
|
||||
errmsg = "TAG_ERROR";
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
testresult = 1;
|
||||
err:
|
||||
if (errmsg != NULL)
|
||||
TEST_info("evp_init_test %d: %s", idx, errmsg);
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return testresult;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const unsigned char *input;
|
||||
const unsigned char *expected;
|
||||
size_t inlen;
|
||||
size_t expectedlen;
|
||||
int enc;
|
||||
} EVP_RESET_TEST_st;
|
||||
|
||||
static const EVP_RESET_TEST_st evp_reset_tests[] = {
|
||||
{
|
||||
cfbPlaintext, cfbCiphertext,
|
||||
sizeof(cfbPlaintext), sizeof(cfbCiphertext), 1
|
||||
},
|
||||
{
|
||||
cfbCiphertext, cfbPlaintext,
|
||||
sizeof(cfbCiphertext), sizeof(cfbPlaintext), 0
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Test a reset of a cipher via EVP_CipherInit_ex after the cipher has already
|
||||
* been used.
|
||||
*/
|
||||
static int test_evp_reset(int idx)
|
||||
{
|
||||
const EVP_RESET_TEST_st *t = &evp_reset_tests[idx];
|
||||
int outlen1, outlen2;
|
||||
int testresult = 0;
|
||||
unsigned char outbuf[1024];
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
const EVP_CIPHER *type = NULL;
|
||||
char *errmsg = NULL;
|
||||
|
||||
if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new())) {
|
||||
errmsg = "CTX_ALLOC";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_ptr(type = EVP_get_cipherbyname("aes-128-cfb"))) {
|
||||
errmsg = "GET_CIPHERBYNAME";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, type, NULL, kCFBDefaultKey, iCFBIV, t->enc))) {
|
||||
errmsg = "CIPHER_INIT";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CIPHER_CTX_set_padding(ctx, 0))) {
|
||||
errmsg = "PADDING";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, t->input, t->inlen))) {
|
||||
errmsg = "CIPHER_UPDATE";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
|
||||
errmsg = "CIPHER_FINAL";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->expected, t->expectedlen, outbuf, outlen1 + outlen2)) {
|
||||
errmsg = "WRONG_RESULT";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, -1))) {
|
||||
errmsg = "CIPHER_REINIT";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, t->input, t->inlen))) {
|
||||
errmsg = "CIPHER_UPDATE (reinit)";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
|
||||
errmsg = "CIPHER_FINAL (reinit)";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->expected, t->expectedlen, outbuf, outlen1 + outlen2)) {
|
||||
errmsg = "WRONG_RESULT (reinit)";
|
||||
goto err;
|
||||
}
|
||||
testresult = 1;
|
||||
err:
|
||||
if (errmsg != NULL)
|
||||
TEST_info("test_evp_reset %d: %s", idx, errmsg);
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return testresult;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const unsigned char *iv1;
|
||||
const unsigned char *iv2;
|
||||
const unsigned char *expected1;
|
||||
const unsigned char *expected2;
|
||||
const unsigned char *tag1;
|
||||
const unsigned char *tag2;
|
||||
size_t ivlen1;
|
||||
size_t ivlen2;
|
||||
size_t expectedlen1;
|
||||
size_t expectedlen2;
|
||||
} TEST_GCM_IV_REINIT_st;
|
||||
|
||||
static const TEST_GCM_IV_REINIT_st gcm_reinit_tests[] = {
|
||||
{
|
||||
iGCMResetIV1, iGCMResetIV2, gcmResetCiphertext1, gcmResetCiphertext2,
|
||||
gcmResetTag1, gcmResetTag2, sizeof(iGCMResetIV1), sizeof(iGCMResetIV2),
|
||||
sizeof(gcmResetCiphertext1), sizeof(gcmResetCiphertext2)
|
||||
},
|
||||
{
|
||||
iGCMResetIV2, iGCMResetIV1, gcmResetCiphertext2, gcmResetCiphertext1,
|
||||
gcmResetTag2, gcmResetTag1, sizeof(iGCMResetIV2), sizeof(iGCMResetIV1),
|
||||
sizeof(gcmResetCiphertext2), sizeof(gcmResetCiphertext1)
|
||||
}
|
||||
};
|
||||
|
||||
static int test_gcm_reinit(int idx)
|
||||
{
|
||||
int outlen1, outlen2, outlen3;
|
||||
int testresult = 0;
|
||||
unsigned char outbuf[1024];
|
||||
unsigned char tag[16];
|
||||
const TEST_GCM_IV_REINIT_st *t = &gcm_reinit_tests[idx];
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
const EVP_CIPHER *type = NULL;
|
||||
size_t taglen = sizeof(tag);
|
||||
char *errmsg = NULL;
|
||||
|
||||
if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new())) {
|
||||
errmsg = "CTX_ALLOC";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_ptr(type = EVP_get_cipherbyname("aes-256-gcm"))) {
|
||||
errmsg = "GET_CIPHERBYNAME";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, type, NULL, NULL, NULL, 1))) {
|
||||
errmsg = "ENC_INIT";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, t->ivlen1, NULL))) {
|
||||
errmsg = "SET_IVLEN1";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, kGCMResetKey, t->iv1, 1))) {
|
||||
errmsg = "SET_IV1";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, NULL, &outlen3, gcmAAD, sizeof(gcmAAD)))) {
|
||||
errmsg = "AAD1";
|
||||
goto err;
|
||||
}
|
||||
EVP_CIPHER_CTX_set_padding(ctx, 0);
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, gcmResetPlaintext,
|
||||
sizeof(gcmResetPlaintext)))) {
|
||||
errmsg = "CIPHER_UPDATE1";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
|
||||
errmsg = "CIPHER_FINAL1";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->expected1, t->expectedlen1, outbuf, outlen1 + outlen2)) {
|
||||
errmsg = "WRONG_RESULT1";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag))) {
|
||||
errmsg = "GET_TAG1";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->tag1, taglen, tag, taglen)) {
|
||||
errmsg = "TAG_ERROR1";
|
||||
goto err;
|
||||
}
|
||||
/* Now reinit */
|
||||
if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, t->ivlen2, NULL))) {
|
||||
errmsg = "SET_IVLEN2";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, t->iv2, -1))) {
|
||||
errmsg = "SET_IV2";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, NULL, &outlen3, gcmAAD, sizeof(gcmAAD)))) {
|
||||
errmsg = "AAD2";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, gcmResetPlaintext,
|
||||
sizeof(gcmResetPlaintext)))) {
|
||||
errmsg = "CIPHER_UPDATE2";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
|
||||
errmsg = "CIPHER_FINAL2";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->expected2, t->expectedlen2, outbuf, outlen1 + outlen2)) {
|
||||
errmsg = "WRONG_RESULT2";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag))) {
|
||||
errmsg = "GET_TAG2";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_eq(t->tag2, taglen, tag, taglen)) {
|
||||
errmsg = "TAG_ERROR2";
|
||||
goto err;
|
||||
}
|
||||
testresult = 1;
|
||||
err:
|
||||
if (errmsg != NULL)
|
||||
TEST_info("evp_init_test %d: %s", idx, errmsg);
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return testresult;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char *cipher;
|
||||
int enc;
|
||||
} EVP_UPDATED_IV_TEST_st;
|
||||
|
||||
static const EVP_UPDATED_IV_TEST_st evp_updated_iv_tests[] = {
|
||||
{
|
||||
"aes-128-cfb", 1
|
||||
},
|
||||
{
|
||||
"aes-128-cfb", 0
|
||||
},
|
||||
{
|
||||
"aes-128-cfb1", 1
|
||||
},
|
||||
{
|
||||
"aes-128-cfb1", 0
|
||||
},
|
||||
{
|
||||
"aes-128-cfb128", 1
|
||||
},
|
||||
{
|
||||
"aes-128-cfb128", 0
|
||||
},
|
||||
{
|
||||
"aes-128-cfb8", 1
|
||||
},
|
||||
{
|
||||
"aes-128-cfb8", 0
|
||||
},
|
||||
{
|
||||
"aes-128-ofb", 1
|
||||
},
|
||||
{
|
||||
"aes-128-ofb", 0
|
||||
},
|
||||
{
|
||||
"aes-128-ctr", 1
|
||||
},
|
||||
{
|
||||
"aes-128-ctr", 0
|
||||
},
|
||||
{
|
||||
"aes-128-cbc", 1
|
||||
},
|
||||
{
|
||||
"aes-128-cbc", 0
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Test that the IV in the context is updated during a crypto operation for CFB
|
||||
* and OFB.
|
||||
*/
|
||||
static int test_evp_updated_iv(int idx)
|
||||
{
|
||||
const EVP_UPDATED_IV_TEST_st *t = &evp_updated_iv_tests[idx];
|
||||
int outlen1, outlen2;
|
||||
int testresult = 0;
|
||||
unsigned char outbuf[1024];
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
const EVP_CIPHER *type = NULL;
|
||||
const unsigned char *updated_iv;
|
||||
int iv_len;
|
||||
char *errmsg = NULL;
|
||||
|
||||
if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new())) {
|
||||
errmsg = "CTX_ALLOC";
|
||||
goto err;
|
||||
}
|
||||
if ((type = EVP_get_cipherbyname(t->cipher)) == NULL) {
|
||||
TEST_info("cipher %s not supported, skipping", t->cipher);
|
||||
goto ok;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherInit_ex(ctx, type, NULL, kCFBDefaultKey, iCFBIV, t->enc))) {
|
||||
errmsg = "CIPHER_INIT";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CIPHER_CTX_set_padding(ctx, 0))) {
|
||||
errmsg = "PADDING";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, cfbPlaintext, sizeof(cfbPlaintext)))) {
|
||||
errmsg = "CIPHER_UPDATE";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_ptr(updated_iv = EVP_CIPHER_CTX_iv(ctx))) {
|
||||
errmsg = "CIPHER_CTX_IV";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(iv_len = EVP_CIPHER_CTX_iv_length(ctx))) {
|
||||
errmsg = "CIPHER_CTX_IV_LEN";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_mem_ne(iCFBIV, sizeof(iCFBIV), updated_iv, iv_len)) {
|
||||
errmsg = "IV_NOT_UPDATED";
|
||||
goto err;
|
||||
}
|
||||
if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
|
||||
errmsg = "CIPHER_FINAL";
|
||||
goto err;
|
||||
}
|
||||
ok:
|
||||
testresult = 1;
|
||||
err:
|
||||
if (errmsg != NULL)
|
||||
TEST_info("test_evp_updated_iv %d: %s", idx, errmsg);
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return testresult;
|
||||
}
|
||||
|
||||
static APK_DATA keydata[] = {
|
||||
{kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER), EVP_PKEY_RSA},
|
||||
{kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8), EVP_PKEY_RSA},
|
||||
@@ -818,10 +1396,14 @@ static struct keys_st {
|
||||
} keys[] = {
|
||||
{
|
||||
EVP_PKEY_HMAC, "0123456789", NULL
|
||||
#ifndef OPENSSL_NO_POLY1305
|
||||
}, {
|
||||
EVP_PKEY_POLY1305, "01234567890123456789012345678901", NULL
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SIPHASH
|
||||
}, {
|
||||
EVP_PKEY_SIPHASH, "0123456789012345", NULL
|
||||
#endif
|
||||
},
|
||||
#ifndef OPENSSL_NO_EC
|
||||
{
|
||||
@@ -851,18 +1433,22 @@ static int test_set_get_raw_keys_int(int tst, int pub)
|
||||
EVP_PKEY *pkey;
|
||||
|
||||
/* Check if this algorithm supports public keys */
|
||||
if (keys[tst].pub == NULL)
|
||||
if (pub && keys[tst].pub == NULL)
|
||||
return 1;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (pub) {
|
||||
#ifndef OPENSSL_NO_EC
|
||||
inlen = strlen(keys[tst].pub);
|
||||
in = (unsigned char *)keys[tst].pub;
|
||||
pkey = EVP_PKEY_new_raw_public_key(keys[tst].type,
|
||||
NULL,
|
||||
in,
|
||||
inlen);
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
} else {
|
||||
inlen = strlen(keys[tst].priv);
|
||||
in = (unsigned char *)keys[tst].priv;
|
||||
@@ -873,6 +1459,7 @@ static int test_set_get_raw_keys_int(int tst, int pub)
|
||||
}
|
||||
|
||||
if (!TEST_ptr(pkey)
|
||||
|| !TEST_int_eq(EVP_PKEY_cmp(pkey, pkey), 1)
|
||||
|| (!pub && !TEST_true(EVP_PKEY_get_raw_private_key(pkey, NULL, &len)))
|
||||
|| (pub && !TEST_true(EVP_PKEY_get_raw_public_key(pkey, NULL, &len)))
|
||||
|| !TEST_true(len == inlen)
|
||||
@@ -1209,5 +1796,10 @@ int setup_tests(void)
|
||||
ADD_TEST(test_EVP_PKEY_set1_DH);
|
||||
#endif
|
||||
|
||||
ADD_ALL_TESTS(test_evp_init_seq, OSSL_NELEM(evp_init_tests));
|
||||
ADD_ALL_TESTS(test_evp_reset, OSSL_NELEM(evp_reset_tests));
|
||||
ADD_ALL_TESTS(test_gcm_reinit, OSSL_NELEM(gcm_reinit_tests));
|
||||
ADD_ALL_TESTS(test_evp_updated_iv, OSSL_NELEM(evp_updated_iv_tests));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -47,7 +47,7 @@ ok(!run(app([@addext_args, "-addext", $val, "-addext", $val3])));
|
||||
ok(!run(app([@addext_args, "-addext", $val2, "-addext", $val3])));
|
||||
|
||||
subtest "generating certificate requests with RSA" => sub {
|
||||
plan tests => 2;
|
||||
plan tests => 6;
|
||||
|
||||
SKIP: {
|
||||
skip "RSA is not supported by this OpenSSL build", 2
|
||||
@@ -63,6 +63,29 @@ subtest "generating certificate requests with RSA" => sub {
|
||||
"-config", srctop_file("test", "test.cnf"),
|
||||
"-verify", "-in", "testreq.pem", "-noout"])),
|
||||
"Verifying signature on request");
|
||||
|
||||
ok(run(app(["openssl", "req",
|
||||
"-config", srctop_file("test", "test.cnf"),
|
||||
"-new", "-out", "testreq_withattrs_pem.pem", "-utf8",
|
||||
"-key", srctop_file("test", "testrsa_withattrs.pem")])),
|
||||
"Generating request from a key with extra attributes - PEM");
|
||||
|
||||
ok(run(app(["openssl", "req",
|
||||
"-config", srctop_file("test", "test.cnf"),
|
||||
"-verify", "-in", "testreq_withattrs_pem.pem", "-noout"])),
|
||||
"Verifying signature on request from a key with extra attributes - PEM");
|
||||
|
||||
ok(run(app(["openssl", "req",
|
||||
"-config", srctop_file("test", "test.cnf"),
|
||||
"-new", "-out", "testreq_withattrs_der.pem", "-utf8",
|
||||
"-key", srctop_file("test", "testrsa_withattrs.der"),
|
||||
"-keyform", "DER"])),
|
||||
"Generating request from a key with extra attributes - PEM");
|
||||
|
||||
ok(run(app(["openssl", "req",
|
||||
"-config", srctop_file("test", "test.cnf"),
|
||||
"-verify", "-in", "testreq_withattrs_der.pem", "-noout"])),
|
||||
"Verifying signature on request from a key with extra attributes - PEM");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -165,7 +188,7 @@ run_conversion('req conversions',
|
||||
run_conversion('req conversions -- testreq2',
|
||||
srctop_file("test", "testreq2.pem"));
|
||||
|
||||
unlink "testkey.pem", "testreq.pem";
|
||||
unlink "testkey.pem", "testreq.pem", "testreq_withattrs_pem.pem", "testreq_withattrs_der.pem";
|
||||
|
||||
sub run_conversion {
|
||||
my $title = shift;
|
||||
|
||||
@@ -396,7 +396,8 @@ ok(verify("some-names2", "sslserver", ["many-constraints"], ["many-constraints"]
|
||||
ok(verify("root-cert-rsa2", "sslserver", ["root-cert-rsa2"], [], "-check_ss_sig"),
|
||||
"Public Key Algorithm rsa instead of rsaEncryption");
|
||||
|
||||
ok(verify("ee-self-signed", "sslserver", ["ee-self-signed"], []),
|
||||
ok(verify("ee-self-signed", "sslserver", ["ee-self-signed"], [],
|
||||
"-attime", "1593565200"),
|
||||
"accept trusted self-signed EE cert excluding key usage keyCertSign");
|
||||
|
||||
SKIP: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -18444,6 +18444,16 @@ Decrypt = SM2_key1
|
||||
Input = 30818A0220466BE2EF5C11782EC77864A0055417F407A5AFC11D653C6BCE69E417BB1D05B6022062B572E21FF0DDF5C726BD3F9FF2EAE56E6294713A607E9B9525628965F62CC804203C1B5713B5DB2728EB7BF775E44F4689FC32668BDC564F52EA45B09E8DF2A5F40422084A9D0CC2997092B7D3C404FCE95956EB604D732B2307A8E5B8900ED6608CA5B197
|
||||
Output = "The floofy bunnies hop at midnight"
|
||||
|
||||
# Test with an C1y value < 32 bytes in length (self generated)
|
||||
Decrypt = SM2_key1
|
||||
Input = 3072022070DAD60CDA7C30D64CF4F278A849003581223F5324BFEC9BB329229BFFAD21A6021F18AFAB2B35459D2643243B242BE4EA80C6FA5071D2D847340CC57EB9309E5D04200B772E4DB664B2601E3B85E39C4AA8C2C1910308BE13B331E009C5A9258C29FD040B6D588BE9260A94DA18E0E6
|
||||
Output = "Hello World"
|
||||
|
||||
# Test with an C1x and C1y valuey > 32 bytes in length, and longer plaintext (self generated)
|
||||
Decrypt = SM2_key1
|
||||
Input = 3081DD022100CD49634BBCB21CAFFFA6D33669A5A867231CB2A942A14352EF4CAF6DC3344D54022100C35B41D4DEBB3A2735EFEE821B9EBA566BD86900176A0C06672E30EE5CC04E930420C4190A3D80D86C4BD20E99F7E4B59BF6427C6808793533EEA9591D1188EC56B50473747295470E81D951BED279AC1B86A1AFE388CD2833FA9632799EC199C7D364E5663D5A94888BB2358CFCBF6283184DE0CBC41CCEA91D24746E99D231A1DA77AFD83CDF908190ED628B7369724494568A27C782A1D1D7294BCAD80C34569ED22859896301128A8118F48924D8CCD43E998D9533
|
||||
Output = "Some longer plaintext for testing SM2 decryption. Blah blah blah blah blah blah blah blah blah blah blah blah blah."
|
||||
|
||||
# This is a "fake" test as it does only verify that the SM2 EVP_PKEY interface
|
||||
# is capable of creating a signature without failing, but it does not say
|
||||
# anything about the generated signature being valid, nor does it test the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -195,17 +195,14 @@ $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
||||
plan tests => 11;
|
||||
ok(TLSProxy::Message->success(), "Initial connection");
|
||||
|
||||
#Test 2: Attempt a resume with no kex modes extension. Should not resume
|
||||
#Test 2: Attempt a resume with no kex modes extension. Should fail (server
|
||||
# MUST abort handshake with pre_shared key and no psk_kex_modes)
|
||||
$proxy->clear();
|
||||
$proxy->clientflags("-sess_in ".$session);
|
||||
my $testtype = DELETE_EXTENSION;
|
||||
$proxy->filter(\&modify_kex_modes_filter);
|
||||
$proxy->start();
|
||||
checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
|
||||
checkhandshake::DEFAULT_EXTENSIONS
|
||||
| checkhandshake::KEY_SHARE_SRV_EXTENSION
|
||||
| checkhandshake::PSK_CLI_EXTENSION,
|
||||
"Resume with no kex modes");
|
||||
ok(TLSProxy::Message->fail(), "Resume with no kex modes");
|
||||
|
||||
#Test 3: Attempt a resume with empty kex modes extension. Should fail (empty
|
||||
# extension is invalid)
|
||||
@@ -243,6 +240,7 @@ checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
|
||||
"Resume with non-dhe kex mode");
|
||||
|
||||
#Test 6: Attempt a resume with only unrecognised kex modes. Should not resume
|
||||
# but rather fall back to full handshake
|
||||
$proxy->clear();
|
||||
$proxy->clientflags("-sess_in ".$session);
|
||||
$testtype = UNKNOWN_KEX_MODES;
|
||||
@@ -252,7 +250,7 @@ checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
|
||||
| checkhandshake::PSK_KEX_MODES_EXTENSION
|
||||
| checkhandshake::KEY_SHARE_SRV_EXTENSION
|
||||
| checkhandshake::PSK_CLI_EXTENSION,
|
||||
"Resume with empty kex modes");
|
||||
"Resume with unrecognized kex mode");
|
||||
|
||||
#Test 7: Attempt a resume with both non-dhe and dhe kex mode. Should resume with
|
||||
# a key_share
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -476,10 +476,10 @@ sub testssl {
|
||||
subtest 'RSA/(EC)DHE/PSK tests' => sub {
|
||||
######################################################################
|
||||
|
||||
plan tests => 5;
|
||||
plan tests => 6;
|
||||
|
||||
SKIP: {
|
||||
skip "TLSv1.0 is not supported by this OpenSSL build", 5
|
||||
skip "TLSv1.0 is not supported by this OpenSSL build", 6
|
||||
if $no_tls1;
|
||||
|
||||
SKIP: {
|
||||
@@ -514,6 +514,14 @@ sub testssl {
|
||||
ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123"])),
|
||||
'test tls1 with PSK via BIO pair');
|
||||
}
|
||||
|
||||
SKIP: {
|
||||
skip "skipping auto PSK tests", 1
|
||||
if ($no_dh || $no_psk || $no_ec);
|
||||
|
||||
ok(run(test(['ssltest_old', '-psk', '0102030405', '-cipher', '@SECLEVEL=2:DHE-PSK-AES128-CCM'])),
|
||||
'test auto DH meets security strength');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -306,7 +306,6 @@ static int test_rsa_oaep(int idx)
|
||||
int ret = 0;
|
||||
RSA *key = NULL;
|
||||
unsigned char ptext[256];
|
||||
unsigned char ctext[256];
|
||||
static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
|
||||
unsigned char ctext_ex[256];
|
||||
int plen;
|
||||
@@ -328,17 +327,17 @@ static int test_rsa_oaep(int idx)
|
||||
|
||||
/* Try decrypting corrupted ciphertexts. */
|
||||
for (n = 0; n < clen; ++n) {
|
||||
ctext[n] ^= 1;
|
||||
num = RSA_private_decrypt(clen, ctext, ptext, key,
|
||||
ctext_ex[n] ^= 1;
|
||||
num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (!TEST_int_le(num, 0))
|
||||
goto err;
|
||||
ctext[n] ^= 1;
|
||||
ctext_ex[n] ^= 1;
|
||||
}
|
||||
|
||||
/* Test truncated ciphertexts, as well as negative length. */
|
||||
for (n = -1; n < clen; ++n) {
|
||||
num = RSA_private_decrypt(n, ctext, ptext, key,
|
||||
num = RSA_private_decrypt(n, ctext_ex, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (!TEST_int_le(num, 0))
|
||||
goto err;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -185,7 +185,7 @@ static int test_sm2_crypt(const EC_GROUP *group,
|
||||
if (!TEST_mem_eq(ctext, ctext_len, expected, ctext_len))
|
||||
goto done;
|
||||
|
||||
if (!TEST_true(sm2_plaintext_size(key, digest, ctext_len, &ptext_len))
|
||||
if (!TEST_true(sm2_plaintext_size(ctext, ctext_len, &ptext_len))
|
||||
|| !TEST_int_eq(ptext_len, msg_len))
|
||||
goto done;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <openssl/srp.h>
|
||||
#include <openssl/txt_db.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#include "ssltestlib.h"
|
||||
#include "testutil.h"
|
||||
@@ -1826,8 +1827,10 @@ static int execute_test_ssl_bio(int pop_ssl, bio_change_t change_bio)
|
||||
|
||||
/* Verify changing the rbio/wbio directly does not cause leaks */
|
||||
if (change_bio != NO_BIO_CHANGE) {
|
||||
if (!TEST_ptr(membio2 = BIO_new(BIO_s_mem())))
|
||||
if (!TEST_ptr(membio2 = BIO_new(BIO_s_mem()))) {
|
||||
ssl = NULL;
|
||||
goto end;
|
||||
}
|
||||
if (change_bio == CHANGE_RBIO)
|
||||
SSL_set0_rbio(ssl, membio2);
|
||||
else
|
||||
@@ -6713,6 +6716,118 @@ end:
|
||||
return testresult;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Test that setting an ALPN does not violate RFC
|
||||
*/
|
||||
static int test_set_alpn(void)
|
||||
{
|
||||
SSL_CTX *ctx = NULL;
|
||||
SSL *ssl = NULL;
|
||||
int testresult = 0;
|
||||
|
||||
unsigned char bad0[] = { 0x00, 'b', 'a', 'd' };
|
||||
unsigned char good[] = { 0x04, 'g', 'o', 'o', 'd' };
|
||||
unsigned char bad1[] = { 0x01, 'b', 'a', 'd' };
|
||||
unsigned char bad2[] = { 0x03, 'b', 'a', 'd', 0x00};
|
||||
unsigned char bad3[] = { 0x03, 'b', 'a', 'd', 0x01, 'b', 'a', 'd'};
|
||||
unsigned char bad4[] = { 0x03, 'b', 'a', 'd', 0x06, 'b', 'a', 'd'};
|
||||
|
||||
/* Create an initial SSL_CTX with no certificate configured */
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
if (!TEST_ptr(ctx))
|
||||
goto end;
|
||||
|
||||
/* the set_alpn functions return 0 (false) on success, non-zero (true) on failure */
|
||||
if (!TEST_false(SSL_CTX_set_alpn_protos(ctx, NULL, 2)))
|
||||
goto end;
|
||||
if (!TEST_false(SSL_CTX_set_alpn_protos(ctx, good, 0)))
|
||||
goto end;
|
||||
if (!TEST_false(SSL_CTX_set_alpn_protos(ctx, good, sizeof(good))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_CTX_set_alpn_protos(ctx, good, 1)))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_CTX_set_alpn_protos(ctx, bad0, sizeof(bad0))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_CTX_set_alpn_protos(ctx, bad1, sizeof(bad1))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_CTX_set_alpn_protos(ctx, bad2, sizeof(bad2))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_CTX_set_alpn_protos(ctx, bad3, sizeof(bad3))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_CTX_set_alpn_protos(ctx, bad4, sizeof(bad4))))
|
||||
goto end;
|
||||
|
||||
ssl = SSL_new(ctx);
|
||||
if (!TEST_ptr(ssl))
|
||||
goto end;
|
||||
|
||||
if (!TEST_false(SSL_set_alpn_protos(ssl, NULL, 2)))
|
||||
goto end;
|
||||
if (!TEST_false(SSL_set_alpn_protos(ssl, good, 0)))
|
||||
goto end;
|
||||
if (!TEST_false(SSL_set_alpn_protos(ssl, good, sizeof(good))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_set_alpn_protos(ssl, good, 1)))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_set_alpn_protos(ssl, bad0, sizeof(bad0))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_set_alpn_protos(ssl, bad1, sizeof(bad1))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_set_alpn_protos(ssl, bad2, sizeof(bad2))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_set_alpn_protos(ssl, bad3, sizeof(bad3))))
|
||||
goto end;
|
||||
if (!TEST_true(SSL_set_alpn_protos(ssl, bad4, sizeof(bad4))))
|
||||
goto end;
|
||||
|
||||
testresult = 1;
|
||||
|
||||
end:
|
||||
SSL_free(ssl);
|
||||
SSL_CTX_free(ctx);
|
||||
return testresult;
|
||||
}
|
||||
|
||||
static int test_inherit_verify_param(void)
|
||||
{
|
||||
int testresult = 0;
|
||||
|
||||
SSL_CTX *ctx = NULL;
|
||||
X509_VERIFY_PARAM *cp = NULL;
|
||||
SSL *ssl = NULL;
|
||||
X509_VERIFY_PARAM *sp = NULL;
|
||||
int hostflags = X509_CHECK_FLAG_NEVER_CHECK_SUBJECT;
|
||||
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
if (!TEST_ptr(ctx))
|
||||
goto end;
|
||||
|
||||
cp = SSL_CTX_get0_param(ctx);
|
||||
if (!TEST_ptr(cp))
|
||||
goto end;
|
||||
if (!TEST_int_eq(X509_VERIFY_PARAM_get_hostflags(cp), 0))
|
||||
goto end;
|
||||
|
||||
X509_VERIFY_PARAM_set_hostflags(cp, hostflags);
|
||||
|
||||
ssl = SSL_new(ctx);
|
||||
if (!TEST_ptr(ssl))
|
||||
goto end;
|
||||
|
||||
sp = SSL_get0_param(ssl);
|
||||
if (!TEST_ptr(sp))
|
||||
goto end;
|
||||
if (!TEST_int_eq(X509_VERIFY_PARAM_get_hostflags(sp), hostflags))
|
||||
goto end;
|
||||
|
||||
testresult = 1;
|
||||
|
||||
end:
|
||||
SSL_free(ssl);
|
||||
SSL_CTX_free(ctx);
|
||||
|
||||
return testresult;
|
||||
}
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
@@ -6840,6 +6955,8 @@ int setup_tests(void)
|
||||
#ifndef OPENSSL_NO_TLS1_3
|
||||
ADD_TEST(test_sni_tls13);
|
||||
#endif
|
||||
ADD_TEST(test_set_alpn);
|
||||
ADD_TEST(test_inherit_verify_param);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
BIN
test/testrsa_withattrs.der
Normal file
BIN
test/testrsa_withattrs.der
Normal file
Binary file not shown.
29
test/testrsa_withattrs.pem
Normal file
29
test/testrsa_withattrs.pem
Normal file
@@ -0,0 +1,29 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIE+QIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDsh7QWxhftrqng
|
||||
RC3Ms+HxH2NFCX1sRoiIV4cYK2z0DQdEiNpFdpHlcs3weTuudcpr8XursodVFMTB
|
||||
eHjROhgwO/LT9xReEUiaoHJgfv6KcKcxEvntCjQkzGhkw03OH5VYdtTRAbwpwcYt
|
||||
groPiZ2STINpQOmFabzai+K+3rddwTGkkca3C5kY7KOMlnt9IuvmycksRqH6MPKz
|
||||
P5QbztlgY95rtra+OEzKLYQ1ux6hkaUlpxT5eGKfzYdccwKJWa0dUXyT/8F6rpTm
|
||||
Zbz3BxdKGAWMywaTfh5ywhNmVNTeIumxIRc3+PInn0rqKTaDrWylxiBdb3t27HxQ
|
||||
InDZmPwdAgMBAAECggEBAMTRrzN8JxEq1ES/tvStgodoPOyHlwxwLNB3NP0RtZnm
|
||||
9XM8BZTjs0egnmlKGDV14riruuMGrcJIg+kR3EcN9m68k7V51kLoUugINuTBCAIe
|
||||
96DIT5vFb9pnFT8znRy1/0obp787mF2O1t+r9jNTqgDBFmCRGUBg2jtpR4bYQPEL
|
||||
ZjXMDPcsmOlmbBdsyQvjlOHqXjCoUWwOCBEZdtaLzxaOPrBW5Jh2h3Xz1pV3NdZ/
|
||||
xufAYRhpJamPNiSipRehBZAeQP2ZAyHj/5x3tgEcA+C04Ki8NvuwJx/6T/lGKD+1
|
||||
x3DKsniNi6fEbGlpST/Zp1GY4WyVPcrLa8JxyO+UagECgYEA+gvBBI+LSK5enPXu
|
||||
WooEQP17fKzdZG7Cic8TfTPbtBIcXjNQFLHjFoBNk+TBFCjZma7L+fEcKcDm+Bg1
|
||||
qa4xihOP6BoQqHXZZNZ+9ZU96MPmI9Zb60CMG9lM1VVhSqrm2n3Q+tefod/a2bQk
|
||||
oz8QsdpsUFqVFCF5l+Tb6lp2QN0CgYEA8imPEml6LG35snBY1H6t0ASCHT1oFdHP
|
||||
o01WKQas/tuLO+pMfZrA0zLZBExxZuUJloC6COsTcOrlK+hGM60Ab6TgSPbUvYqH
|
||||
8yMV7SYLvheEngqIiFExmHg79mxnys3Rgv9KMxAV2Ip2wBrBMwUOaURU9pUKXlIN
|
||||
xiaUuevSVEECgYEA0Dbrcs3JUSuKM7AC3DfjlO6/XrFf5hrpOfJKq058m/Uc1EBs
|
||||
Zd8/V2RdtVKeiRf/Ix9QUYA6UHaGnn8iaHpaXD0v7zmNN4pzDaojrIKrO+GtCZid
|
||||
kEd+pE4N0fO4AYJQnA567/aPwi7zQaflfl6smz1kRoE3dLzvUNHNYtgTcq0CgYAm
|
||||
Op1VgMVCwlHK86VyVlVGI5AO4aTO3QJ0ez8A1wb0bOA8Iy7UHVwXe017Oj4kyj+L
|
||||
POMhiUrWZp6rIc4DVmpdNaAapKzNB1OS9JT/jSQJbFkJQgxvyLGVqlV8/3wbLgbH
|
||||
MVobWYy5VJKOnSqmzUOLJrhq/PhYD4gRIgIUn7/igQKBgQCptqrREOq9fXDEpozC
|
||||
39TL4vDrKJWpB1uK6pBEjgEVD/+tcfziVN40j5hnNFDUu/8kxxp9/4w8mPjdJ0CF
|
||||
hWIvrXasjnnFehy6IewWCljNH5CfOM64rDoXaF+ESIM4rLBHbQ8KYvaKkMjOcdNB
|
||||
JG1sRWVU01AwEhnvxS1zbyBtiqA4MDYGCCqFAwIJAwgBMSoEKBqiSOXm8r5I7hEA
|
||||
+gglN/s0bbRCnzopEhuEorpcnDXrktVtjQrmMi0=
|
||||
-----END PRIVATE KEY-----
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -330,10 +330,12 @@ static int test_x509_time(int idx)
|
||||
|
||||
/* if t is not NULL but expected_string is NULL, it is an 'OK' case too */
|
||||
if (t != NULL && x509_format_tests[idx].expected_string) {
|
||||
if (!TEST_str_eq((const char *)t->data,
|
||||
x509_format_tests[idx].expected_string)) {
|
||||
TEST_info("test_x509_time(%d) failed: expected_string %s, got %s\n",
|
||||
idx, x509_format_tests[idx].expected_string, t->data);
|
||||
if (!TEST_mem_eq((const char *)t->data, t->length,
|
||||
x509_format_tests[idx].expected_string,
|
||||
strlen(x509_format_tests[idx].expected_string))) {
|
||||
TEST_info("test_x509_time(%d) failed: expected_string %s, got %.*s\n",
|
||||
idx, x509_format_tests[idx].expected_string, t->length,
|
||||
t->data);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user