Skip to content

Commit d7ead5d

Browse files
committed
feat(shadowsocks): double check AEAD-2022 ipsk length
1 parent 70ceea3 commit d7ead5d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

crates/shadowsocks/src/config.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ pub enum ServerConfigError {
394394
/// Key length mismatch
395395
#[error("invalid key length for {0}, expecting {1} bytes, but found {2} bytes")]
396396
InvalidKeyLength(CipherKind, usize, usize),
397+
398+
/// User Key (ipsk) length mismatch
399+
#[error("invalid user key length for {0}, expecting {1} bytes, but found {2} bytes")]
400+
InvalidUserKeyLength(CipherKind, usize, usize),
397401
}
398402

399403
/// Configuration for a server
@@ -538,6 +542,22 @@ where
538542
for ipsk in split_iter {
539543
match USER_KEY_BASE64_ENGINE.decode(ipsk) {
540544
Ok(v) => {
545+
// Double check identity key's length
546+
match method {
547+
CipherKind::AEAD2022_BLAKE3_AES_128_GCM => {
548+
// AES-128
549+
if v.len() != 16 {
550+
return Err(ServerConfigError::InvalidUserKeyLength(method, 16, v.len()));
551+
}
552+
}
553+
CipherKind::AEAD2022_BLAKE3_AES_256_GCM => {
554+
// AES-256
555+
if v.len() != 32 {
556+
return Err(ServerConfigError::InvalidUserKeyLength(method, 32, v.len()));
557+
}
558+
}
559+
_ => unreachable!("{} doesn't support EIH", method),
560+
}
541561
identity_keys.push(Bytes::from(v));
542562
}
543563
Err(err) => {

0 commit comments

Comments
 (0)