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

Regression: SS_RC4_MD5's salt_len has changed #12

Closed
spacemeowx2 opened this issue Feb 15, 2022 · 2 comments
Closed

Regression: SS_RC4_MD5's salt_len has changed #12

spacemeowx2 opened this issue Feb 15, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@spacemeowx2
Copy link
Contributor

In 0.3.x, the iv_len of SS_RC4_MD5 is changed from 16 to 0.

https://github.com/shadowsocks/shadowsocks-crypto/blob/main/src/v1/streamcipher/rc4_md5.rs#L45

https://github.com/shadowsocks/shadowsocks-crypto/blob/v0.2.5/src/v1/streamcipher/rc4_md5.rs#L24

@spacemeowx2
Copy link
Contributor Author

spacemeowx2 commented Feb 15, 2022

const KEY: &'static [u8] = b"1234123412341234";
const EMPTY_IV: &'static [u8] = b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
const EMPTY: &'static [u8] = b"";
const MSG: &'static [u8] = b"Hello, world!";

fn old_enc() -> Vec<u8> {
    let mut cipher =
        old_crypto::v1::Cipher::new(old_crypto::v1::CipherKind::SS_RC4_MD5, KEY, EMPTY_IV);

    let mut helloworld = MSG.to_vec();

    cipher.encrypt_packet(&mut helloworld);

    helloworld
}

fn main() {
    let mut helloworld = old_enc();
    let mut cipher =
        old_crypto::v1::Cipher::new(old_crypto::v1::CipherKind::SS_RC4_MD5, KEY, EMPTY_IV);

    assert!(cipher.decrypt_packet(&mut helloworld));
    assert_eq!(helloworld, MSG);

    let mut helloworld = old_enc();
    let mut cipher =
        fix_crypto::v1::Cipher::new(fix_crypto::v1::CipherKind::SS_RC4_MD5, KEY, EMPTY_IV);

    assert!(cipher.decrypt_packet(&mut helloworld));
    assert_eq!(helloworld, MSG);

    println!("{:?}", helloworld);

    let mut helloworld = old_enc();
    // NOTE that the IV len is zero, so it's impossible to decrypt
    let mut cipher =
        new_crypto::v1::Cipher::new(new_crypto::v1::CipherKind::SS_RC4_MD5, KEY, EMPTY);

    assert!(cipher.decrypt_packet(&mut helloworld));
    // assert failed here
    assert_eq!(helloworld, MSG);
}

https://github.com/spacemeowx2/bug-crypto

@spacemeowx2
Copy link
Contributor Author

I think a regression test needs to be done for each CipherKind.

@zonyitoo zonyitoo added the bug Something isn't working label Feb 15, 2022
@zonyitoo zonyitoo self-assigned this Feb 15, 2022
zonyitoo added a commit to shadowsocks/shadowsocks-rust that referenced this issue Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants