MCPcopy Create free account
hub / github.com/imroc/req / setTLSFingerprint

Method setTLSFingerprint

client.go:1231–1284  ·  view source on GitHub ↗
(clientHelloID utls.ClientHelloID, uTLSConnApply func(*uTLSConn) error)

Source from the content-addressed store, hash-verified

1229 return c
1230}
1231func (c *Client) setTLSFingerprint(clientHelloID utls.ClientHelloID, uTLSConnApply func(*uTLSConn) error) *Client {
1232 fn := func(ctx context.Context, addr string, plainConn net.Conn) (conn net.Conn, tlsState *tls.ConnectionState, err error) {
1233 colonPos := strings.LastIndex(addr, ":")
1234 if colonPos == -1 {
1235 colonPos = len(addr)
1236 }
1237 hostname := addr[:colonPos]
1238 tlsConfig := c.GetTLSClientConfig()
1239 utlsConfig := &utls.Config{
1240 ServerName: hostname,
1241 Rand: tlsConfig.Rand,
1242 Time: tlsConfig.Time,
1243 RootCAs: tlsConfig.RootCAs,
1244 NextProtos: tlsConfig.NextProtos,
1245 ClientCAs: tlsConfig.ClientCAs,
1246 InsecureSkipVerify: tlsConfig.InsecureSkipVerify,
1247 CipherSuites: tlsConfig.CipherSuites,
1248 SessionTicketsDisabled: tlsConfig.SessionTicketsDisabled,
1249 MinVersion: tlsConfig.MinVersion,
1250 MaxVersion: tlsConfig.MaxVersion,
1251 DynamicRecordSizingDisabled: tlsConfig.DynamicRecordSizingDisabled,
1252 KeyLogWriter: tlsConfig.KeyLogWriter,
1253 }
1254 uconn := &uTLSConn{utls.UClient(plainConn, utlsConfig, clientHelloID)}
1255 if uTLSConnApply != nil {
1256 if err = uTLSConnApply(uconn); err != nil {
1257 return
1258 }
1259 }
1260 err = uconn.HandshakeContext(ctx)
1261 if err != nil {
1262 return
1263 }
1264 cs := uconn.Conn.ConnectionState()
1265 conn = uconn
1266 tlsState = &tls.ConnectionState{
1267 Version: cs.Version,
1268 HandshakeComplete: cs.HandshakeComplete,
1269 DidResume: cs.DidResume,
1270 CipherSuite: cs.CipherSuite,
1271 NegotiatedProtocol: cs.NegotiatedProtocol,
1272 NegotiatedProtocolIsMutual: cs.NegotiatedProtocolIsMutual,
1273 ServerName: cs.ServerName,
1274 PeerCertificates: cs.PeerCertificates,
1275 VerifiedChains: cs.VerifiedChains,
1276 SignedCertificateTimestamps: cs.SignedCertificateTimestamps,
1277 OCSPResponse: cs.OCSPResponse,
1278 TLSUnique: cs.TLSUnique,
1279 }
1280 return
1281 }
1282 c.Transport.SetTLSHandshake(fn)
1283 return c
1284}
1285
1286// SetTLSFingerprintSpec set the tls fingerprint for tls handshake using a custom
1287// ClientHelloSpec, which allows fine-grained control over the TLS fingerprint

Callers 2

SetTLSFingerprintMethod · 0.95
SetTLSFingerprintSpecMethod · 0.95

Calls 4

GetTLSClientConfigMethod · 0.95
HandshakeContextMethod · 0.80
ConnectionStateMethod · 0.65
SetTLSHandshakeMethod · 0.45

Tested by

no test coverage detected