首頁  >  文章  >  後端開發  >  如何透過 HTTP 1.1 代理建立 UTLS 連線?

如何透過 HTTP 1.1 代理建立 UTLS 連線?

Susan Sarandon
Susan Sarandon原創
2024-11-15 13:29:02760瀏覽

How to Establish UTLS Connections via HTTP 1.1 Proxy?

Proxied UTLS Connections via HTTP 1.1

When establishing UTLS connections, you may encounter the need to utilize a proxy, such as an HTTP or SOCKS5 proxy. To achieve this, you can leverage the following strategies:

First, you'll need to create a custom proxy dialer function. This function takes the form of dialTLS(network, addr string, _ *tls.Config) (net.Conn, error). Using this function, you can dial the proxy to establish a net.Conn. Afterward, use the net.Conn to create a UTLS client before performing the handshake.

Below is an example of how your custom dialTLS function could look:

import (
    "crypto/tls"
    "net"
    "net/url"

    "github.com/magisterquis/connectproxy"
    "golang.org/x/net/proxy"
    utls "github.com/refraction-networking/utls"
)

var proxyString = "http://127.0.0.1:8080"

dialTLS := func(network, addr string, _ *tls.Config) (net.Conn, error) {
    proxyURI, _ := url.Parse(proxyString)

    var proxyDialer proxy.Dialer
    switch proxyURI.Scheme {
    case "socks5":
        proxyDialer, err = proxy.SOCKS5("tcp", proxyString, nil, proxy.Direct)
    case "http":
        proxyDialer, err = connectproxy.New(proxyURI, proxy.Direct)
    }

    conn, err := proxyDialer.Dial("tcp", addr)
    uconn := utls.UClient(conn, cfg, &utls.HelloRandomizedALPN)
    // ... continue handshake and request
}

Here are a few additional tips:

  • Consider using the "connectproxy" module if you plan to tunnel through an HTTP CONNECT proxy.
  • Explore the Meek pluggable transport source for Tor. Its 'utls.go' module simplifies the process, including setting up HTTP or HTTP2 transport based on the negotiated ALPN protocol. It currently supports SOCKS but can be adapted for HTTP proxies.

以上是如何透過 HTTP 1.1 代理建立 UTLS 連線?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn