Explorar el Código

Benchmark getClientHelloVersion performance

Rod Hynes hace 7 años
padre
commit
cb0d882d9c
Se han modificado 2 ficheros con 17 adiciones y 0 borrados
  1. 9 0
      psiphon/tlsCompatibility_test.go
  2. 8 0
      psiphon/tlsDialer.go

+ 9 - 0
psiphon/tlsCompatibility_test.go

@@ -32,6 +32,7 @@ import (
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
 	tris "github.com/Psiphon-Labs/tls-tris"
 	tris "github.com/Psiphon-Labs/tls-tris"
+	utls "github.com/refraction-networking/utls"
 )
 )
 
 
 func TestTLSCompatibility(t *testing.T) {
 func TestTLSCompatibility(t *testing.T) {
@@ -162,3 +163,11 @@ func testTLSCompatibility(t *testing.T, address string) {
 		}
 		}
 	}
 	}
 }
 }
+
+func BenchmarkRandomizedGetClientHelloVersion(b *testing.B) {
+	for n := 0; n < b.N; n++ {
+		utlsClientHelloID := utls.HelloRandomized
+		utlsClientHelloID.Seed, _ = utls.NewPRNGSeed()
+		getClientHelloVersion(utlsClientHelloID)
+	}
+}

+ 8 - 0
psiphon/tlsDialer.go

@@ -198,6 +198,14 @@ func getClientHelloVersion(utlsClientHelloID utls.ClientHelloID) (string, error)
 	// Assumes utlsClientHelloID.Seed has been set; otherwise the result is
 	// Assumes utlsClientHelloID.Seed has been set; otherwise the result is
 	// ephemeral.
 	// ephemeral.
 
 
+	// As utls.HelloRandomized may be either TLS 1.2 or TLS 1.3, we cannot
+	// perform a simple ClientHello ID check. BuildHandshakeState is run, which
+	// constructs the entire ClientHello.
+	//
+	// BenchmarkRandomizedGetClientHelloVersion indicates that this operation
+	// takes on the order of 0.05ms and allocates ~8KB for randomized client
+	// hellos.
+
 	conn := utls.UClient(
 	conn := utls.UClient(
 		nil,
 		nil,
 		&utls.Config{InsecureSkipVerify: true},
 		&utls.Config{InsecureSkipVerify: true},