Skip to content

Do TLS with the target inside the proxy tunnel - #115

Open
liquidsec wants to merge 1 commit into
devfrom
fix-proxy-tls
Open

liquidsec wants to merge 1 commit into
devfrom
fix-proxy-tls

Conversation

@liquidsec

Copy link
Copy Markdown
Collaborator

Fixes #89.

HTTPS through a CONNECT or SOCKS5 proxy never did TLS with the target. hyper-util's Tunnel and SocksV5 call the inner connector with the proxy's URI, so our connector saw http and skipped TLS, and the request went into the tunnel as plaintext. In practice that means proxied HTTPS just failed (a real HTTPS server rejects plaintext, and the new tests got client error (Canceled)), unless the proxy passed plaintext along, in which case the request leaked.

OpenSslConnector now opens the tunnel itself, using the CONNECT and SOCKS5 handshakes raw_connect already uses, and then does TLS with the target over it. Connections are still pooled, and the TCP connection to the proxy is made the same way as before. hyper-util's proxy connectors are gone, along with its client-proxy feature.

Behavior changes:

  • verify_certs, cipher and TLS-version settings, and alpn_protocols now apply to proxied HTTPS.
  • SOCKS5 credentials in the proxy URL (socks5://user:pass@host) are sent. They were silently ignored before.
  • An https:// proxy URL is refused for HTTPS targets with a clear error, since that would need TLS inside TLS. It never worked. Plain-HTTP targets through an https:// proxy URL are unchanged.

tests/proxy_tls.rs runs a small CONNECT proxy and a small SOCKS5 proxy in front of the TLS test server, and checks that the first byte through the tunnel is a TLS handshake, that certificate verification applies to the target, and that SOCKS5 credentials arrive.

hyper-util's Tunnel and SocksV5 call the inner connector with the proxy's
URI, so our connector saw an http scheme and never did TLS. An https
request through a CONNECT or SOCKS5 proxy went into the tunnel as
plaintext, which a real HTTPS server rejects, and verify_certs and the
other TLS settings did nothing.

The connector now opens the tunnel itself with the CONNECT and SOCKS5
handshakes raw_connect already uses, then does TLS with the target over
it. Connections are still pooled. SOCKS5 credentials in the proxy URL
are now sent, which they weren't before. An https:// proxy URL is
refused for an https target, since that needs TLS inside TLS.

Fixes #89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants