Earlier today I needed to debug an incompatibility between an updated version of Apache and a customer’s HTTPS API client application. Unfortunately, even with the server’s private key Wireshark was unable to decrypt the packet stream. It gave the following message “ssl_decrypt_pre_master_secret session uses DH (17) key exchange, which is impossible to decrypt”.
There are a number of HTTPS debugging proxies (notably Fiddler) for this type of work, but because I was trying to debug what looked to be protocol violation, I wanted something that would preserve the HTTP stream byte for byte. The solution was stunnel to proxy the connect and tcpdump on the local interface. Essentially this creates an intentional man-in-the-middle attack. As with all SSL, it’s important that outgoing domain name (The “connect = www.mydomain.com:443″ line) match the SubjectName of the certificate at the destination. Additionally, newer Apache’s verify that the HTTP Host head match the SNI provided by the SSL connection and will 400 on mismatch.
Stunnel4 Configuration is below:
setuid = stunnel4 setgid = stunnel4 pid = /var/run/stunnel4/stunnel4.pid debug = 7 output = /var/log/stunnel4/stunnel.log cert = /etc/stunnel/www.mydomain.pem options = SINGLE_ECDH_USE options = SINGLE_DH_USE verify = 2 CApath = /etc/ssl/certs [httpsOUT] ; Accept cleartext on port 10443 and relay it to www.mydomain.com:443 accept = 127.0.0.1:10443 client = yes connect = www.mydomain.com:443 [httpsIN] ; Accept SSL stream from client on 443, and relay it to the above cleartext socket @ 127.0.0.1:10443 accept = 443 connect = 127.0.0.1:10443 ; TIMEOUTclose is only necessary for older Microsoft SSL - read up on it in man stunnel4 TIMEOUTclose = 0
TCPDump invokation:
tcpdump -i lo -s0 -w ~/www.mydomain.com.10443.cleartext.pcap tcp port 10443