From e764386c86caf4a80470188221e3f4141fc7c883 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Fri, 21 Jan 2022 17:51:41 -0800 Subject: [PATCH] Randomize fixed bit for compatible peers --- quinn-proto/src/connection/packet_builder.rs | 6 +++++- quinn-proto/src/packet.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/quinn-proto/src/connection/packet_builder.rs b/quinn-proto/src/connection/packet_builder.rs index 56040c761..0630c3dd7 100644 --- a/quinn-proto/src/connection/packet_builder.rs +++ b/quinn-proto/src/connection/packet_builder.rs @@ -7,7 +7,7 @@ use tracing::{trace, trace_span}; use super::{spaces::SentPacket, Connection, SentFrames, State}; use crate::{ frame::{self, Close}, - packet::{Header, LongType, PacketNumber, PartialEncode, SpaceId}, + packet::{Header, LongType, PacketNumber, PartialEncode, SpaceId, FIXED_BIT}, TransportError, TransportErrorCode, }; @@ -115,6 +115,10 @@ impl PacketBuilder { }, }; let partial_encode = header.encode(buffer); + if conn.peer_params.grease_quic_bit && conn.rng.gen() { + buffer[partial_encode.start] ^= FIXED_BIT; + } + let (sample_size, tag_len) = if let Some(ref crypto) = space.crypto { ( crypto.header.local.sample_size(), diff --git a/quinn-proto/src/packet.rs b/quinn-proto/src/packet.rs index 0bcc8354a..296b17648 100644 --- a/quinn-proto/src/packet.rs +++ b/quinn-proto/src/packet.rs @@ -770,7 +770,7 @@ impl From for PacketDecodeError { } pub(crate) const LONG_HEADER_FORM: u8 = 0x80; -const FIXED_BIT: u8 = 0x40; +pub(crate) const FIXED_BIT: u8 = 0x40; pub(crate) const SPIN_BIT: u8 = 0x20; const SHORT_RESERVED_BITS: u8 = 0x18; const LONG_RESERVED_BITS: u8 = 0x0c;