Skip to content

Commit

Permalink
Truncate additional data
Browse files Browse the repository at this point in the history
  • Loading branch information
kansi committed Aug 25, 2020
1 parent b119819 commit fe47254
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,4 @@ const MIN_MTU: u16 = 1232;
const TIMER_GRANULARITY: Duration = Duration::from_millis(1);
/// Maximum number of streams that can be uniquely identified by a stream ID
const MAX_STREAM_COUNT: u64 = 1 << 60;
const MAX_ADDITIONAL_DATA_SIZE: usize = 39; // max(ipv4, ipv6) + port + retry_src_cid
7 changes: 4 additions & 3 deletions quinn-proto/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
coding::{BufExt, BufMutExt},
crypto::{AeadKey, HmacKey, PseudoRandomKey},
shared::ConnectionId,
RESET_TOKEN_SIZE,
MAX_ADDITIONAL_DATA_SIZE, RESET_TOKEN_SIZE,
};

// TODO: Use AEAD to hide token details from clients for better stability guarantees:
Expand Down Expand Up @@ -80,7 +80,7 @@ impl<'a> RetryToken<'a> {
let aead_key = key.aead_from_hkdf(random_bytes);
let mut sealed_token = raw_token_bytes[Self::RANDOM_BYTES_LEN..].to_vec();

let mut additional_data = [0u8; 16 + 2 + 21]; // max(ipv4, ipv6) + port + retry_src_cid
let mut additional_data = [0u8; MAX_ADDITIONAL_DATA_SIZE];
let mut cursor = &mut additional_data[..];
match address.ip() {
IpAddr::V4(x) => cursor.put_slice(&x.octets()),
Expand All @@ -89,7 +89,8 @@ impl<'a> RetryToken<'a> {
cursor.write(address.port());
retry_src_cid.encode_long(&mut cursor);

let data = aead_key.open(&mut sealed_token, &additional_data)?;
let size = MAX_ADDITIONAL_DATA_SIZE - cursor.len();
let data = aead_key.open(&mut sealed_token, &additional_data[..size])?;
let mut reader = io::Cursor::new(data);

let orig_dst_cid = ConnectionId::decode_long(&mut reader).ok_or(())?;
Expand Down

0 comments on commit fe47254

Please sign in to comment.