From 171ec60f78616dcfd8ec9b1a5091e77e274625fd Mon Sep 17 00:00:00 2001 From: Joseph Birr-Pixton Date: Fri, 3 May 2024 16:24:45 +0100 Subject: [PATCH] server.c: allow specification of session cache modes --- rustls-libssl/tests/runner.rs | 2 ++ rustls-libssl/tests/server.c | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/rustls-libssl/tests/runner.rs b/rustls-libssl/tests/runner.rs index b3bd610..7b23035 100644 --- a/rustls-libssl/tests/runner.rs +++ b/rustls-libssl/tests/runner.rs @@ -297,6 +297,7 @@ fn server() { "test-ca/rsa/server.key", "test-ca/rsa/server.cert", "unauth", + "internal+external", ]) .stdout(Stdio::piped()) .spawn() @@ -315,6 +316,7 @@ fn server() { "test-ca/rsa/server.key", "test-ca/rsa/server.cert", "unauth", + "internal+external", ]) .stdout(Stdio::piped()) .spawn() diff --git a/rustls-libssl/tests/server.c b/rustls-libssl/tests/server.c index 9e80647..9356a55 100644 --- a/rustls-libssl/tests/server.c +++ b/rustls-libssl/tests/server.c @@ -98,14 +98,15 @@ static void sess_remove_callback(SSL_CTX *ctx, SSL_SESSION *sess) { } int main(int argc, char **argv) { - if (argc != 5) { - printf("%s |unauth\n\n", + if (argc != 6) { + printf("%s |unauth " + "none|internal|external|internal+external\n\n", argv[0]); return 1; } const char *port = argv[1], *keyfile = argv[2], *certfile = argv[3], - *cacert = argv[4]; + *cacert = argv[4], *cache = argv[5]; int listener = TRACE(socket(AF_INET, SOCK_STREAM, 0)); struct sockaddr_in us, them; @@ -151,12 +152,21 @@ int main(int argc, char **argv) { SSL_CTX_set_tlsext_servername_arg(ctx, &sni_cookie); dump_openssl_error_stack(); - SSL_CTX_sess_set_new_cb(ctx, sess_new_callback); - SSL_CTX_sess_set_get_cb(ctx, sess_get_callback); - SSL_CTX_sess_set_remove_cb(ctx, sess_remove_callback); - TRACE(SSL_CTX_sess_set_cache_size(ctx, 10)); - TRACE(SSL_CTX_sess_get_cache_size(ctx)); - TRACE(SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_SERVER)); + if (strstr(cache, "external")) { + SSL_CTX_sess_set_new_cb(ctx, sess_new_callback); + SSL_CTX_sess_set_get_cb(ctx, sess_get_callback); + SSL_CTX_sess_set_remove_cb(ctx, sess_remove_callback); + } + + if (strstr(cache, "internal")) { + TRACE(SSL_CTX_sess_set_cache_size(ctx, 10)); + TRACE(SSL_CTX_sess_get_cache_size(ctx)); + TRACE(SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_SERVER)); + } + + if (strcmp(cache, "none") == 0) { + TRACE(SSL_CTX_set_session_cache_mode(ctx, 0)); + } X509 *server_cert = NULL; EVP_PKEY *server_key = NULL;