Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
allow the client to disable 0-RTT when using a 0-RTT enabled session …
Browse files Browse the repository at this point in the history
…ticket
  • Loading branch information
marten-seemann committed Oct 24, 2023
1 parent b4213ca commit 174a6a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ type ExtraConfig struct {

// Is called when the client uses a session ticket.
// Restores the application data that was saved earlier on GetAppDataForSessionTicket.
SetAppDataFromSessionState func([]byte)
SetAppDataFromSessionState func([]byte) (allowEarlyData bool)
}

// Clone clones.
Expand Down
9 changes: 5 additions & 4 deletions handshake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,12 @@ func (c *Conn) loadSession(hello *clientHelloMsg) (cacheKey string,
}

if c.quic != nil && maxEarlyData > 0 {
var earlyData bool
if session.vers == VersionTLS13 && c.extraConfig != nil && c.extraConfig.SetAppDataFromSessionState != nil {
earlyData = c.extraConfig.SetAppDataFromSessionState(appData)
}
// For 0-RTT, the cipher suite has to match exactly.
if mutualCipherSuiteTLS13(hello.cipherSuites, session.cipherSuite) != nil {
if earlyData && mutualCipherSuiteTLS13(hello.cipherSuites, session.cipherSuite) != nil {
hello.earlyData = true
}
}
Expand Down Expand Up @@ -449,9 +453,6 @@ func (c *Conn) loadSession(hello *clientHelloMsg) (cacheKey string,
return "", nil, nil, nil, err
}

if session.vers == VersionTLS13 && c.extraConfig != nil && c.extraConfig.SetAppDataFromSessionState != nil {
c.extraConfig.SetAppDataFromSessionState(appData)
}
return
}

Expand Down
3 changes: 2 additions & 1 deletion tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,9 @@ func TestExtraConfigCloneFuncField(t *testing.T) {
called |= 1 << 2
return nil
},
SetAppDataFromSessionState: func([]byte) {
SetAppDataFromSessionState: func([]byte) bool {
called |= 1 << 3
return true
},
}

Expand Down

0 comments on commit 174a6a1

Please sign in to comment.