Skip to content

Commit

Permalink
Force Handshake packet epoch for CC frame if handshake hasn't been co…
Browse files Browse the repository at this point in the history
…nfirmed

The RFC states that an endpoint can immediately close a connection by
sending a CONNECTION_CLOSE frame during the handshake:
> However, prior to confirming the handshake, it is possible that more
  advanced packet protection keys are not available to the peer, so
  another CONNECTION_CLOSE frame MAY be sent in a packet that uses a lower
  packet protection level.

Currently, when we decide the packet epoch when a CC frame is present,
we always choose Application. This commit downgrades the epoch to
Handshake if the handshake wasn't confirmed.

The test added in this PR fails without this patch - since the packet is
sent in the Application space without keys, the server can't decrypt it,
so its `peer_error` is None.
  • Loading branch information
evanrittenhouse committed Aug 28, 2024
1 parent 0ba4a74 commit 53185d0
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion quiche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6823,7 +6823,7 @@ impl Connection {
crypto::Level::OneRTT => packet::Epoch::Application,
};

if !self.is_established() {
if !self.handshake_confirmed {
match epoch {
// Downgrade the epoch to Handshake as the handshake is not
// completed yet.
Expand Down Expand Up @@ -14922,6 +14922,48 @@ mod tests {
);
}

#[test]
fn transport_close_by_client_during_handshake_established() {
let mut pipe = testing::Pipe::new().unwrap();

// Client sends initial flight.
let flight = testing::emit_flight(&mut pipe.client).unwrap();
testing::process_flight(&mut pipe.server, flight).unwrap();

let flight = testing::emit_flight(&mut pipe.server).unwrap();

// Both connections are not established.
assert!(!pipe.client.is_established() && !pipe.server.is_established());

testing::process_flight(&mut pipe.client, flight).unwrap();

// Connection is established on the client.
assert!(pipe.client.is_established());

// Client sends after connection is established.
pipe.client.close(false, 123, b"connection close").unwrap();

let flight = testing::emit_flight(&mut pipe.client).unwrap();
testing::process_flight(&mut pipe.server, flight).unwrap();

assert_eq!(
pipe.server.peer_error(),
Some(&ConnectionError {
is_app: false,
error_code: 123,
reason: b"connection close".to_vec()
})
);
assert_eq!(
pipe.client.local_error(),
Some(&ConnectionError {
is_app: false,
error_code: 123,
reason: b"connection close".to_vec()
})
);
}

#[test]
fn peer_error() {
let mut pipe = testing::Pipe::new().unwrap();
Expand Down

0 comments on commit 53185d0

Please sign in to comment.