diff --git a/Sources/SwiftNetwork/QUIC/QUICConnection.swift b/Sources/SwiftNetwork/QUIC/QUICConnection.swift index 0418715..d0f8ada 100644 --- a/Sources/SwiftNetwork/QUIC/QUICConnection.swift +++ b/Sources/SwiftNetwork/QUIC/QUICConnection.swift @@ -1643,6 +1643,11 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol, return } + if state == .retrySent { + // The token was validated and is no longer needed. + self.initialToken = nil + } + // Change state from idle to initial received with key state = handshake state.change(to: .initialReceived, logIDString: logPrefixer.logIDString) keyState = .handshake diff --git a/Tests/SwiftNetworkTests/SwiftNetworkQUICRetryTokenTests.swift b/Tests/SwiftNetworkTests/SwiftNetworkQUICRetryTokenTests.swift index 7aa9424..537c3ae 100644 --- a/Tests/SwiftNetworkTests/SwiftNetworkQUICRetryTokenTests.swift +++ b/Tests/SwiftNetworkTests/SwiftNetworkQUICRetryTokenTests.swift @@ -65,9 +65,10 @@ final class SwiftNetworkQUICRetryTokenTests: NetTestCase { harness.state?.clientInstance.initialToken, "Client should have an initial retry token" ) - XCTAssertNotNil( + // The server's token was reset after verifying the client token. + XCTAssertNil( harness.state?.serverInstance.initialToken, - "Server should have an initial retry token" + "Server must discard the retry token once validated, so it is never sent in an INITIAL" ) expectation.fulfill() } @@ -101,9 +102,10 @@ final class SwiftNetworkQUICRetryTokenTests: NetTestCase { harness.state?.clientInstance.initialToken, "Client should have an initial retry token" ) - XCTAssertNotNil( + // The server's token was reset after verifying the client token. + XCTAssertNil( harness.state?.serverInstance.initialToken, - "Server should have an initial retry token" + "Server must discard the retry token once validated, so it is never sent in an INITIAL" ) expectation.fulfill() } @@ -128,9 +130,10 @@ final class SwiftNetworkQUICRetryTokenTests: NetTestCase { harness.state?.clientInstance.initialToken, "Client should have an initial retry token" ) - XCTAssertNotNil( + // The server's token was reset after verifying the client token. + XCTAssertNil( harness.state?.serverInstance.initialToken, - "Server should have an initial retry token" + "Server must discard the retry token once validated, so it is never sent in an INITIAL" ) expectation.fulfill() }