forked from stanford-esrg/retina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add quic support * Update main.rs * fix indexing errors * probe indexing change * configs * fix usize error * further usize fixes * another index fix * return configs * minimal performance improvements * config changes * rename file * lazy load bytes * lazy string copy * other string conversion * small change again * renove config changes * rename quic stream * parseresult done * revert parse result * remove configs * this is gonna break a lot * config changes * fix reference errors * import fixes * pub header * public vec_u8 * import hell * rename * slight fixes * everything mutable * this wont work * better cloning * cloning * fix * fully clone * more cloning * copy trait * partial move * remove ref * fix * println debugging * fix * more prints * hashset * from clone * y not * cleanliness * print quic clone * done * remove prints * clear on end * remove dead code * remove imports * remove configs * reference based conn_ids * configs * rename quic to quicpacket * remove quic.toml * remove configs * revert * remove configs * clippy fix
- Loading branch information
1 parent
db2affe
commit 746b9b9
Showing
12 changed files
with
611 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//! Quic header types | ||
use serde::Serialize; | ||
|
||
/// Quic Long Header | ||
#[derive(Debug, Serialize, Clone)] | ||
pub struct QuicLongHeader { | ||
pub packet_type: u8, | ||
pub type_specific: u8, | ||
pub version: u32, | ||
pub dcid_len: u8, // length of dcid in bytes | ||
pub dcid: String, // hex string | ||
pub scid_len: u8, // length of scid in bytes | ||
pub scid: String, // hex string | ||
} | ||
|
||
/// Quic Short Header | ||
#[derive(Debug, Serialize, Clone)] | ||
pub struct QuicShortHeader { | ||
pub dcid: Option<String>, // optional. If not pre-existing cid then none. | ||
|
||
#[serde(skip)] | ||
pub dcid_bytes: Vec<u8>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
//! QUIC protocol parser. | ||
//! | ||
//! ## Remarks | ||
//! [QUIC-INVARIANTS] https://datatracker.ietf.org/doc/rfc8999/ | ||
//! [QUIC-RFC9000] https://datatracker.ietf.org/doc/rfc9000/ (Quic V1) | ||
//! Retina currently only parses Quic Long and Short Headers and does not attempt to parse TLS or HTTP/3 out of | ||
//! Quic packets. The Quic protocol parser makes several assumptions about the way that quic | ||
//! packets will behave: | ||
//! - Assume that the Quic version is one as listed in the QuicVersion Enum in the quic/parser.rs file | ||
//! - Assume that the dcid of a short header is a maximum of 20 bytes. | ||
//! - Assume that the packet will not try to grease the fixed bit. | ||
//! [QUIC-GREASE](https://www.rfc-editor.org/rfc/rfc9287.html) | ||
//! | ||
//! Additionally, there are a couple decisions made in the design of the quic parser: | ||
//! - The parser will not parse a short header dcid if it is not a part of a pre-identified connection | ||
//! - The payload bytes count is a lazy counter which does not try to exclude tokens for encryption, | ||
//! which is a process that happens in wireshark. | ||
/* | ||
TODO: support parsing the tls out of the initial quic packet setup | ||
TODO support dns over quic | ||
TODO: support HTTP/3 | ||
*/ | ||
pub(crate) mod parser; | ||
|
||
pub use self::header::{QuicLongHeader, QuicShortHeader}; | ||
use serde::Serialize; | ||
pub(crate) mod header; | ||
|
||
/// Parsed Quic Packet contents | ||
#[derive(Debug, Serialize, Clone)] | ||
pub struct QuicPacket { | ||
/// Quic Short header | ||
pub short_header: Option<QuicShortHeader>, | ||
|
||
/// Quic Long header | ||
pub long_header: Option<QuicLongHeader>, | ||
|
||
/// The number of bytes contained in the estimated payload | ||
pub payload_bytes_count: u16, | ||
} | ||
|
||
impl QuicPacket { | ||
/// Returns the header type of the Quic packet (ie. "long" or "short") | ||
pub fn header_type(&self) -> &str { | ||
match &self.long_header { | ||
Some(_) => "long", | ||
None => match &self.short_header { | ||
Some(_) => "short", | ||
None => "", | ||
}, | ||
} | ||
} | ||
|
||
/// Returns the packet type of the Quic packet | ||
pub fn packet_type(&self) -> u8 { | ||
match &self.long_header { | ||
Some(long_header) => long_header.packet_type, | ||
None => 0, | ||
} | ||
} | ||
|
||
/// Returns the version of the Quic packet | ||
pub fn version(&self) -> u32 { | ||
match &self.long_header { | ||
Some(long_header) => long_header.version, | ||
None => 0, | ||
} | ||
} | ||
|
||
/// Returns the destination connection ID of the Quic packet or an empty string if it does not exist | ||
pub fn dcid(&self) -> &str { | ||
match &self.long_header { | ||
Some(long_header) => { | ||
if long_header.dcid_len > 0 { | ||
&long_header.dcid | ||
} else { | ||
"" | ||
} | ||
} | ||
None => { | ||
if let Some(short_header) = &self.short_header { | ||
short_header.dcid.as_deref().unwrap_or("") | ||
} else { | ||
"" | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Returns the source connection ID of the Quic packet or an empty string if it does not exist | ||
pub fn scid(&self) -> &str { | ||
match &self.long_header { | ||
Some(long_header) => { | ||
if long_header.scid_len > 0 { | ||
&long_header.scid | ||
} else { | ||
"" | ||
} | ||
} | ||
None => "", | ||
} | ||
} | ||
|
||
/// Returns the number of bytes in the payload of the Quic packet | ||
pub fn payload_bytes_count(&self) -> u16 { | ||
self.payload_bytes_count | ||
} | ||
} |
Oops, something went wrong.