Skip to content

Instantly share code, notes, and snippets.

@nclv
Last active January 5, 2023 10:27
Show Gist options
  • Save nclv/e8eda7bdb1926301d359d502e010b8c7 to your computer and use it in GitHub Desktop.
Save nclv/e8eda7bdb1926301d359d502e010b8c7 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"crypto/tls"
"fmt"
"io"
"net"
"strings"
"github.com/imroc/req/v3"
utls "github.com/refraction-networking/utls"
)
type TLSConn struct {
*utls.UConn
}
func (conn *TLSConn) ConnectionState() tls.ConnectionState {
cs := conn.UConn.ConnectionState()
return 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,
}
}
// curl https://tls.peet.ws/api/search-ja3?by=$(go run utls.go | jq -r ."tls"."ja3")
func main() {
c := req.C()
c.SetDialTLS(func(ctx context.Context, network, addr string) (net.Conn, error) {
plainConn, err := net.Dial(network, addr)
if err != nil {
return nil, err
}
colonPos := strings.LastIndex(addr, ":")
if colonPos == -1 {
colonPos = len(addr)
}
hostname := addr[:colonPos]
utlsConfig := &utls.Config{ServerName: hostname, NextProtos: c.GetTLSClientConfig().NextProtos}
conn := utls.UClient(plainConn, utlsConfig, utls.HelloFirefox_Auto)
return &TLSConn{conn}, nil
})
resp := c.R().MustGet("https://tls.peet.ws/api/all")
fmt.Println(resp.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment