Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚮 Remove security-iv-printable-prefix feature #940

Merged
merged 1 commit into from
Sep 12, 2022
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
89 changes: 43 additions & 46 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ aead-cipher-2022-extra = ["shadowsocks-service/aead-cipher-2022-extra"]
# Enable detection against replay attack (Stream / AEAD)
security-replay-attack-detect = ["shadowsocks-service/security-replay-attack-detect"]
replay-attack-detect = ["security-replay-attack-detect"] # Backward compatibility. DO NOT USE.
# Enable IV printable prefix
security-iv-printable-prefix = ["shadowsocks-service/security-iv-printable-prefix"]

# Enable ARMv8 related optimizations
armv8 = ["shadowsocks-service/armv8"]
Expand Down
2 changes: 0 additions & 2 deletions crates/shadowsocks-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ aead-cipher-2022-extra = ["shadowsocks/aead-cipher-2022-extra"]

# Enable detection against replay attack
security-replay-attack-detect = ["shadowsocks/security-replay-attack-detect"]
# Enable IV printable prefix
security-iv-printable-prefix = ["shadowsocks/security-iv-printable-prefix"]

# Enable ARMv8 related optimizations
armv8 = ["shadowsocks/armv8"]
Expand Down
2 changes: 0 additions & 2 deletions crates/shadowsocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ aead-cipher-2022-extra = ["aead-cipher-2022", "shadowsocks-crypto/v2-extra"]

# Enable detection against replay attack
security-replay-attack-detect = ["bloomfilter"]
# Enable IV printable prefix
security-iv-printable-prefix = ["rand"]

# Enable ARMv8 related optimizations
armv8 = ["shadowsocks-crypto/armv8"]
Expand Down
33 changes: 0 additions & 33 deletions crates/shadowsocks/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@ impl Context {
loop {
random_iv_or_salt(nonce);

// SECURITY: First 6 bytes of payload should be printable characters
// Observation shows that prepending 6 bytes of printable characters to random payload will exempt it from blocking.
// by 2022-01-13 gfw.report et al.
#[cfg(feature = "security-iv-printable-prefix")]
{
const SECURITY_PRINTABLE_PREFIX_LEN: usize = 6;
if nonce.len() >= SECURITY_PRINTABLE_PREFIX_LEN {
// Printable characters use base64 letters instead
static ASCII_PRINTABLE_CHARS: &[u8] = br##"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"##;

for b in nonce.iter_mut().take(SECURITY_PRINTABLE_PREFIX_LEN) {
*b = ASCII_PRINTABLE_CHARS[(*b as usize) % ASCII_PRINTABLE_CHARS.len()];
}
}
}

// Salt already exists, generate a new one.
if unique && self.check_nonce_and_set(method, nonce) {
continue;
Expand Down Expand Up @@ -163,20 +147,3 @@ impl Context {
self.replay_policy
}
}

#[cfg(test)]
mod tests {
use crate::config::ServerType;
use crate::context::Context;
use byte_string::ByteStr;
use shadowsocks_crypto::CipherKind;

#[test]
fn generate_nonce() {
let mut salt = vec![0u8; 64];
let context = Context::new(ServerType::Server);
context.generate_nonce(CipherKind::AES_128_GCM, &mut salt, false);
println!("generate nonce printable ascii: {:?}", ByteStr::new(&salt));
}

}