summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGravatar Norman Maurer <norman_maurer@apple.com> 2021-05-10 11:33:36 +0200
committerGravatar GitHub <noreply@github.com> 2021-05-10 10:33:36 +0100
commit4f83722db0028d5d2799280983e1989317d74f30 (patch)
tree36a69564df77114f493a1cdd7b0ec329910d9d9d /src/lib.rs
parentd6f1122f45a99eaabc625449225cf8705bf511c7 (diff)
downloadquiche-4f83722db0028d5d2799280983e1989317d74f30.tar.gz
quiche-4f83722db0028d5d2799280983e1989317d74f30.tar.zst
quiche-4f83722db0028d5d2799280983e1989317d74f30.zip
validate protocol version when creating Config
Motivation: We should validate that the version is valid that was used to create the Config object and if not fail. Modifications: - Add validation for the version - Add some tests Result: Version is validated during config creation
Diffstat (limited to '')
-rw-r--r--src/lib.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index db472c46..5feb7da2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -329,6 +329,8 @@ const PAYLOAD_LENGTH_LEN: usize = 2;
// The number of undecryptable that can be buffered.
const MAX_UNDECRYPTABLE_PACKETS: usize = 10;
+const RESERVED_VERSION_MASK: u32 = 0xfafafafa;
+
/// A specialized [`Result`] type for quiche operations.
///
/// This type is used throughout quiche's public API for any operation that
@@ -499,6 +501,11 @@ pub struct Config {
max_send_udp_payload_size: usize,
}
+// See https://quicwg.org/base-drafts/rfc9000.html#section-15
+fn is_reserved_version(version: u32) -> bool {
+ version & RESERVED_VERSION_MASK == version
+}
+
impl Config {
/// Creates a config object with the given version.
///
@@ -509,6 +516,10 @@ impl Config {
/// # Ok::<(), quiche::Error>(())
/// ```
pub fn new(version: u32) -> Result<Config> {
+ if !is_reserved_version(version) && !version_is_supported(version) {
+ return Err(Error::UnknownVersion);
+ }
+
let tls_ctx = Mutex::new(tls::Context::new()?);
Ok(Config {
@@ -5597,6 +5608,20 @@ mod tests {
}
#[test]
+ fn config_version_reserved() {
+ Config::new(0xbabababa).unwrap();
+ Config::new(0x1a2a3a4a).unwrap();
+ }
+
+ #[test]
+ fn config_version_invalid() {
+ assert_eq!(
+ Config::new(0xb1bababa).err().unwrap(),
+ Error::UnknownVersion
+ );
+ }
+
+ #[test]
fn version_negotiation() {
let mut buf = [0; 65535];