final fixes for utls impl.

This commit is contained in:
Vladislav Yarmak
2024-02-25 00:01:11 +02:00
parent bbd2ea4048
commit fc9e85dba0
3 changed files with 9 additions and 9 deletions

View File

@@ -399,7 +399,6 @@ func httpClientWithProxy(agent *FallbackAgent) *http.Client {
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
var dialer ContextDialer = baseDialer
@@ -414,22 +413,23 @@ func httpClientWithProxy(agent *FallbackAgent) *http.Client {
t.DialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
host, _, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
return nil, fmt.Errorf("hostname extraction error: %w", err)
}
conn, err := dialer.DialContext(ctx, network, addr)
if err != nil {
return nil, err
return nil, fmt.Errorf("can't prepare underlying connection for TLS session: %w", err)
}
var cfg tls.Config
if tlsConfig != nil {
cfg = *tlsConfig
}
cfg.ServerName = host
conn = tls.UClient(conn, &cfg, tls.HelloChrome_Auto)
if err := conn.(*tls.UConn).HandshakeContext(ctx); err != nil {
return nil, err
tlsConn := tls.UClient(conn, &cfg, tls.HelloRandomized)
if err := tlsConn.HandshakeContext(ctx); err != nil {
conn.Close()
return nil, fmt.Errorf("UClient handshake failed: %w", err)
}
return conn, nil
return tlsConn, nil
}
return &http.Client{
Transport: t,

View File

@@ -62,7 +62,7 @@ func (d *PlaintextDialer) DialContext(ctx context.Context, network, address stri
_, err := cs.PeerCertificates[0].Verify(opts)
return err
},
}, tls.HelloChrome_Auto)
}, tls.HelloRandomized)
}
return conn, nil
}

View File

@@ -122,7 +122,7 @@ func (d *ProxyDialer) DialContext(ctx context.Context, network, address string)
_, err := cs.PeerCertificates[0].Verify(opts)
return err
},
}, tls.HelloChrome_Auto)
}, tls.HelloRandomized)
}
req := &http.Request{