lib/proxy: pass proxy hostname in Host header of the CONNECT request

This should resolve the following issue when connecting to tls proxy:

  cannot validate certificate for ... because it doesn't contain any IP SANs
This commit is contained in:
Aliaksandr Valialkin 2021-03-09 20:39:38 +02:00
parent 36fd007247
commit 787242d7b0

View File

@ -86,7 +86,7 @@ func (u *URL) NewDialFunc(ac *promauth.Config) (fasthttp.DialFunc, error) {
} }
proxyConn = tls.Client(proxyConn, tlsCfgLocal) proxyConn = tls.Client(proxyConn, tlsCfgLocal)
} }
conn, err := sendConnectRequest(proxyConn, addr, authHeader) conn, err := sendConnectRequest(proxyConn, proxyAddr, addr, authHeader)
if err != nil { if err != nil {
_ = proxyConn.Close() _ = proxyConn.Close()
return nil, fmt.Errorf("error when sending CONNECT request to proxy %q: %w", pu, err) return nil, fmt.Errorf("error when sending CONNECT request to proxy %q: %w", pu, err)
@ -125,8 +125,8 @@ func defaultDialFunc(addr string) (net.Conn, error) {
} }
// sendConnectRequest sends CONNECT request to proxyConn for the given addr and authHeader and returns the established connection to dstAddr. // sendConnectRequest sends CONNECT request to proxyConn for the given addr and authHeader and returns the established connection to dstAddr.
func sendConnectRequest(proxyConn net.Conn, dstAddr, authHeader string) (net.Conn, error) { func sendConnectRequest(proxyConn net.Conn, proxyAddr, dstAddr, authHeader string) (net.Conn, error) {
req := "CONNECT " + dstAddr + " HTTP/1.1\r\nHost: " + dstAddr + "\r\n" + authHeader + "\r\n" req := "CONNECT " + dstAddr + " HTTP/1.1\r\nHost: " + proxyAddr + "\r\n" + authHeader + "\r\n"
if _, err := proxyConn.Write([]byte(req)); err != nil { if _, err := proxyConn.Write([]byte(req)); err != nil {
return nil, fmt.Errorf("cannot send CONNECT request for dstAddr=%q: %w", dstAddr, err) return nil, fmt.Errorf("cannot send CONNECT request for dstAddr=%q: %w", dstAddr, err)
} }