Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new listener opt: sslkeylogfile #341

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions c_src/quicer_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,6 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
// A monitor is automatically removed when it triggers or when the
// resource is deallocated.
status = handle_connection_event_connected(c_ctx, Event);
// Client dump SSL KEY
if (NULL != c_ctx->TlsSecrets && NULL != c_ctx->ssl_keylogfile)
{
dump_sslkeylogfile(c_ctx->ssl_keylogfile, *(c_ctx->TlsSecrets));
}
break;
case QUIC_CONNECTION_EVENT_PEER_STREAM_STARTED:
//
Expand Down Expand Up @@ -1187,6 +1182,15 @@ handle_connection_event_connected(QuicerConnCTX *c_ctx,
ERL_NIF_TERM report = make_event_with_props(
c_ctx->env, ATOM_CONNECTED, ConnHandle, props_name, props_value, 2);

// Client&Server Dump SSL Key Log File
if (NULL != c_ctx->TlsSecrets && NULL != c_ctx->ssl_keylogfile)
{
dump_sslkeylogfile(c_ctx->ssl_keylogfile, *(c_ctx->TlsSecrets));
// @NOTE: only free ssl_keylogfile not TlsSecrets
CXPLAT_FREE(c_ctx->ssl_keylogfile, QUICER_TRACE);
c_ctx->ssl_keylogfile = NULL;
}

// testing this, just unblock acceptor
// should pick a 'acceptor' here?
if (!enif_send(NULL, acc_pid, NULL, report))
Expand Down
1 change: 1 addition & 0 deletions c_src/quicer_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ deinit_l_ctx(QuicerListenerCTX *l_ctx)
#endif // QUICER_USE_TRUSTED_STORE

AcceptorQueueDestroy(l_ctx->acceptor_queue);
CXPLAT_FREE(l_ctx->ssl_keylogfile, QUICER_TRACE);
enif_mutex_destroy(l_ctx->lock);
enif_free_env(l_ctx->env);
}
Expand Down
2 changes: 2 additions & 0 deletions c_src/quicer_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ typedef struct QuicerListenerCTX
BOOLEAN is_stopped;
BOOLEAN allow_insecure;
CXPLAT_LIST_ENTRY RegistrationLink;
char *ssl_keylogfile;
uint16_t ssl_keylogfile_len;
void *reserved1;
void *reserved2;
void *reserved3;
Expand Down
16 changes: 16 additions & 0 deletions c_src/quicer_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ ServerListenerCallback(__unused_parm__ HQUIC Listener,
(void *)ServerConnectionCallback,
c_ctx);

if (l_ctx->ssl_keylogfile)
{
char *ssl_keylogfile
= CXPLAT_ALLOC_NONPAGED(l_ctx->ssl_keylogfile_len, QUICER_TRACE);
strncpy(ssl_keylogfile,
l_ctx->ssl_keylogfile,
l_ctx->ssl_keylogfile_len);
set_conn_sslkeylogfile(c_ctx, ssl_keylogfile);
}

enif_clear_env(env);
break;

Expand Down Expand Up @@ -401,6 +411,12 @@ listen2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
goto exit;
}

l_ctx->ssl_keylogfile
= str_from_map(env, ATOM_SSL_KEYLOGFILE_NAME, &options, NULL, PATH_MAX);
l_ctx->ssl_keylogfile_len
= l_ctx->ssl_keylogfile ? strlen(l_ctx->ssl_keylogfile) + 1 : 0;
CXPLAT_FRE_ASSERT(l_ctx->ssl_keylogfile_len < PATH_MAX);

// Start Listener
Status = MsQuic->ListenerStart(
l_ctx->Listener, alpn_buffers, alpn_buffer_length, &Address);
Expand Down
12 changes: 9 additions & 3 deletions c_src/quicer_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,21 @@ parse_sslkeylogfile_option(ErlNifEnv *env,
ERL_NIF_TERM eoptions,
QuicerConnCTX *c_ctx)
{
QUIC_STATUS Status;

char *keylogfile = str_from_map(
env, ATOM_SSL_KEYLOGFILE_NAME, &eoptions, NULL, PATH_MAX + 1);
char *keylogfile
= str_from_map(env, ATOM_SSL_KEYLOGFILE_NAME, &eoptions, NULL, PATH_MAX);

if (!keylogfile)
{
return;
}
set_conn_sslkeylogfile(c_ctx, keylogfile);
}

void
set_conn_sslkeylogfile(QuicerConnCTX *c_ctx, char *keylogfile)
{
QUIC_STATUS Status;

// Allocate the TLS secrets
QUIC_TLS_SECRETS *TlsSecrets
Expand Down
2 changes: 2 additions & 0 deletions c_src/quicer_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ eoptions_to_cred_config(ErlNifEnv *env,
ERL_NIF_TERM eoptions,
QUIC_CREDENTIAL_CONFIG *CredConfig,
X509_STORE **trusted_store);

void set_conn_sslkeylogfile(QuicerConnCTX *c_ctx, char *keylogfile);
#endif // QUICER_TLS_H_
8 changes: 6 additions & 2 deletions test/quicer_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2543,9 +2543,12 @@ tc_stream_send_shutdown_complete(Config) ->
tc_conn_opt_sslkeylogfile(Config) ->
Port = select_port(),
TargetFName = "SSLKEYLOGFILE",
ServerTargetFName = "SERVERSSLKEYLOGFILE",
file:delete(TargetFName),
application:ensure_all_started(quicer),
ListenerOpts = [{conn_acceptors, 32} | default_listen_opts(Config)],
ListenerOpts = [
{sslkeylogfile, ServerTargetFName}, {conn_acceptors, 32} | default_listen_opts(Config)
],
ConnectionOpts = [
{conn_callback, quicer_server_conn_callback},
{stream_acceptors, 32}
Expand All @@ -2569,7 +2572,8 @@ tc_conn_opt_sslkeylogfile(Config) ->
),
quicer:close_connection(Conn),
timer:sleep(100),
{ok, #file_info{type = regular}} = file:read_file_info(TargetFName).
{ok, #file_info{type = regular}} = file:read_file_info(TargetFName),
{ok, #file_info{type = regular}} = file:read_file_info(ServerTargetFName).

tc_insecure_traffic(Config) ->
Port = select_port(),
Expand Down
Loading