Skip to content

Commit

Permalink
server.c: observe session callback behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Apr 26, 2024
1 parent 40f4313 commit d17c827
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions rustls-libssl/tests/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ static int sni_callback(SSL *ssl, int *al, void *arg) {
return SSL_TLSEXT_ERR_OK;
}

static int sess_new_callback(SSL *ssl, SSL_SESSION *sess) {
printf("in sess_new_callback\n");
assert(ssl != NULL);
assert(sess != NULL);
unsigned id_len = 0;
SSL_SESSION_get_id(sess, &id_len);
printf(" SSL_SESSION_get_id len=%u\n", id_len);
return 0;
}

static SSL_SESSION *sess_get_callback(SSL *ssl, const uint8_t *id, int id_len,
int *copy) {
(void)id;
printf("in sess_get_callback\n");
assert(ssl != NULL);
printf(" id_len=%d\n", id_len);
*copy = 0;
return NULL;
}

static void sess_remove_callback(SSL_CTX *ctx, SSL_SESSION *sess) {
printf("in sess_remove_callback\n");
assert(ctx != NULL);
assert(sess != NULL);
}

int main(int argc, char **argv) {
if (argc != 5) {
printf("%s <port> <key-file> <cert-chain-file> <cacert>|unauth\n\n",
Expand Down Expand Up @@ -123,6 +149,10 @@ 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);

X509 *server_cert = NULL;
EVP_PKEY *server_key = NULL;
TRACE(SSL_CTX_use_certificate_chain_file(ctx, certfile));
Expand Down

0 comments on commit d17c827

Please sign in to comment.