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

client/server: support for KeyLog trait, SSLKEYLOGFILE #465

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

cpu
Copy link
Member

@cpu cpu commented Sep 20, 2024

For debugging purposes it's quite helpful to be able to log session secrets to a file specified by the SSLKEYLOGFILE env var, for example to use with Wireshark to decrypt session traffic.

This commit adds two methods to rustls-ffi for both client and server configurations to facilitate this:

  1. rustls_server_config_builder_set_key_log_file() and rustls_client_config_builder_set_key_log_file() enable using the Rustls KeyLogFile implementation of the KeyLog trait. This option simply honours the SSLKEYLOGFILE env var and spits out a NSS formatted key log file appropriate for use with Wireshark and other tools that support this format.

  2. rustls_server_config_builder_set_key_log() and rustls_client_config_builder_set_key_log() enable providing C callbacks that will be invoked to decide which secrets are logged, and to do the logging. This allows for fine-grained control over how secrets are logged and may be more appropriate for applications that already handle this task for other TLS backends (e.g. curl).

The client and server examples are updated to optionally use these new features. If the SSLKEYLOG env. var is set, both will use the _set_key_log_file() fns to set up the standard file based key logging. If the STDERRKEYLOG env var is set then both will use the _set_key_log() fns to set up custom callbacks that will print the hex-encoded secret data to stderr as a simple demonstration.

See the upstream rustls::KeyLog trait and rustls::KeyLogFile implementation for more detail.

For debugging purposes it's quite helpful to be able to log session
secrets to a file specified by the `SSLKEYLOGFILE`, for example to use
with Wireshark to decrypt session traffic.

This commit adds two methods to rustls-ffi for both client and server
configurations to facilitate this:

1. `rustls_server_config_builder_set_key_log_file()` and
   `rustls_client_config_builder_set_key_log_file()` enable using the
   Rustls `KeyLogFile` implementation of the `KeyLog` trait. This option
   simply honours the `SSLKEYLOGFILE` env var and spits out a NSS
   formatted key log file appropriate for use with Wireshark and other
   tools that support this format.

2. `rustls_server_config_builder_set_key_log()` and
   `rustls_client_config_builder_set_key_log()` enable providing
   C callbacks that will be invoked to decide which secrets are logged,
   and to do the logging. This allows for fine-grained control over how
   secrets are logged and may be more appropriate for applications that
   already handle this task for other TLS backends (e.g. curl).

The client and server examples are updated to optionally use these new
features. If the `SSLKEYLOG` env. var is set, both will use the
`_set_key_log_file()` fns to set up the standard file based key logging.
If the `STDERRKEYLOG` env var is set then both will use the
`_set_key_log()` fns to set up custom callbacks that will print the
hex-encoded secret data to stderr as a simple demonstration.
@cpu cpu self-assigned this Sep 20, 2024
Copy link
Member

@ctz ctz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cpu
Copy link
Member Author

cpu commented Sep 24, 2024

@jsha Is this a branch you'd like to review pre-merge?

@cpu
Copy link
Member Author

cpu commented Sep 26, 2024

jsha Is this a branch you'd like to review pre-merge?

I'm going to merge this but will handle any feedback separately if it arrives. I'm not planning to cut a release imminently so there's time to address any issues.

@cpu cpu merged commit c73b2e1 into rustls:main Sep 26, 2024
38 checks passed
@cpu cpu deleted the cpu-keylog-wip branch September 26, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants