Log SSL/TLS keys for decrypting SSL/TLS connections made in Python

segevfiner segevfiner Last update: Aug 23, 2022

sslkeylog

PyPIDocumentation StatusBuild & Test Status

This is an implementation of the SSLKEYLOGFILE facility, available in Firefox andChromium/Google Chrome, that is supported by Wireshark in order to decrypt SSL/TLS connectionseven when you don't have the private key, or when using key exchange methods that will preventdecryption even if you do (Such as Diffie-Hellman).

This is for the standard library ssl module, it won't work for other ssl modules.

Note:

Python 3.8+ includes built-in support for generating an SSL key log file viassl.SSLContext.keylog_filename, and will also enable it when the SSLKEYLOGFILEenvironment variable is set when creating a context via ssl.create_default_context.

This package uses the same callback the built-in implementation is using, which will likely causeboth implementations to trample each other, causing the other not to work, or other unintendedconsequences. As such, you should probably not enable both at the same time.

Quick Start

import osimport sslkeylogsslkeylog.set_keylog(os.environ.get('SSLKEYLOGFILE'))  # Or directly specify a path# Do anything involving SSL (Using the built-in ssl module)

Set the SSLKEYLOGFILE environment variable if you use it, and set "(Pre)-Master-Secret logfilename" in Wireshark's SSL protocol preferences to the resulting file.

Links

License

MIT License, except OpenSSL which is licensed under it's own license. See LICENSE.txt

This product includes software developed by the OpenSSL Projectfor use in the OpenSSL Toolkit (http://www.openssl.org/)

PRAGMA foreign_keys = off; BEGIN TRANSACTION; COMMIT TRANSACTION; PRAGMA foreign_keys = on;

Subscribe to our newsletter