diff --git a/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/Cargo.lock b/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/Cargo.lock index 708b79ed46d5..a47021d54b46 100644 --- a/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/Cargo.lock +++ b/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/Cargo.lock @@ -76,6 +76,15 @@ dependencies = [ "cipher", ] +[[package]] +name = "ecb" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a8bfa975b1aec2145850fcaa1c6fe269a16578c44705a532ae3edc92b8881c7" +dependencies = [ + "cipher", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -146,6 +155,7 @@ dependencies = [ "cbc", "cipher", "des", + "ecb", "rabbit", "rc2", "rc4", diff --git a/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/options.yml b/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/options.yml index 5a3cf0cab12e..139cb084be20 100644 --- a/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/options.yml +++ b/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/options.yml @@ -8,3 +8,4 @@ qltest_dependencies: - rc2 = { version = "0.8.1" } - rc5 = { version = "0.0.1" } - cbc = { version = "0.1.2" } + - ecb = { version = "0.1.2" } diff --git a/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/test_cipher.rs b/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/test_cipher.rs index 61471ac99ecf..17db0f9ceb19 100644 --- a/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/test_cipher.rs +++ b/rust/ql/test/query-tests/security/CWE-327/BrokenCryptoAlgorithm/test_cipher.rs @@ -145,3 +145,33 @@ fn test_cbc( let des_cipher4 = cbc::Encryptor::::new(key.into(), iv.into()); // $ MISSING: Alert[rust/weak-cryptographic-algorithm] _ = des_cipher4.encrypt_padded_b2b_mut::(input, data).unwrap(); } + +type MyAesEcbEncryptor = ecb::Encryptor; + +fn test_ecb( + key: &[u8], key128: &[u8;16], + input: &[u8], data: &mut [u8] +) { + let data_len = data.len(); + + // aes with ECB (weak block mode) + let aes_cipher1 = ecb::Encryptor::::new(key128.into()); // $ MISSING: Alert[rust/weak-cryptographic-algorithm] + _ = aes_cipher1.encrypt_padded_mut::(data, data_len).unwrap(); + + let aes_cipher2 = MyAesEcbEncryptor::new(key.into()); // $ MISSING: Alert[rust/weak-cryptographic-algorithm] + _ = aes_cipher2.encrypt_padded_mut::(data, data_len).unwrap(); + + let aes_cipher3 = ecb::Encryptor::::new_from_slice(&key).unwrap(); // $ MISSING: Alert[rust/weak-cryptographic-algorithm] + _ = aes_cipher3.encrypt_padded_mut::(data, data_len).unwrap(); + + let aes_cipher4 = ecb::Encryptor::::new(key.into()); // $ MISSING: Alert[rust/weak-cryptographic-algorithm] + _ = aes_cipher4.encrypt_padded_b2b_mut::(input, data).unwrap(); + + // des with ECB (broken cipher + weak block mode) + let des_cipher1 = ecb::Encryptor::::new(key.into()); // $ MISSING: Alert[rust/weak-cryptographic-algorithm] + _ = des_cipher1.encrypt_padded_mut::(data, data_len).unwrap(); + + // rc2 with ECB (broken cipher + weak block mode) + let rc2_cipher1 = ecb::Encryptor::::new(key.into()); // $ MISSING: Alert[rust/weak-cryptographic-algorithm] + _ = rc2_cipher1.encrypt_padded_mut::(data, data_len).unwrap(); +}