Home >Backend Development >Golang >How to Establish UTLS Connections Through Proxies with HTTP 1.1 Requests?

How to Establish UTLS Connections Through Proxies with HTTP 1.1 Requests?

DDD
DDDOriginal
2024-11-27 10:59:10779browse

How to Establish UTLS Connections Through Proxies with HTTP 1.1 Requests?

Connecting via Proxy while Using UTLS and HTTP 1.1 Request

Establishing connections through proxies while using UTLS and HTTP 1.1 requests requires specific configuration.

Problem:

How can we utilize an HTTP or SOCKS5 proxy while opening a UTLS connection for randomized TLS fingerprinting?

Answer:

To utilize a proxy for UTLS connections, follow these steps:

  1. Create a Proxy Dialer: Determine the proxy type (HTTP or SOCKS5) and create an appropriate proxy dialer (e.g., connectproxy.New() for HTTP or proxy.SOCKS5() for SOCKS5).
  2. Dial the Proxy: Use the proxy dialer to establish a net.Conn connection to the proxy.
  3. Configure UTLS Client: Initialize a UTLS client (e.g., tls.UClient()) using the net.Conn obtained from the proxy dial.

Here's an example of a custom dialTLS function that accommodates proxy connections:

package main

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)

    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)
    ...
}

Additional Suggestions:

  • Consider using the "connectproxy" module to handle HTTP CONNECT tunneling.
  • Utilize the Meek pluggable transport from Tor, which handles the setup process for both SoC

The above is the detailed content of How to Establish UTLS Connections Through Proxies with HTTP 1.1 Requests?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn