Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ directories = "6.0"
xdg = "2.5"
rpassword = "7.3"
libc = { version = "0.2", features = ["extra_traits"] }
rand = "0.8"
rand = "0.9"

futures = "0.3"
tokio = { version = "1", features = ["rt", "signal"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/shadowsocks-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ lru_time_cache = "0.11"
bytes = "1.7"
byte_string = "1.0"
byteorder = "1.5"
rand = { version = "0.8", features = ["small_rng"] }
rand = { version = "0.9", features = ["small_rng"] }
sled = { version = "0.34.7", optional = true }

futures = "0.3"
Expand Down
7 changes: 3 additions & 4 deletions crates/shadowsocks-service/src/local/dns/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use hickory_resolver::proto::{
rr::{DNSClass, Name, RData, RecordType},
};
use log::{debug, error, info, trace, warn};
use rand::{thread_rng, Rng};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::{TcpStream, UdpSocket},
Expand Down Expand Up @@ -854,7 +853,7 @@ impl DnsClient {

async fn lookup_remote_inner(&self, query: &Query, remote_addr: &Address) -> io::Result<Message> {
let mut message = Message::new();
message.set_id(thread_rng().gen());
message.set_id(rand::random());
message.set_recursion_desired(true);
message.add_query(query.clone());

Expand Down Expand Up @@ -884,7 +883,7 @@ impl DnsClient {
// Then this future will be disabled and have no effect
//
// Randomly choose from 500ms ~ 1.5s for preventing obvious request pattern
let sleep_time = thread_rng().gen_range(500..=1500);
let sleep_time = rand::random_range(500..=1500);
time::sleep(Duration::from_millis(sleep_time)).await;

let server = self.balancer.best_tcp_server();
Expand Down Expand Up @@ -933,7 +932,7 @@ impl DnsClient {

async fn lookup_local_inner(&self, query: &Query, local_addr: &NameServerAddr) -> io::Result<Message> {
let mut message = Message::new();
message.set_id(thread_rng().gen());
message.set_id(rand::random());
message.set_recursion_desired(true);
message.add_query(query.clone());

Expand Down
3 changes: 1 addition & 2 deletions crates/shadowsocks-service/src/local/dns/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use bytes::{BufMut, BytesMut};
use hickory_resolver::proto::{op::Message, ProtoError, ProtoErrorKind};
use log::{error, trace};
use lru_time_cache::{Entry, LruCache};
use rand::{thread_rng, Rng};
use shadowsocks::{
config::ServerConfig,
context::SharedContext,
Expand Down Expand Up @@ -139,7 +138,7 @@ impl DnsClient {

async fn inner_lookup(&mut self, msg: &mut Message) -> Result<Message, ProtoError> {
// Make a random ID
msg.set_id(thread_rng().gen());
msg.set_id(rand::random());

trace!("DNS lookup {:?}", msg);

Expand Down
9 changes: 7 additions & 2 deletions crates/shadowsocks-service/src/local/net/udp/association.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,18 @@ where
}

thread_local! {
static CLIENT_SESSION_RNG: RefCell<SmallRng> = RefCell::new(SmallRng::from_entropy());
static CLIENT_SESSION_RNG: RefCell<SmallRng> = RefCell::new(SmallRng::from_os_rng());
}

/// Generate an AEAD-2022 Client SessionID
#[inline]
pub fn generate_client_session_id() -> u64 {
CLIENT_SESSION_RNG.with(|rng| rng.borrow_mut().gen())
loop {
let id = CLIENT_SESSION_RNG.with(|rng| rng.borrow_mut().random());
if id != 0 {
break id;
}
}
}

impl<W> UdpAssociationContext<W>
Expand Down
9 changes: 7 additions & 2 deletions crates/shadowsocks-service/src/server/udprelay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,17 @@ impl Drop for UdpAssociationContext {
}

thread_local! {
static CLIENT_SESSION_RNG: RefCell<SmallRng> = RefCell::new(SmallRng::from_entropy());
static CLIENT_SESSION_RNG: RefCell<SmallRng> = RefCell::new(SmallRng::from_os_rng());
}

#[inline]
fn generate_server_session_id() -> u64 {
CLIENT_SESSION_RNG.with(|rng| rng.borrow_mut().gen())
loop {
let id = CLIENT_SESSION_RNG.with(|rng| rng.borrow_mut().random());
if id != 0 {
break id;
}
}
}

impl UdpAssociationContext {
Expand Down
2 changes: 1 addition & 1 deletion crates/shadowsocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spin = { version = "0.9", features = ["std"] }
pin-project = "1.1"
bloomfilter = { version = "3.0.0", optional = true }
thiserror = "2.0"
rand = { version = "0.8", optional = true }
rand = { version = "0.9", optional = true }
lru_time_cache = { version = "0.11", optional = true }

serde = { version = "1.0", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/shadowsocks/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn get_aead_2022_padding_size(payload: &[u8]) -> usize {
use rand::{rngs::SmallRng, Rng, SeedableRng};

thread_local! {
static PADDING_RNG: RefCell<SmallRng> = RefCell::new(SmallRng::from_entropy());
static PADDING_RNG: RefCell<SmallRng> = RefCell::new(SmallRng::from_os_rng());
}

if payload.is_empty() {
PADDING_RNG.with(|rng| rng.borrow_mut().gen::<usize>() % AEAD2022_MAX_PADDING_SIZE)
PADDING_RNG.with(|rng| rng.borrow_mut().random_range::<usize, _>(0..=AEAD2022_MAX_PADDING_SIZE))
} else {
0
}
Expand Down
Loading