Skip to content

Commit 1c5d8c8

Browse files
committed
Test for the SSL_OP_IGNORE_UNEXPECTED_EOF option
1 parent 8dc3578 commit 1c5d8c8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/sslapitest.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6672,6 +6672,61 @@ static int test_ticket_callbacks(int tst)
66726672
return testresult;
66736673
}
66746674

6675+
/*
6676+
* Test incorrect shutdown.
6677+
* Test 0: client does not shutdown properly,
6678+
* server does not set SSL_OP_IGNORE_UNEXPECTED_EOF,
6679+
* server should get SSL_ERROR_SSL
6680+
* Test 1: client does not shutdown properly,
6681+
* server sets SSL_OP_IGNORE_UNEXPECTED_EOF,
6682+
* server should get SSL_ERROR_ZERO_RETURN
6683+
*/
6684+
static int test_incorrect_shutdown(int tst)
6685+
{
6686+
SSL_CTX *cctx = NULL, *sctx = NULL;
6687+
SSL *clientssl = NULL, *serverssl = NULL;
6688+
int testresult = 0;
6689+
char buf[80];
6690+
BIO *c2s;
6691+
6692+
if (!TEST_true(create_ssl_ctx_pair(libctx, TLS_server_method(),
6693+
TLS_client_method(), 0, 0,
6694+
&sctx, &cctx, cert, privkey)))
6695+
goto end;
6696+
6697+
if (tst == 1)
6698+
SSL_CTX_set_options(sctx, SSL_OP_IGNORE_UNEXPECTED_EOF);
6699+
6700+
if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
6701+
NULL, NULL)))
6702+
goto end;
6703+
6704+
if (!TEST_true(create_ssl_connection(serverssl, clientssl,
6705+
SSL_ERROR_NONE)))
6706+
goto end;
6707+
6708+
c2s = SSL_get_rbio(serverssl);
6709+
BIO_set_mem_eof_return(c2s, 0);
6710+
6711+
if (!TEST_false(SSL_read(serverssl, buf, sizeof(buf))))
6712+
goto end;
6713+
6714+
if (tst == 0 && !TEST_int_eq(SSL_get_error(serverssl, 0), SSL_ERROR_SSL) )
6715+
goto end;
6716+
if (tst == 1 && !TEST_int_eq(SSL_get_error(serverssl, 0), SSL_ERROR_ZERO_RETURN) )
6717+
goto end;
6718+
6719+
testresult = 1;
6720+
6721+
end:
6722+
SSL_free(serverssl);
6723+
SSL_free(clientssl);
6724+
SSL_CTX_free(sctx);
6725+
SSL_CTX_free(cctx);
6726+
6727+
return testresult;
6728+
}
6729+
66756730
/*
66766731
* Test bi-directional shutdown.
66776732
* Test 0: TLSv1.2
@@ -7685,6 +7740,7 @@ int setup_tests(void)
76857740
ADD_ALL_TESTS(test_ssl_get_shared_ciphers, OSSL_NELEM(shared_ciphers_data));
76867741
ADD_ALL_TESTS(test_ticket_callbacks, 16);
76877742
ADD_ALL_TESTS(test_shutdown, 7);
7743+
ADD_ALL_TESTS(test_incorrect_shutdown, 2);
76887744
ADD_ALL_TESTS(test_cert_cb, 6);
76897745
ADD_ALL_TESTS(test_client_cert_cb, 2);
76907746
ADD_ALL_TESTS(test_ca_names, 3);

0 commit comments

Comments
 (0)