brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: openssl s_client -keylogfile lets Wireshark decrypt your own TLS test

Openssl
~/tips/tip-openssl-s-client-keylogfile

| openssl s_client -connect example.com:443 -servername example.com -quiet -keylogfile keys.log

Write the TLS session secrets to a file so a packet capture of that connection can be decrypted.

Encrypted traffic in a capture is a wall of noise. If you control the client, you can make it write its session keys to a file, and Wireshark uses that file to show the plain text.

Start a capture, then connect with -keylogfile:

sudo tcpdump -i any -w tls.pcap host example.com and port 443 &
printf 'GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n' \
  | openssl s_client -connect example.com:443 -servername example.com -quiet -keylogfile keys.log

The file starts with a comment line and then holds lines like SERVER_HANDSHAKE_TRAFFIC_SECRET followed by long hex values. In Wireshark, open the capture and point Preferences, Protocols, TLS, (Pre)-Master-Secret log filename at keys.log. The HTTP request and response then show up decrypted.

This is the same format browsers write when you set the SSLKEYLOGFILE variable, so you can mix it with that workflow.

Treat keys.log as a secret. Anyone with the file and the capture can read that session, including cookies or tokens you sent. I’d delete both afterwards. It only works for connections made by this client, and you can never decrypt other people’s traffic this way, which is the point of TLS.

Further reading: OpenSSL: openssl-s_client, Wireshark: TLS decryption

More Openssl tips openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem printf %s hello | openssl dgst -sha256 -hmac secret openssl pkcs12 -legacy -in old.pfx -nokeys echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d All Openssl tips (34) All topics

Link