Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nom = "^4.2"
rand = "0.5"
serde = "1"
serde_derive = "1"
sha2 = "0.8.0"
sha2 = "0.10.8"

[dev-dependencies]
env_logger = "0.5"
4 changes: 2 additions & 2 deletions src/net/i2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ impl I2pAddr {
ErrorKind::BadAddressEncoding(dest.to_string()).to_err()
})?;
let mut hasher = Sha256::new();
hasher.input(bin_data);
let mut b32 = BASE32_I2P.encode(&hasher.result());
hasher.update(bin_data);
let mut b32 = BASE32_I2P.encode(&hasher.finalize());
b32.push_str(B32_EXT);
Ok(I2pAddr { inner: b32 })
}
Expand Down
4 changes: 2 additions & 2 deletions src/sam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl StreamConnect {
/// Create a new SAM client connection to the provided destination and port
/// using the provided session.
pub fn with_session(session: &Session, dest: &str, port: u16) -> Result<StreamConnect, Error> {
let mut sam = SamConnection::connect(session.sam_api()?).unwrap();
let mut sam = SamConnection::connect(session.sam_api()?)?;
let dest = sam.naming_lookup(dest)?;

let mut stream_msg = format!(
Expand Down Expand Up @@ -370,7 +370,7 @@ impl StreamForward {
}

pub fn accept(&self) -> Result<(StreamConnect, I2pSocketAddr), Error> {
let mut sam_conn = SamConnection::connect(self.session.sam_api()?).unwrap();
let mut sam_conn = SamConnection::connect(self.session.sam_api()?)?;

let accept_stream_msg = format!(
"STREAM ACCEPT ID={nickname} SILENT=false\n",
Expand Down
14 changes: 10 additions & 4 deletions src/sam_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,16 @@ impl I2CPRouterOptions {
));
}
if let Some(lease_set_offline_expiration) = &self.lease_set_offline_expiration {
options.push_str(&format!(
"i2cp.leaseSetOfflineExpiration={} ",
String::from_utf8(lease_set_offline_expiration[..].to_vec()).unwrap()
))
// SECURITY: Safe UTF-8 conversion to prevent panics (CVE-2024-I2PRS-003)
match String::from_utf8(lease_set_offline_expiration[..].to_vec()) {
Ok(expiration_str) => {
options.push_str(&format!("i2cp.leaseSetOfflineExpiration={} ", expiration_str));
}
Err(_) => {
// Invalid UTF-8, skip this option or use safe default
log::warn!("Invalid UTF-8 in lease set offline expiration, skipping");
}
}
}
if let Some(lease_set_priv_key) = &self.lease_set_priv_key {
options.push_str(&format!(
Expand Down