Golang 中通过不安全的 HTTPS 代理实现安全的 HTTPS 会话

问题描述 投票:0回答:1

如何在 Go 中复制

curl --proxy-insecure
行为

  • insecureproxy.net
    有自签名证书,
  • somesecureurl.net
    有正确且可信的证书吗?
https_proxy="https://insecureproxy.net" curl https://somesecureurl.net/ --proxy-insecure

我想接受代理使用不安全的 TLS 证书这一事实,但我仍然想建立到我的目的地的安全 TLS 会话。

我尝试使用

net/http
,但我只能使用 InsecureSkipVerify 禁用对
 代理和目的地的 TLS 验证。

c.Client = &http.Client{
    Transport: &http.Transport{
        TLSClientConfig: &tls.Config{
            InsecureSkipVerify: true
        },
        Proxy: http.ProxyURL(insecureproxy),
    },
}
go http security ssl proxy
1个回答
0
投票

您可以将客户端传输设置为同时使用 Transport.TLSClientConfig 和 Transport.DialTLSContext。在这种情况下,TLSClientConfig 应用于连接到目标 HTTPS 服务器,而 DialTLSContext 用于连接到您的 HTTPS 代理。

在你的情况下,它可能看起来像这样:

c.Client = &http.Client{
    Transport: &http.Transport{
        TLSClientConfig: &tls.Config{
            // configs for destination server or nil to use defaults
        },
        Proxy: http.ProxyURL(insecureproxy),
        DialTLSContext: func(_ context.Context, network, addr string) (net.Conn, error) {
            return tls.Dial(network, addr, &tls.Config{InsecureSkipVerify: true})
        },
    },
}
© www.soinside.com 2019 - 2024. All rights reserved.