netxlite: utls for TLS parroting
This is the ground work for https://github.com/ooni/probe/issues/1424.
This commit is contained in:
committed by
Simone Basso
parent
17bfb052c5
commit
285290a98d
@@ -5,6 +5,8 @@ import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
utls "gitlab.com/yawning/utls.git"
|
||||
)
|
||||
|
||||
// TLSHandshaker is the generic TLS handshaker.
|
||||
@@ -105,4 +107,41 @@ func (h *TLSHandshakerLogger) Handshake(
|
||||
return tlsconn, state, nil
|
||||
}
|
||||
|
||||
// UTLSConn implements TLSConn and uses a utls UConn as its underlying connection
|
||||
type UTLSConn struct {
|
||||
*utls.UConn
|
||||
}
|
||||
|
||||
// NewConnUTLS creates a NewConn function creating a utls connection with a specified ClientHelloID
|
||||
func NewConnUTLS(clientHello *utls.ClientHelloID) func(conn net.Conn, config *tls.Config) TLSConn {
|
||||
return func(conn net.Conn, config *tls.Config) TLSConn {
|
||||
uConfig := &utls.Config{
|
||||
RootCAs: config.RootCAs,
|
||||
NextProtos: config.NextProtos,
|
||||
ServerName: config.ServerName,
|
||||
InsecureSkipVerify: config.InsecureSkipVerify,
|
||||
DynamicRecordSizingDisabled: config.DynamicRecordSizingDisabled,
|
||||
}
|
||||
tlsConn := utls.UClient(conn, uConfig, *clientHello)
|
||||
return &UTLSConn{tlsConn}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *UTLSConn) ConnectionState() tls.ConnectionState {
|
||||
uState := c.Conn.ConnectionState()
|
||||
return tls.ConnectionState{
|
||||
Version: uState.Version,
|
||||
HandshakeComplete: uState.HandshakeComplete,
|
||||
DidResume: uState.DidResume,
|
||||
CipherSuite: uState.CipherSuite,
|
||||
NegotiatedProtocol: uState.NegotiatedProtocol,
|
||||
ServerName: uState.ServerName,
|
||||
PeerCertificates: uState.PeerCertificates,
|
||||
VerifiedChains: uState.VerifiedChains,
|
||||
SignedCertificateTimestamps: uState.SignedCertificateTimestamps,
|
||||
OCSPResponse: uState.OCSPResponse,
|
||||
TLSUnique: uState.TLSUnique,
|
||||
}
|
||||
}
|
||||
|
||||
var _ TLSHandshaker = &TLSHandshakerLogger{}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxmocks"
|
||||
utls "gitlab.com/yawning/utls.git"
|
||||
)
|
||||
|
||||
func TestTLSHandshakerConfigurableWithError(t *testing.T) {
|
||||
@@ -177,3 +178,18 @@ func TestTLSHandshakerLoggerFailure(t *testing.T) {
|
||||
t.Fatal("expected zero ConnectionState here")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUTLSHandshakerChrome(t *testing.T) {
|
||||
h := &TLSHandshakerConfigurable{
|
||||
NewConn: NewConnUTLS(&utls.HelloChrome_Auto),
|
||||
}
|
||||
cfg := &tls.Config{ServerName: "google.com"}
|
||||
conn, err := net.Dial("tcp", "google.com:443")
|
||||
conn, _, err = h.Handshake(context.Background(), conn, cfg)
|
||||
if err != nil {
|
||||
t.Fatal("unexpected error", err)
|
||||
}
|
||||
if conn == nil {
|
||||
t.Fatal("nil connection")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user