From 6a73d07bc26292bee808053303298f09809a8769 Mon Sep 17 00:00:00 2001 From: Amir Khan Date: Thu, 18 Jul 2024 12:18:32 -0400 Subject: [PATCH 1/2] fix: generate ClientHelloSpec only once --- u_conn.go | 1 + u_parrots.go | 39 +++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/u_conn.go b/u_conn.go index 49cc0f0e..753decdd 100644 --- a/u_conn.go +++ b/u_conn.go @@ -32,6 +32,7 @@ type UConn struct { sessionController *sessionController clientHelloBuildStatus ClientHelloBuildStatus + clientHelloSpec *ClientHelloSpec HandshakeState PubClientHandshakeState diff --git a/u_parrots.go b/u_parrots.go index 8ac1ca07..a9dbe9d3 100644 --- a/u_parrots.go +++ b/u_parrots.go @@ -2588,25 +2588,32 @@ func ShuffleChromeTLSExtensions(exts []TLSExtension) []TLSExtension { } func (uconn *UConn) applyPresetByID(id ClientHelloID) (err error) { - var spec ClientHelloSpec - uconn.ClientHelloID = id - // choose/generate the spec - switch id.Client { - case helloRandomized, helloRandomizedNoALPN, helloRandomizedALPN: - spec, err = uconn.generateRandomizedSpec() - if err != nil { - return err - } - case helloCustom: - return nil - default: - spec, err = UTLSIdToSpec(id) - if err != nil { - return err + + if uconn.clientHelloSpec == nil { + + var spec ClientHelloSpec + uconn.ClientHelloID = id + + // choose/generate the spec + switch id.Client { + case helloRandomized, helloRandomizedNoALPN, helloRandomizedALPN: + spec, err = uconn.generateRandomizedSpec() + if err != nil { + return err + } + case helloCustom: + return nil + default: + spec, err = UTLSIdToSpec(id) + if err != nil { + return err + } } + + uconn.clientHelloSpec = &spec } - return uconn.ApplyPreset(&spec) + return uconn.ApplyPreset(uconn.clientHelloSpec) } // ApplyPreset should only be used in conjunction with HelloCustom to apply custom specs. From db5af5dad9ff5eeda38c5c7391cbc506d0e764a6 Mon Sep 17 00:00:00 2001 From: adotkhan <61702862+adotkhan@users.noreply.github.com> Date: Fri, 19 Jul 2024 00:23:28 -0400 Subject: [PATCH 2/2] chore: remove empty line in u_parrots.go Co-authored-by: Gaukas Wang Signed-off-by: adotkhan <61702862+adotkhan@users.noreply.github.com> --- u_parrots.go | 1 - 1 file changed, 1 deletion(-) diff --git a/u_parrots.go b/u_parrots.go index a9dbe9d3..885b7431 100644 --- a/u_parrots.go +++ b/u_parrots.go @@ -2590,7 +2590,6 @@ func ShuffleChromeTLSExtensions(exts []TLSExtension) []TLSExtension { func (uconn *UConn) applyPresetByID(id ClientHelloID) (err error) { if uconn.clientHelloSpec == nil { - var spec ClientHelloSpec uconn.ClientHelloID = id