Skip to content

Commit

Permalink
fix: Marshal the Client Hello after loading session
Browse files Browse the repository at this point in the history
  • Loading branch information
adotkhan committed Jun 26, 2024
1 parent cbf02ab commit f061fb7
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions u_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,18 @@ func UClient(conn net.Conn, config *Config, clientHelloID ClientHelloID) *UConn
// With the excpetion of session ticket and psk extensions, which cannot be changed
// after calling BuildHandshakeState, all other fields can be modified.
func (uconn *UConn) BuildHandshakeState() error {
err := uconn.BuildHandshakeStateWithoutSession()
if err != nil {
return err
}
if uconn.ClientHelloID != HelloGolang {
err := uconn.uLoadSession()
if err != nil {
return err
}

uconn.uApplyPatch()

uconn.sessionController.finalCheck()
}
return nil
return uconn.buildHandshakeState(true)
}

// BuildHandshakeStateWithoutSession is the same as BuildHandshakeState, but does not
// set the session. This is only useful when you want to inspect the ClientHello before
// setting the session manually through SetSessionTicketExtension or SetPSKExtension.
// BuildHandshakeState is automatically called before uTLS performs handshake.
func (uconn *UConn) BuildHandshakeStateWithoutSession() error {
return uconn.buildHandshakeState(false)
}

func (uconn *UConn) buildHandshakeState(loadSession bool) error {
if uconn.ClientHelloID == HelloGolang {
if uconn.clientHelloBuildStatus == BuildByGoTLS {
return nil
Expand Down Expand Up @@ -149,10 +139,23 @@ func (uconn *UConn) BuildHandshakeStateWithoutSession() error {
return err
}

if loadSession {
err = uconn.uLoadSession()
if err != nil {
return err
}
}

err = uconn.MarshalClientHello()
if err != nil {
return err
}

if loadSession {
uconn.uApplyPatch()
uconn.sessionController.finalCheck()
}

uconn.clientHelloBuildStatus = BuildByUtls
}
return nil
Expand Down

0 comments on commit f061fb7

Please sign in to comment.