Skip to content

Commit 6e243da

Browse files
rhyshgopherbot
authored andcommitted
quic: update Initial keys when handling Retry
A Retry packet specifies a new connection ID for the client to use as a destination address, in what the server will consider to be the client's "first" Initial packet. Re-derive the Initial space's packet protection keys, since that address is an input to their derivation function. "Changing the Destination Connection ID field also results in a change to the keys used to protect the Initial packet." https://www.rfc-editor.org/rfc/rfc9000#section-17.2.5.2-4 For golang/go#58547 Change-Id: Id8acf5788a05d367f952dce33ef4b06f7e8b66e2 Reviewed-on: https://go-review.googlesource.com/c/net/+/712341 Auto-Submit: Rhys Hiltner <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 98daa2e commit 6e243da

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

internal/quic/cmd/interop/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ func main() {
114114
case "resumption":
115115
// TODO
116116
case "retry":
117-
// TODO
117+
if *listen != "" && len(urls) == 0 {
118+
config.RequireAddressValidation = true
119+
}
120+
basicTest(ctx, config, urls)
121+
return
118122
case "versionnegotiation":
119123
// "The client should start a connection using
120124
// an unsupported version number [...]"

quic/conn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Conn struct {
6767
// connTestHooks override conn behavior in tests.
6868
type connTestHooks interface {
6969
// init is called after a conn is created.
70-
init()
70+
init(first bool)
7171

7272
// nextMessage is called to request the next event from msgc.
7373
// Used to give tests control of the connection event loop.
@@ -177,7 +177,7 @@ func newConn(now time.Time, side connSide, cids newServerConnIDs, peerHostname s
177177
}
178178

179179
if c.testHooks != nil {
180-
c.testHooks.init()
180+
c.testHooks.init(true)
181181
}
182182
go c.loop(now)
183183
return c, nil

quic/conn_recv.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ func (c *Conn) handleRetry(now time.Time, pkt []byte) {
208208
}
209209
c.retryToken = cloneBytes(p.token)
210210
c.connIDState.handleRetryPacket(p.srcConnID)
211+
c.keysInitial = initialKeys(p.srcConnID, c.side)
211212
// We need to resend any data we've already sent in Initial packets.
212213
// We must not reuse already sent packet numbers.
213214
c.loss.discardPackets(initialSpace, c.log, c.handleAckOrLoss)
214215
// TODO: Discard 0-RTT packets as well, once we support 0-RTT.
216+
if c.testHooks != nil {
217+
c.testHooks.init(false)
218+
}
215219
}
216220

217221
var errVersionNegotiation = errors.New("server does not support QUIC version 1")

quic/conn_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,11 +1001,11 @@ func spaceForPacketType(ptype packetType) numberSpace {
10011001
// testConnHooks implements connTestHooks.
10021002
type testConnHooks testConn
10031003

1004-
func (tc *testConnHooks) init() {
1004+
func (tc *testConnHooks) init(first bool) {
10051005
tc.conn.keysAppData.updateAfter = maxPacketNumber // disable key updates
10061006
tc.keysInitial.r = tc.conn.keysInitial.w
10071007
tc.keysInitial.w = tc.conn.keysInitial.r
1008-
if tc.conn.side == serverSide {
1008+
if first && tc.conn.side == serverSide {
10091009
tc.endpoint.acceptQueue = append(tc.endpoint.acceptQueue, (*testConn)(tc))
10101010
}
10111011
}

quic/endpoint_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func TestConnect(t *testing.T) {
2222
newLocalConnPair(t, &Config{}, &Config{})
2323
}
2424

25+
func TestConnectRetry(t *testing.T) {
26+
newLocalConnPair(t, &Config{RequireAddressValidation: true}, &Config{})
27+
}
28+
2529
func TestConnectDefaultTLSConfig(t *testing.T) {
2630
serverConfig := newTestTLSConfigWithMoreDefaults(serverSide)
2731
clientConfig := newTestTLSConfigWithMoreDefaults(clientSide)

0 commit comments

Comments
 (0)