Golang中不安全HTTPS代理上的安全HTTPS会话

jm2pwxwz  于 2023-11-14  发布在  Go
关注(0)|答案(1)|浏览(125)

如何在Go中复制curl --proxy-insecure行为,

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

字符集
我想接受代理使用不安全的TLS证书的事实,但我仍然想建立到目的地的安全TLS会话。
我尝试过使用net/http,但我只能使用InsecureSkipVerify禁用**代理和目标的TLS验证。

  1. c.Client = &http.Client{
  2. Transport: &http.Transport{
  3. TLSClientConfig: &tls.Config{
  4. InsecureSkipVerify: true
  5. },
  6. Proxy: http.ProxyURL(insecureproxy),
  7. },
  8. }

6vl6ewon

6vl6ewon1#

您可以将客户端Transport设置为同时使用Transport.TLSClientConfig和Transport. DialTLSContext。在这种情况下,TLSClientConfig应用于连接到目标HTTPS服务器,DialTLSContext -用于连接到HTTPS代理。
在您的情况下,它可能看起来像这样:

  1. c.Client = &http.Client{
  2. Transport: &http.Transport{
  3. TLSClientConfig: &tls.Config{
  4. // configs for destination server or nil to use defaults
  5. },
  6. Proxy: http.ProxyURL(insecureproxy),
  7. DialTLSContext: func(_ context.Context, network, addr string) (net.Conn, error) {
  8. return tls.Dial(network, addr, &tls.Config{InsecureSkipVerify: true})
  9. },
  10. },
  11. }

字符集

展开查看全部

相关问题