Skip to content

Instantly share code, notes, and snippets.

@dawncold
Created June 22, 2021 00:16
Show Gist options
  • Save dawncold/ea829510d14cf8f1ccf026081c84c50b to your computer and use it in GitHub Desktop.
Save dawncold/ea829510d14cf8f1ccf026081c84c50b to your computer and use it in GitHub Desktop.
How to debug Twisted TLS with wireshark
# 1. setup environment SSLKEYLOGFILE, value is a file path, I set it to /tmp/.ssl-key.log
# 2. put /tmp/.ssl-key.log to wireshark TLS pre-master key path
# 3. use following code, setup pyOpenSSL key log callback
certificateOptions = OpenSSLCertificateOptions(
trustRoot=platformTrust(),
acceptableProtocols=[b'h2'],
)
ctx = certificateOptions.getContext()
def append_to_key_log_file(key):
log_file_path = os.getenv('SSLKEYLOGFILE')
with open(log_file_path, 'ab+') as f:
f.write(key + b'\n')
ctx.set_keylog_callback(lambda _, key: append_to_key_log_file(key))
options = ClientTLSOptions(AUTHORITY, ctx)
connectProtocol(
SSL4ClientEndpoint(reactor, AUTHORITY, 443, options),
H2Protocol()
)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment