Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 20 additions & 28 deletions src/shadowsocks/shadowsocks_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,20 +442,16 @@ impl ShadowsocksStream {
let timestamp_bytes = &self.unprocessed_buf[self.salt_len + 1..self.salt_len + 9];
let timestamp_secs = u64::from_be_bytes(timestamp_bytes.try_into().unwrap());
let current_time_secs = current_time_secs();
if current_time_secs >= timestamp_secs {
if current_time_secs - timestamp_secs > 30 {
return Err(std::io::Error::other(
"timestamp is greater than 30 seconds",
));
}
} else {
// Make sure times aren't too far in the future.
if timestamp_secs - current_time_secs > 2 {
return Err(std::io::Error::other(format!(
"timestamp is {} seconds in the future",
timestamp_secs - current_time_secs
)));
}
// SIP022 (Shadowsocks 2022 Edition) requires rejecting any header
// whose timestamp is more than 30 seconds away from the current
// time, in either direction. Enforce the same symmetric window so
// peers with a fast clock (NTP drift, virtualized hosts) aren't
// rejected for being more than a couple of seconds ahead.
let time_diff_secs = current_time_secs.abs_diff(timestamp_secs);
if time_diff_secs > 30 {
return Err(std::io::Error::other(format!(
"timestamp is {time_diff_secs} seconds away from the current time"
)));
}

let decrypt_iv = &self.unprocessed_buf[0..self.salt_len];
Expand Down Expand Up @@ -509,20 +505,16 @@ impl ShadowsocksStream {
let timestamp_bytes = &self.unprocessed_buf[self.salt_len + 1..self.salt_len + 9];
let timestamp_secs = u64::from_be_bytes(timestamp_bytes.try_into().unwrap());
let current_time_secs = current_time_secs();
if current_time_secs >= timestamp_secs {
if current_time_secs - timestamp_secs > 30 {
return Err(std::io::Error::other(
"timestamp is greater than 30 seconds",
));
}
} else {
// Make sure times aren't too far in the future.
if timestamp_secs - current_time_secs > 2 {
return Err(std::io::Error::other(format!(
"timestamp is {} seconds in the future",
timestamp_secs - current_time_secs
)));
}
// SIP022 (Shadowsocks 2022 Edition) requires rejecting any header
// whose timestamp is more than 30 seconds away from the current
// time, in either direction. Enforce the same symmetric window so
// peers with a fast clock (NTP drift, virtualized hosts) aren't
// rejected for being more than a couple of seconds ahead.
let time_diff_secs = current_time_secs.abs_diff(timestamp_secs);
if time_diff_secs > 30 {
return Err(std::io::Error::other(format!(
"timestamp is {time_diff_secs} seconds away from the current time"
)));
}

if let Some(salt_checker) = &self.salt_checker {
Expand Down