For reference only, a regular HTTP proxy handles HTTPS requests using the CONNECT method: it reads the host name and port, establishes a TCP connection to this destination server on this port, returns 200 OK , and then simply tunnels that TCP connection to the original client (the fact that SSL / TLS is exchanging over this TCP connection is hardly appropriate).
This is the do_CONNECT method if WEBrick::HTTPProxyServer .
If you need a MITM proxy, i.e. if you want to view SSL / TLS traffic, you can use WEBrick::HTTPProxyServer , but you will need to change do_CONNECT completely :
- First, your proxy server needs to implement a mini-CA that can generate certificates on the fly (otherwise, you can use self-signed certificates if you want to bypass warnings in the browser). Then you import this CA certificate into the browser.
- When you receive a
CONNECT request, you need to create a certificate valid for this host name (preferably with the name Suject Alt. For this host name or common subject name), and also update the socket in the SSL / TLS server socket (using this certificate). If the browser agrees to trust this certificate, then what you get from it in this SSL / TLS socket is plain text traffic. - Then you have to process the requests (get the query string, headers and entity) and use it for use through the regular HTTPS client library. You may be able to send this traffic to the second instance of
WEBrick::HTTPProxyServer , but you will need to configure it to perform outgoing HTTPS requests instead of simple HTTP requests.
source share