req
req copied to clipboard
能否添加一个直接设置ClientHelloSpec的方法?
我有自定义ClientHelloSpec的需求,用SetTLSHandshake能解决,但能否新增一个设置ClientHelloSpec的方法,类似于下面这样:
utls.HelloCustom 支持自定义ClientHelloSpec
func (c *Client) SetTLSClientHelloSpec(spec *utls.ClientHelloSpec) *Client {
fn := func(ctx context.Context, addr string, plainConn net.Conn) (conn net.Conn, tlsState *tls.ConnectionState, err error) {
colonPos := strings.LastIndex(addr, ":")
if colonPos == -1 {
colonPos = len(addr)
}
hostname := addr[:colonPos]
tlsConfig := c.GetTLSClientConfig()
utlsConfig := &utls.Config{
ServerName: hostname,
Rand: tlsConfig.Rand,
Time: tlsConfig.Time,
RootCAs: tlsConfig.RootCAs,
NextProtos: tlsConfig.NextProtos,
ClientCAs: tlsConfig.ClientCAs,
InsecureSkipVerify: tlsConfig.InsecureSkipVerify,
CipherSuites: tlsConfig.CipherSuites,
SessionTicketsDisabled: tlsConfig.SessionTicketsDisabled,
MinVersion: tlsConfig.MinVersion,
MaxVersion: tlsConfig.MaxVersion,
DynamicRecordSizingDisabled: tlsConfig.DynamicRecordSizingDisabled,
KeyLogWriter: tlsConfig.KeyLogWriter,
}
uconn := &uTLSConn{utls.UClient(plainConn, utlsConfig, utls.HelloCustom)}
err = uconn.ApplyPreset(spec)
if err != nil {
return
}
err = uconn.BuildHandshakeState()
if err != nil {
return
}
err = uconn.HandshakeContext(ctx)
if err != nil {
return
}
cs := uconn.Conn.ConnectionState()
conn = uconn
tlsState = &tls.ConnectionState{
Version: cs.Version,
HandshakeComplete: cs.HandshakeComplete,
DidResume: cs.DidResume,
CipherSuite: cs.CipherSuite,
NegotiatedProtocol: cs.NegotiatedProtocol,
NegotiatedProtocolIsMutual: cs.NegotiatedProtocolIsMutual,
ServerName: cs.ServerName,
PeerCertificates: cs.PeerCertificates,
VerifiedChains: cs.VerifiedChains,
SignedCertificateTimestamps: cs.SignedCertificateTimestamps,
OCSPResponse: cs.OCSPResponse,
TLSUnique: cs.TLSUnique,
}
return
}
c.Transport.SetTLSHandshake(fn)
return c
}