Imported OpenSSL 1.1.1b
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2019 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
|
||||
@@ -4028,20 +4028,25 @@ static int test_serverinfo(int tst)
|
||||
* no test vectors so all we do is test that both sides of the communication
|
||||
* produce the same results for different protocol versions.
|
||||
*/
|
||||
#define SMALL_LABEL_LEN 10
|
||||
#define LONG_LABEL_LEN 249
|
||||
static int test_export_key_mat(int tst)
|
||||
{
|
||||
int testresult = 0;
|
||||
SSL_CTX *cctx = NULL, *sctx = NULL, *sctx2 = NULL;
|
||||
SSL *clientssl = NULL, *serverssl = NULL;
|
||||
const char label[] = "test label";
|
||||
const char label[LONG_LABEL_LEN + 1] = "test label";
|
||||
const unsigned char context[] = "context";
|
||||
const unsigned char *emptycontext = NULL;
|
||||
unsigned char ckeymat1[80], ckeymat2[80], ckeymat3[80];
|
||||
unsigned char skeymat1[80], skeymat2[80], skeymat3[80];
|
||||
size_t labellen;
|
||||
const int protocols[] = {
|
||||
TLS1_VERSION,
|
||||
TLS1_1_VERSION,
|
||||
TLS1_2_VERSION,
|
||||
TLS1_3_VERSION,
|
||||
TLS1_3_VERSION,
|
||||
TLS1_3_VERSION
|
||||
};
|
||||
|
||||
@@ -4058,7 +4063,7 @@ static int test_export_key_mat(int tst)
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef OPENSSL_NO_TLS1_3
|
||||
if (tst == 3)
|
||||
if (tst >= 3)
|
||||
return 1;
|
||||
#endif
|
||||
if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
|
||||
@@ -4076,33 +4081,52 @@ static int test_export_key_mat(int tst)
|
||||
SSL_ERROR_NONE)))
|
||||
goto end;
|
||||
|
||||
if (tst == 5) {
|
||||
/*
|
||||
* TLSv1.3 imposes a maximum label len of 249 bytes. Check we fail if we
|
||||
* go over that.
|
||||
*/
|
||||
if (!TEST_int_le(SSL_export_keying_material(clientssl, ckeymat1,
|
||||
sizeof(ckeymat1), label,
|
||||
LONG_LABEL_LEN + 1, context,
|
||||
sizeof(context) - 1, 1), 0))
|
||||
goto end;
|
||||
|
||||
testresult = 1;
|
||||
goto end;
|
||||
} else if (tst == 4) {
|
||||
labellen = LONG_LABEL_LEN;
|
||||
} else {
|
||||
labellen = SMALL_LABEL_LEN;
|
||||
}
|
||||
|
||||
if (!TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat1,
|
||||
sizeof(ckeymat1), label,
|
||||
sizeof(label) - 1, context,
|
||||
labellen, context,
|
||||
sizeof(context) - 1, 1), 1)
|
||||
|| !TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat2,
|
||||
sizeof(ckeymat2), label,
|
||||
sizeof(label) - 1,
|
||||
labellen,
|
||||
emptycontext,
|
||||
0, 1), 1)
|
||||
|| !TEST_int_eq(SSL_export_keying_material(clientssl, ckeymat3,
|
||||
sizeof(ckeymat3), label,
|
||||
sizeof(label) - 1,
|
||||
labellen,
|
||||
NULL, 0, 0), 1)
|
||||
|| !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat1,
|
||||
sizeof(skeymat1), label,
|
||||
sizeof(label) - 1,
|
||||
labellen,
|
||||
context,
|
||||
sizeof(context) -1, 1),
|
||||
1)
|
||||
|| !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat2,
|
||||
sizeof(skeymat2), label,
|
||||
sizeof(label) - 1,
|
||||
labellen,
|
||||
emptycontext,
|
||||
0, 1), 1)
|
||||
|| !TEST_int_eq(SSL_export_keying_material(serverssl, skeymat3,
|
||||
sizeof(skeymat3), label,
|
||||
sizeof(label) - 1,
|
||||
labellen,
|
||||
NULL, 0, 0), 1)
|
||||
/*
|
||||
* Check that both sides created the same key material with the
|
||||
@@ -4131,10 +4155,10 @@ static int test_export_key_mat(int tst)
|
||||
* Check that an empty context and no context produce different results in
|
||||
* protocols less than TLSv1.3. In TLSv1.3 they should be the same.
|
||||
*/
|
||||
if ((tst != 3 && !TEST_mem_ne(ckeymat2, sizeof(ckeymat2), ckeymat3,
|
||||
if ((tst < 3 && !TEST_mem_ne(ckeymat2, sizeof(ckeymat2), ckeymat3,
|
||||
sizeof(ckeymat3)))
|
||||
|| (tst ==3 && !TEST_mem_eq(ckeymat2, sizeof(ckeymat2), ckeymat3,
|
||||
sizeof(ckeymat3))))
|
||||
|| (tst >= 3 && !TEST_mem_eq(ckeymat2, sizeof(ckeymat2), ckeymat3,
|
||||
sizeof(ckeymat3))))
|
||||
goto end;
|
||||
|
||||
testresult = 1;
|
||||
@@ -4226,6 +4250,58 @@ static int test_export_key_mat_early(int idx)
|
||||
|
||||
return testresult;
|
||||
}
|
||||
|
||||
#define NUM_KEY_UPDATE_MESSAGES 40
|
||||
/*
|
||||
* Test KeyUpdate.
|
||||
*/
|
||||
static int test_key_update(void)
|
||||
{
|
||||
SSL_CTX *cctx = NULL, *sctx = NULL;
|
||||
SSL *clientssl = NULL, *serverssl = NULL;
|
||||
int testresult = 0, i, j;
|
||||
char buf[20];
|
||||
static char *mess = "A test message";
|
||||
|
||||
if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),
|
||||
TLS_client_method(),
|
||||
TLS1_3_VERSION,
|
||||
0,
|
||||
&sctx, &cctx, cert, privkey))
|
||||
|| !TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
|
||||
NULL, NULL))
|
||||
|| !TEST_true(create_ssl_connection(serverssl, clientssl,
|
||||
SSL_ERROR_NONE)))
|
||||
goto end;
|
||||
|
||||
for (j = 0; j < 2; j++) {
|
||||
/* Send lots of KeyUpdate messages */
|
||||
for (i = 0; i < NUM_KEY_UPDATE_MESSAGES; i++) {
|
||||
if (!TEST_true(SSL_key_update(clientssl,
|
||||
(j == 0)
|
||||
? SSL_KEY_UPDATE_NOT_REQUESTED
|
||||
: SSL_KEY_UPDATE_REQUESTED))
|
||||
|| !TEST_true(SSL_do_handshake(clientssl)))
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Check that sending and receiving app data is ok */
|
||||
if (!TEST_int_eq(SSL_write(clientssl, mess, strlen(mess)), strlen(mess))
|
||||
|| !TEST_int_eq(SSL_read(serverssl, buf, sizeof(buf)),
|
||||
strlen(mess)))
|
||||
goto end;
|
||||
}
|
||||
|
||||
testresult = 1;
|
||||
|
||||
end:
|
||||
SSL_free(serverssl);
|
||||
SSL_free(clientssl);
|
||||
SSL_CTX_free(sctx);
|
||||
SSL_CTX_free(cctx);
|
||||
|
||||
return testresult;
|
||||
}
|
||||
#endif /* OPENSSL_NO_TLS1_3 */
|
||||
|
||||
static int test_ssl_clear(int idx)
|
||||
@@ -4710,18 +4786,14 @@ static struct info_cb_states_st {
|
||||
{SSL_CB_LOOP, "TWCCS"}, {SSL_CB_LOOP, "TWEE"}, {SSL_CB_LOOP, "TWSC"},
|
||||
{SSL_CB_LOOP, "TRSCV"}, {SSL_CB_LOOP, "TWFIN"}, {SSL_CB_LOOP, "TED"},
|
||||
{SSL_CB_EXIT, NULL}, {SSL_CB_LOOP, "TED"}, {SSL_CB_LOOP, "TRFIN"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_HANDSHAKE_START, NULL},
|
||||
{SSL_CB_LOOP, "TWST"}, {SSL_CB_HANDSHAKE_DONE, NULL},
|
||||
{SSL_CB_HANDSHAKE_START, NULL}, {SSL_CB_LOOP, "TWST"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_ALERT, NULL}, {SSL_CB_HANDSHAKE_START, NULL},
|
||||
{SSL_CB_LOOP, "PINIT "}, {SSL_CB_LOOP, "PINIT "}, {SSL_CB_LOOP, "TRCH"},
|
||||
{SSL_CB_LOOP, "TWSH"}, {SSL_CB_LOOP, "TWCCS"}, {SSL_CB_LOOP, "TWEE"},
|
||||
{SSL_CB_LOOP, "TWFIN"}, {SSL_CB_LOOP, "TED"}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_LOOP, "TED"}, {SSL_CB_LOOP, "TRFIN"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_HANDSHAKE_START, NULL},
|
||||
{SSL_CB_LOOP, "TWST"}, {SSL_CB_HANDSHAKE_DONE, NULL},
|
||||
{SSL_CB_EXIT, NULL}, {0, NULL},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_LOOP, "TWST"},
|
||||
{SSL_CB_LOOP, "TWST"}, {SSL_CB_EXIT, NULL}, {SSL_CB_ALERT, NULL},
|
||||
{SSL_CB_HANDSHAKE_START, NULL}, {SSL_CB_LOOP, "PINIT "},
|
||||
{SSL_CB_LOOP, "PINIT "}, {SSL_CB_LOOP, "TRCH"}, {SSL_CB_LOOP, "TWSH"},
|
||||
{SSL_CB_LOOP, "TWCCS"}, {SSL_CB_LOOP, "TWEE"}, {SSL_CB_LOOP, "TWFIN"},
|
||||
{SSL_CB_LOOP, "TED"}, {SSL_CB_EXIT, NULL}, {SSL_CB_LOOP, "TED"},
|
||||
{SSL_CB_LOOP, "TRFIN"}, {SSL_CB_HANDSHAKE_DONE, NULL},
|
||||
{SSL_CB_LOOP, "TWST"}, {SSL_CB_EXIT, NULL}, {0, NULL},
|
||||
}, {
|
||||
/* TLSv1.3 client followed by resumption */
|
||||
{SSL_CB_HANDSHAKE_START, NULL}, {SSL_CB_LOOP, "PINIT "},
|
||||
@@ -4729,20 +4801,16 @@ static struct info_cb_states_st {
|
||||
{SSL_CB_LOOP, "TRSH"}, {SSL_CB_LOOP, "TREE"}, {SSL_CB_LOOP, "TRSC"},
|
||||
{SSL_CB_LOOP, "TRSCV"}, {SSL_CB_LOOP, "TRFIN"}, {SSL_CB_LOOP, "TWCCS"},
|
||||
{SSL_CB_LOOP, "TWFIN"}, {SSL_CB_HANDSHAKE_DONE, NULL},
|
||||
{SSL_CB_EXIT, NULL}, {SSL_CB_HANDSHAKE_START, NULL},
|
||||
{SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "TRST"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_HANDSHAKE_START, NULL}, {SSL_CB_LOOP, "SSLOK "},
|
||||
{SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "TRST"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_EXIT, NULL}, {SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "SSLOK "},
|
||||
{SSL_CB_LOOP, "TRST"}, {SSL_CB_EXIT, NULL}, {SSL_CB_LOOP, "SSLOK "},
|
||||
{SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "TRST"}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_ALERT, NULL}, {SSL_CB_HANDSHAKE_START, NULL},
|
||||
{SSL_CB_LOOP, "PINIT "}, {SSL_CB_LOOP, "TWCH"}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_LOOP, "TWCH"}, {SSL_CB_LOOP, "TRSH"}, {SSL_CB_LOOP, "TREE"},
|
||||
{SSL_CB_LOOP, "TRFIN"}, {SSL_CB_LOOP, "TWCCS"}, {SSL_CB_LOOP, "TWFIN"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_HANDSHAKE_START, NULL}, {SSL_CB_LOOP, "SSLOK "},
|
||||
{SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "TRST"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_EXIT, NULL}, {0, NULL},
|
||||
{SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "TRST"},
|
||||
{SSL_CB_EXIT, NULL}, {0, NULL},
|
||||
}, {
|
||||
/* TLSv1.3 server, early_data */
|
||||
{SSL_CB_HANDSHAKE_START, NULL}, {SSL_CB_LOOP, "PINIT "},
|
||||
@@ -4751,8 +4819,7 @@ static struct info_cb_states_st {
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_EXIT, NULL},
|
||||
{SSL_CB_HANDSHAKE_START, NULL}, {SSL_CB_LOOP, "TED"},
|
||||
{SSL_CB_LOOP, "TED"}, {SSL_CB_LOOP, "TWEOED"}, {SSL_CB_LOOP, "TRFIN"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_HANDSHAKE_START, NULL},
|
||||
{SSL_CB_LOOP, "TWST"}, {SSL_CB_HANDSHAKE_DONE, NULL},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_LOOP, "TWST"},
|
||||
{SSL_CB_EXIT, NULL}, {0, NULL},
|
||||
}, {
|
||||
/* TLSv1.3 client, early_data */
|
||||
@@ -4763,9 +4830,8 @@ static struct info_cb_states_st {
|
||||
{SSL_CB_LOOP, "TED"}, {SSL_CB_LOOP, "TRSH"}, {SSL_CB_LOOP, "TREE"},
|
||||
{SSL_CB_LOOP, "TRFIN"}, {SSL_CB_LOOP, "TPEDE"}, {SSL_CB_LOOP, "TWEOED"},
|
||||
{SSL_CB_LOOP, "TWFIN"}, {SSL_CB_HANDSHAKE_DONE, NULL},
|
||||
{SSL_CB_EXIT, NULL}, {SSL_CB_HANDSHAKE_START, NULL},
|
||||
{SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "TRST"},
|
||||
{SSL_CB_HANDSHAKE_DONE, NULL}, {SSL_CB_EXIT, NULL}, {0, NULL},
|
||||
{SSL_CB_EXIT, NULL}, {SSL_CB_LOOP, "SSLOK "}, {SSL_CB_LOOP, "SSLOK "},
|
||||
{SSL_CB_LOOP, "TRST"}, {SSL_CB_EXIT, NULL}, {0, NULL},
|
||||
}, {
|
||||
{0, NULL},
|
||||
}
|
||||
@@ -4804,8 +4870,11 @@ static void sslapi_info_callback(const SSL *s, int where, int ret)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check that, if we've got SSL_CB_HANDSHAKE_DONE we are not in init */
|
||||
if ((where & SSL_CB_HANDSHAKE_DONE) && SSL_in_init((SSL *)s) != 0) {
|
||||
/*
|
||||
* Check that, if we've got SSL_CB_HANDSHAKE_DONE we are not in init
|
||||
*/
|
||||
if ((where & SSL_CB_HANDSHAKE_DONE)
|
||||
&& SSL_in_init((SSL *)s) != 0) {
|
||||
info_cb_failed = 1;
|
||||
return;
|
||||
}
|
||||
@@ -5384,7 +5453,7 @@ static int test_shutdown(int tst)
|
||||
|
||||
if (tst == 3) {
|
||||
if (!TEST_true(create_bare_ssl_connection(serverssl, clientssl,
|
||||
SSL_ERROR_NONE))
|
||||
SSL_ERROR_NONE, 1))
|
||||
|| !TEST_ptr_ne(sess = SSL_get_session(clientssl), NULL)
|
||||
|| !TEST_false(SSL_SESSION_is_resumable(sess)))
|
||||
goto end;
|
||||
@@ -5909,9 +5978,10 @@ int setup_tests(void)
|
||||
ADD_ALL_TESTS(test_custom_exts, 3);
|
||||
#endif
|
||||
ADD_ALL_TESTS(test_serverinfo, 8);
|
||||
ADD_ALL_TESTS(test_export_key_mat, 4);
|
||||
ADD_ALL_TESTS(test_export_key_mat, 6);
|
||||
#ifndef OPENSSL_NO_TLS1_3
|
||||
ADD_ALL_TESTS(test_export_key_mat_early, 3);
|
||||
ADD_TEST(test_key_update);
|
||||
#endif
|
||||
ADD_ALL_TESTS(test_ssl_clear, 2);
|
||||
ADD_ALL_TESTS(test_max_fragment_len_ext, OSSL_NELEM(max_fragment_len_test));
|
||||
|
||||
Reference in New Issue
Block a user