Skip to content

Commit

Permalink
Add a test for late loading of an ENGINE in TLS
Browse files Browse the repository at this point in the history
Confirm that using an ENGINE works as expected with TLS even if it is
loaded late (after construction of the SSL_CTX).

(cherry picked from commit a9c97da)

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from #22865)

(cherry picked from commit dda9208)
  • Loading branch information
mattcaswell committed Dec 12, 2023
1 parent a52ca9c commit 9ffd4a3
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions test/sslapitest.c
Original file line number Diff line number Diff line change
Expand Up @@ -10128,6 +10128,27 @@ static int test_load_dhfile(void)
}

#if !defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_DYNAMIC_ENGINE)

static ENGINE *load_dasync(void)
{
ENGINE *e;

if (!TEST_ptr(e = ENGINE_by_id("dasync")))
return NULL;

if (!TEST_true(ENGINE_init(e))) {
ENGINE_free(e);
return NULL;
}

if (!TEST_true(ENGINE_register_ciphers(e))) {
ENGINE_free(e);
return NULL;
}

return e;
}

/*
* Test TLSv1.2 with a pipeline capable cipher. TLSv1.3 and DTLS do not
* support this yet. The only pipeline capable cipher that we have is in the
Expand All @@ -10143,6 +10164,8 @@ static int test_load_dhfile(void)
* Test 4: Client has pipelining enabled, server does not: more data than all
* the available pipelines can take
* Test 5: Client has pipelining enabled, server does not: Maximum size pipeline
* Test 6: Repeat of test 0, but the engine is loaded late (after the SSL_CTX
* is created)
*/
static int test_pipelining(int idx)
{
Expand All @@ -10155,25 +10178,28 @@ static int test_pipelining(int idx)
size_t written, readbytes, offset, msglen, fragsize = 10, numpipes = 5;
size_t expectedreads;
unsigned char *buf = NULL;
ENGINE *e;

if (!TEST_ptr(e = ENGINE_by_id("dasync")))
return 0;
ENGINE *e = NULL;

if (!TEST_true(ENGINE_init(e))) {
ENGINE_free(e);
return 0;
if (idx != 6) {
e = load_dasync();
if (e == NULL)
return 0;
}

if (!TEST_true(ENGINE_register_ciphers(e)))
goto end;

if (!TEST_true(create_ssl_ctx_pair(libctx, TLS_server_method(),
TLS_client_method(), 0,
TLS1_2_VERSION, &sctx, &cctx, cert,
privkey)))
goto end;

if (idx == 6) {
e = load_dasync();
if (e == NULL)
goto end;
/* Now act like test 0 */
idx = 0;
}

if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl,
&clientssl, NULL, NULL)))
goto end;
Expand Down Expand Up @@ -10309,9 +10335,11 @@ static int test_pipelining(int idx)
SSL_free(clientssl);
SSL_CTX_free(sctx);
SSL_CTX_free(cctx);
ENGINE_unregister_ciphers(e);
ENGINE_finish(e);
ENGINE_free(e);
if (e != NULL) {
ENGINE_unregister_ciphers(e);
ENGINE_finish(e);
ENGINE_free(e);
}
OPENSSL_free(buf);
if (fragsize == SSL3_RT_MAX_PLAIN_LENGTH)
OPENSSL_free(msg);
Expand Down Expand Up @@ -10684,7 +10712,7 @@ int setup_tests(void)
ADD_ALL_TESTS(test_serverinfo_custom, 4);
#endif
#if !defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_DYNAMIC_ENGINE)
ADD_ALL_TESTS(test_pipelining, 6);
ADD_ALL_TESTS(test_pipelining, 7);
#endif
ADD_ALL_TESTS(test_handshake_retry, 16);
return 1;
Expand Down

0 comments on commit 9ffd4a3

Please sign in to comment.