Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate ClientHelloSpec only once #306

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 23 additions & 16 deletions u_parrots.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

adotkhan marked this conversation as resolved.
Show resolved Hide resolved
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
Loading