Test that we can process a KeyUpdate received after we sent close_notify
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7114)
Kurt Roeckx authored 5 years ago
Matt Caswell committed 5 years ago
5340 | 5340 | * Test 1: TLSv1.2, server continues to read/write after client shutdown |
5341 | 5341 | * Test 2: TLSv1.3, no pending NewSessionTicket messages |
5342 | 5342 | * Test 3: TLSv1.3, pending NewSessionTicket messages |
5343 | * Test 4: TLSv1.3, server continues to read/write after client shutdown, client | |
5344 | * reads it | |
5343 | * Test 4: TLSv1.3, server continues to read/write after client shutdown, server | |
5344 | * sends key update, client reads it | |
5345 | 5345 | * Test 5: TLSv1.3, server continues to read/write after client shutdown, client |
5346 | 5346 | * doesn't read it |
5347 | 5347 | */ |
5353 | 5353 | char msg[] = "A test message"; |
5354 | 5354 | char buf[80]; |
5355 | 5355 | size_t written, readbytes; |
5356 | SSL_SESSION *sess; | |
5356 | 5357 | |
5357 | 5358 | #ifdef OPENSSL_NO_TLS1_2 |
5358 | 5359 | if (tst <= 1) |
5375 | 5376 | |
5376 | 5377 | if (tst == 3) { |
5377 | 5378 | if (!TEST_true(create_bare_ssl_connection(serverssl, clientssl, |
5378 | SSL_ERROR_NONE))) | |
5379 | SSL_ERROR_NONE)) | |
5380 | || !TEST_ptr_ne(sess = SSL_get_session(clientssl), NULL) | |
5381 | || !TEST_false(SSL_SESSION_is_resumable(sess))) | |
5379 | 5382 | goto end; |
5380 | 5383 | } else if (!TEST_true(create_ssl_connection(serverssl, clientssl, |
5381 | SSL_ERROR_NONE))) { | |
5384 | SSL_ERROR_NONE)) | |
5385 | || !TEST_ptr_ne(sess = SSL_get_session(clientssl), NULL) | |
5386 | || !TEST_true(SSL_SESSION_is_resumable(sess))) { | |
5382 | 5387 | goto end; |
5383 | 5388 | } |
5384 | 5389 | |
5399 | 5404 | * Even though we're shutdown on receive we should still be |
5400 | 5405 | * able to write. |
5401 | 5406 | */ |
5402 | || !TEST_true(SSL_write(serverssl, msg, sizeof(msg))) | |
5403 | || !TEST_int_eq(SSL_shutdown(serverssl), 1)) | |
5407 | || !TEST_true(SSL_write(serverssl, msg, sizeof(msg)))) | |
5408 | goto end; | |
5409 | if (tst == 4 && | |
5410 | (!TEST_true(SSL_key_update(serverssl, SSL_KEY_UPDATE_REQUESTED)) | |
5411 | || !TEST_true(SSL_write(serverssl, msg, sizeof(msg))))) | |
5412 | goto end; | |
5413 | if (!TEST_int_eq(SSL_shutdown(serverssl), 1)) | |
5404 | 5414 | goto end; |
5405 | 5415 | if (tst == 4) { |
5406 | /* Should still be able to read data from server */ | |
5416 | /* Should still be able to read data from server */ | |
5407 | 5417 | if (!TEST_true(SSL_read_ex(clientssl, buf, sizeof(buf), |
5408 | &readbytes)) | |
5418 | &readbytes)) | |
5419 | || !TEST_size_t_eq(readbytes, sizeof(msg)) | |
5420 | || !TEST_int_eq(memcmp(msg, buf, readbytes), 0) | |
5421 | || !TEST_true(SSL_read_ex(clientssl, buf, sizeof(buf), | |
5422 | &readbytes)) | |
5409 | 5423 | || !TEST_size_t_eq(readbytes, sizeof(msg)) |
5410 | 5424 | || !TEST_int_eq(memcmp(msg, buf, readbytes), 0)) |
5411 | 5425 | goto end; |
5429 | 5443 | */ |
5430 | 5444 | || !TEST_false(SSL_write_ex(serverssl, msg, sizeof(msg), &written)) |
5431 | 5445 | || !TEST_int_eq(SSL_shutdown(clientssl), 1) |
5446 | || !TEST_ptr_ne(sess = SSL_get_session(clientssl), NULL) | |
5447 | || !TEST_true(SSL_SESSION_is_resumable(sess)) | |
5432 | 5448 | || !TEST_int_eq(SSL_shutdown(serverssl), 1)) |
5433 | 5449 | goto end; |
5434 | 5450 | } else if (tst == 4) { |
5437 | 5453 | * received by the server which has responded with a close_notify. The |
5438 | 5454 | * client needs to read the close_notify sent by the server. |
5439 | 5455 | */ |
5440 | if (!TEST_int_eq(SSL_shutdown(clientssl), 1)) | |
5456 | if (!TEST_int_eq(SSL_shutdown(clientssl), 1) | |
5457 | || !TEST_ptr_ne(sess = SSL_get_session(clientssl), NULL) | |
5458 | || !TEST_true(SSL_SESSION_is_resumable(sess))) | |
5441 | 5459 | goto end; |
5442 | 5460 | } else { |
5443 | 5461 | /* |