socat port forwarding for https

Denis Shevchenko picture Denis Shevchenko · Jan 14, 2016 · Viewed 34.7k times · Source

I can use socat for the port forwarding like this:

socat TCP4-LISTEN:8080 TCP4:123.456.789.12:80

In this case, it works perfectly: all http-requests to localhost:8080 will be redirected to 123.456.789.12:80.

But how can I use such forwarding for https-requests?

UPDATE: I need a single socat process between Firefox and remote server. socat is just a forwarder (proxy redirector), nothing more. Something like this:

Firefox -> socat -> server
       ------------>
           https

Answer

Thor picture Thor · Jan 18, 2016

Normally https servers run on port 443, so maybe that is your issue?

Trying to browse through socat to google.com with https works, albeit with an SSL certificate warning:

socat TCP-LISTEN:8080,fork,reuseaddr TCP:google.com:443

(use fork and reuseaddr to allow multiple connections and fast ip:port reuse, but beaware of the caveats).

Now you can access https at google from a browser, just go to https://localhost:8080.