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

Support SSLKEYLOGFILE environment variable #797

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DerGenaue
Copy link
Contributor

This allows using eg. Wireshark to debug the encrypted connection

This environment variable apparently is pretty standard in many ssl / tls scenarios such as browsers.
It gives a path to a file, eg. tls.keylog, where all encryption keys are logged.

The resulting file can be plugged into the TLS module of Wireshark which then allows it to decrypt the packages it captured.

Please note that Wireshark needs additional tweaks to recognize DTLS & SCTP inside

# Log TLS secrets to a file, similar to browsers
SSLKEYLOGFILE = os.getenv('SSLKEYLOGFILE')
if SSLKEYLOGFILE:
logger.warning('Logging all TLS keys to %s', SSLKEYLOGFILE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we emitting a warning here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because logging all encryption keys is something you probably don't want by default, so I thought it might be a good idea to log a warning if it is enabled.

@jlaine jlaine added the changes requested Some changes are required before the PR can be merged. label Jan 21, 2023
@jlaine
Copy link
Collaborator

jlaine commented Jan 21, 2023

Please note that Wireshark needs additional tweaks to recognize DTLS & SCTP inside

I'm not sure I understand this comment. Is the produced log file usable in Wireshark or not?

@DerGenaue
Copy link
Contributor Author

DerGenaue commented Jan 21, 2023

Yes, the log file is perfectly usable; Wireshark just was unable to decode the protocol stack
I have reported the problem with SCTP over DTLS with Wireshark and they fixed it so that you can at least manually specify the protocol combination. Automatic detection doesn't work yet, though.
https://gitlab.com/wireshark/wireshark/-/issues/18719

@jlaine
Copy link
Collaborator

jlaine commented Jan 23, 2023

Please note that #813 is going to clash with this, is it possible to enable this logging using PyOpenSSL's API?

EDIT: apparently yes it's possible https://www.pyopenssl.org/en/latest/api/ssl.html#OpenSSL.SSL.Context.set_keylog_callback

@DerGenaue
Copy link
Contributor Author

ah, perfect, you already found it

@jlaine
Copy link
Collaborator

jlaine commented Jan 23, 2023

PR #813 has been merged if you'd care to rework your pr on top of main?

@DerGenaue
Copy link
Contributor Author

I'll do it tomorrow 👍

@jlaine
Copy link
Collaborator

jlaine commented Jan 23, 2023

I'll do it tomorrow +1

Sure take your time, I'm not in a position to ask for immediate turnarounds ATM :)

Thanks again for your PR for the SCTP stack, the issue it fixed had been outstanding for a while.

@DerGenaue
Copy link
Contributor Author

Rebased ✅
Still needs testing

This allows using eg. Wireshark to debug the encrypted connection
@DerGenaue
Copy link
Contributor Author

ok; linter is happy now

@jlaine
Copy link
Collaborator

jlaine commented Jan 28, 2023

I'm a bit spooked by the fact coverage has not changed, who is setting the environment variable in CI?

EDIT: looking at the logs it looks as though the coverage report could not be uploaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes requested Some changes are required before the PR can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants