Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send client CONNECTION_CLOSE on 1-RTT before handshake completion. #4145

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/core/packet_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,22 @@ QuicPacketBuilderGetPacketTypeAndKeyForControlFrames(
CXPLAT_DBG_ASSERT(SendFlags != 0);
QuicSendValidate(&Builder->Connection->Send);

QUIC_PACKET_KEY_TYPE MaxKeyType = Connection->Crypto.TlsState.WriteKey;

if (QuicConnIsClient(Connection) &&
!Connection->State.HandshakeConfirmed &&
MaxKeyType == QUIC_PACKET_KEY_1_RTT &&
(SendFlags & QUIC_CONN_SEND_FLAG_CONNECTION_CLOSE)) {
//
// Server is not allowed to process 1-RTT packets until the handshake is confirmed and since we are
// closing the connection, the handshake is unlikely to complete. Ensure the CONNECTION_CLOSE is sent
// in a packet which server can process.
//
MaxKeyType = QUIC_PACKET_KEY_HANDSHAKE;
}

for (QUIC_PACKET_KEY_TYPE KeyType = 0;
KeyType <= Connection->Crypto.TlsState.WriteKey;
KeyType <= MaxKeyType;
++KeyType) {

if (KeyType == QUIC_PACKET_KEY_0_RTT) {
Expand Down Expand Up @@ -538,7 +552,7 @@ QuicPacketBuilderGetPacketTypeAndKeyForControlFrames(
if (Connection->Crypto.TlsState.WriteKey == QUIC_PACKET_KEY_0_RTT) {
*PacketKeyType = QUIC_PACKET_KEY_INITIAL;
} else {
*PacketKeyType = Connection->Crypto.TlsState.WriteKey;
*PacketKeyType = MaxKeyType;
}
return TRUE;
}
Expand Down
25 changes: 11 additions & 14 deletions src/test/lib/HandshakeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,13 +885,11 @@ QuicTestCustomServerCertificateValidation(
}
TEST_EQUAL(AcceptCert, Client.GetIsConnected());

if (AcceptCert) { // Server will be deleted on reject case, so can't validate.
Copy link
Member Author

@rzikm rzikm Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how the server would get deleted. The new connection instance is held by the unique_ptr above and neither the AutoDelete bit nor ShutdownEventCallback is set, so the connection should be valid until the unique_ptr goes out of scope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was meant to handle a case where the listener could reject the connection, and then this pointer would never be set. That being said, I cannot see a path where that would happen in this test case (or the one below). And since the tests seem to pass just fine, I'm ok with these changes.

TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Server->GetIsConnected());
TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}
TEST_EQUAL(AcceptCert, Server->GetIsConnected());
}
}
}
Expand Down Expand Up @@ -998,16 +996,15 @@ QuicTestCustomClientCertificateValidation(
if (!Client.WaitForConnectionComplete()) {
return;
}

if (AcceptCert) { // Server will be deleted on reject case, so can't validate.
TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Server->GetIsConnected());
}
// In all cases, the client "connects", but in the rejection case, it gets disconnected.
TEST_TRUE(Client.GetIsConnected());

TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}

TEST_EQUAL(AcceptCert, Server->GetIsConnected());
}
}
}
Expand Down
Loading