Skip to content

Commit

Permalink
Correctly Send & Validate Retry Source CID (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks authored Jun 9, 2020
1 parent e9e81ed commit 5d64178
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
26 changes: 13 additions & 13 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,8 @@ QuicConnHandshakeConfigure(
QUIC_FREE(Connection->OrigDestCID);
Connection->OrigDestCID = NULL;

if (Connection->Stats.QuicVersion != QUIC_VERSION_DRAFT_27) {
if (Connection->State.HandshakeUsedRetryPacket &&
Connection->Stats.QuicVersion != QUIC_VERSION_DRAFT_27) {
QUIC_DBG_ASSERT(SourceCid->Link.Next != NULL);
const QUIC_CID_HASH_ENTRY* PrevSourceCid =
QUIC_CONTAINING_RECORD(
Expand Down Expand Up @@ -2222,7 +2223,7 @@ QuicConnValidateTransportParameterDraft27CIDs(
_In_ QUIC_CONNECTION* Connection
)
{
if (Connection->State.ReceivedRetryPacket) {
if (Connection->State.HandshakeUsedRetryPacket) {
QUIC_DBG_ASSERT(!QuicConnIsServer(Connection));
QUIC_DBG_ASSERT(Connection->OrigDestCID != NULL);
//
Expand Down Expand Up @@ -2329,7 +2330,7 @@ QuicConnValidateTransportParameterCIDs(
}
QUIC_FREE(Connection->OrigDestCID);
Connection->OrigDestCID = NULL;
if (Connection->State.ReceivedRetryPacket) {
if (Connection->State.HandshakeUsedRetryPacket) {
if (!(Connection->PeerTransportParams.Flags & QUIC_TP_FLAG_RETRY_SOURCE_CONNECTION_ID)) {
QuicTraceEvent(
ConnError,
Expand All @@ -2340,15 +2341,13 @@ QuicConnValidateTransportParameterCIDs(
}
// TODO - Validate
} else {
if (Connection->State.ReceivedRetryPacket) {
if (Connection->PeerTransportParams.Flags & QUIC_TP_FLAG_RETRY_SOURCE_CONNECTION_ID) {
QuicTraceEvent(
ConnError,
"[conn][%p] ERROR, %s.",
Connection,
"Server incorrectly provided the retry source CID in TP");
return FALSE;
}
if (Connection->PeerTransportParams.Flags & QUIC_TP_FLAG_RETRY_SOURCE_CONNECTION_ID) {
QuicTraceEvent(
ConnError,
"[conn][%p] ERROR, %s.",
Connection,
"Server incorrectly provided the retry source CID in TP");
return FALSE;
}
}
}
Expand Down Expand Up @@ -2820,7 +2819,7 @@ QuicConnRecvRetry(
}

Connection->State.GotFirstServerResponse = TRUE;
Connection->State.ReceivedRetryPacket = TRUE;
Connection->State.HandshakeUsedRetryPacket = TRUE;

//
// Update the Initial packet's key based on the new CID.
Expand Down Expand Up @@ -3054,6 +3053,7 @@ QuicConnRecvHeader(
Connection->OrigDestCID->Data,
Token.Encrypted.OrigConnId,
Token.Encrypted.OrigConnIdLength);
Connection->State.HandshakeUsedRetryPacket = TRUE;

QuicPathSetValid(Connection, Path, QUIC_PATH_VALID_INITIAL_TOKEN);

Expand Down
5 changes: 2 additions & 3 deletions src/core/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ typedef union QUIC_CONNECTION_STATE {
BOOLEAN GotFirstServerResponse : 1;

//
// This flag indicates the client received a Retry packet during the
// handshake.
// This flag indicates the Retry packet was used during the handshake.
//
BOOLEAN ReceivedRetryPacket : 1;
BOOLEAN HandshakeUsedRetryPacket : 1;

//
// We have confirmed that the peer has completed the handshake.
Expand Down
5 changes: 2 additions & 3 deletions src/tools/dbg/quictypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ typedef union QUIC_CONNECTION_STATE {
BOOLEAN GotFirstServerResponse : 1;

//
// This flag indicates the client received a Retry packet during the
// handshake.
// This flag indicates the Retry packet was used during the handshake.
//
BOOLEAN ReceivedRetryPacket : 1;
BOOLEAN HandshakeUsedRetryPacket : 1;

//
// We have confirmed that the peer has completed the handshake.
Expand Down

0 comments on commit 5d64178

Please sign in to comment.