Skip to content

Commit

Permalink
server.c: allow specification of session cache modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed May 3, 2024
1 parent 5394c7e commit 171ec60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions rustls-libssl/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ fn server() {
"test-ca/rsa/server.key",
"test-ca/rsa/server.cert",
"unauth",
"internal+external",
])
.stdout(Stdio::piped())
.spawn()
Expand All @@ -315,6 +316,7 @@ fn server() {
"test-ca/rsa/server.key",
"test-ca/rsa/server.cert",
"unauth",
"internal+external",
])
.stdout(Stdio::piped())
.spawn()
Expand Down
28 changes: 19 additions & 9 deletions rustls-libssl/tests/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <port> <key-file> <cert-chain-file> <cacert>|unauth\n\n",
if (argc != 6) {
printf("%s <port> <key-file> <cert-chain-file> <cacert>|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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 171ec60

Please sign in to comment.