Skip to content

Commit

Permalink
Add a test for SSL_clear()
Browse files Browse the repository at this point in the history
Reviewed-by: Ben Kaduk <[email protected]>
Reviewed-by: Bernd Edlinger <[email protected]>
(Merged from openssl#3954)
  • Loading branch information
mattcaswell committed Jul 18, 2017
1 parent 59ff3f0 commit e11b6aa
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/sslapitest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,60 @@ static int test_export_key_mat(int tst)
return testresult;
}

static int test_ssl_clear(int idx)
{
SSL_CTX *cctx = NULL, *sctx = NULL;
SSL *clientssl = NULL, *serverssl = NULL;
int testresult = 0;

#ifdef OPENSSL_NO_TLS1_2
if (idx == 1)
return 1;
#endif

/* Create an initial connection */
if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),
TLS_client_method(), &sctx,
&cctx, cert, privkey))
|| (idx == 1
&& !TEST_true(SSL_CTX_set_max_proto_version(cctx,
TLS1_2_VERSION)))
|| !TEST_true(create_ssl_objects(sctx, cctx, &serverssl,
&clientssl, NULL, NULL))
|| !TEST_true(create_ssl_connection(serverssl, clientssl,
SSL_ERROR_NONE)))
goto end;

SSL_shutdown(clientssl);
SSL_shutdown(serverssl);
SSL_free(serverssl);
serverssl = NULL;

/* Clear clientssl - we're going to reuse the object */
if (!TEST_true(SSL_clear(clientssl)))
goto end;

if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
NULL, NULL))
|| !TEST_true(create_ssl_connection(serverssl, clientssl,
SSL_ERROR_NONE))
|| !TEST_true(SSL_session_reused(clientssl)))
goto end;

SSL_shutdown(clientssl);
SSL_shutdown(serverssl);

testresult = 1;

end:
SSL_free(serverssl);
SSL_free(clientssl);
SSL_CTX_free(sctx);
SSL_CTX_free(cctx);

return testresult;
}

int test_main(int argc, char *argv[])
{
int testresult = 1;
Expand Down Expand Up @@ -2704,6 +2758,7 @@ int test_main(int argc, char *argv[])
#endif
ADD_ALL_TESTS(test_serverinfo, 8);
ADD_ALL_TESTS(test_export_key_mat, 4);
ADD_ALL_TESTS(test_ssl_clear, 2);

testresult = run_tests(argv[0]);

Expand Down

0 comments on commit e11b6aa

Please sign in to comment.