Skip to content

Commit

Permalink
fix: generate ClientHelloSpec only once (#306)
Browse files Browse the repository at this point in the history
* fix: generate ClientHelloSpec only once

* chore: remove empty line in u_parrots.go

Co-authored-by: Gaukas Wang <i@gauk.as>
Signed-off-by: adotkhan <61702862+adotkhan@users.noreply.github.com>

---------

Signed-off-by: adotkhan <61702862+adotkhan@users.noreply.github.com>
Co-authored-by: Gaukas Wang <i@gauk.as>
  • Loading branch information
adotkhan and gaukas committed Jul 19, 2024
1 parent 841ef93 commit 4a28d1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions u_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type UConn struct {
sessionController *sessionController

clientHelloBuildStatus ClientHelloBuildStatus
clientHelloSpec *ClientHelloSpec

HandshakeState PubClientHandshakeState

Expand Down
38 changes: 22 additions & 16 deletions u_parrots.go
Original file line number Diff line number Diff line change
Expand Up @@ -2588,25 +2588,31 @@ 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.
Expand Down

0 comments on commit 4a28d1a

Please sign in to comment.