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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* Updated the `java/weak-cryptographic-algorithm` query in line with NIST SP 800-131A Rev. 2 to report `SKIPJACK` (`Skipjack`) as insecure and to report Triple DES (`DESede`, `DESedeWrap`, `TripleDES`, `3DES`) with a dedicated Triple DES explanation rather than the single-DES message, including uppercase and lowercase variants.
* Updated the `java/potentially-weak-cryptographic-algorithm` query to recognize `ChaCha20`, `ChaCha20-Poly1305`, and `ChaCha20Poly1305` as secure algorithms, removing false positives.
20 changes: 18 additions & 2 deletions java/ql/lib/semmle/code/java/security/Encryption.qll
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,24 @@ private string algorithmRegex(string algorithmString) {
* `reason` explains why it is insecure.
*/
predicate insecureAlgorithm(string name, string reason) {
name = "DES" and
// Exclude 3DES variants (such as TripleDES, 3DES, and DESede), which are handled separately below.
name = "(?<!(?i)triple)(?<!(?i)triple[-_])(?<!3)(?<!3[-_])DES(?!(?i)[-_]?ede|[-_]?3)" and
reason =
"It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead."
or
// 3TDEA (Triple DES) has different names across JCA, JSSE, and Bouncy Castle.
name =
[
"DES[-_]?ede((RFC3211)?Wrap)?", "(?i)PBEWithSHA1AndDESede", "Triple[-_]?DES", "3[-_]?DES",
"DES[-_]?3"
] and
reason =
"It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead."
or
name = ["SKIPJACK", "Skipjack"] and
reason =
"It has a short key length of 80 bits, making it vulnerable to brute-force attacks, and has been disallowed by NIST. Consider using AES instead."
Comment on lines +223 to +227
or
name = "RC2" and
reason = "It is vulnerable to related-key attacks. Consider using AES instead."
or
Expand Down Expand Up @@ -268,7 +282,9 @@ string getASecureAlgorithmName() {
// These are modern, secure algorithms recommended by NIST and other standards bodies.
"EC", "ECDSA", "ECDH", "EdDSA", "Ed25519", "Ed448", "XDH", "X25519", "X448",
// HMAC-based algorithms and key derivation functions.
"HMACSHA(1|256|384|512)", "HmacSHA(1|256|384|512)", "PBKDF2"
"HMACSHA(1|256|384|512)", "HmacSHA(1|256|384|512)", "PBKDF2",
// Stream cipher and AEAD construction (RFC 8439 / JEP 329).
"ChaCha20", "ChaCha20Poly1305"
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ is a strong modern algorithm.</p>

<li>NIST, FIPS 140 Annex a: <a href="http://csrc.nist.gov/publications/fips/fips140-2/fips1402annexa.pdf">
Approved Security Functions</a>.</li>
<li>NIST, SP 800-131A: <a href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar1.pdf">
<li>NIST, SP 800-131A: <a href="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf">
Transitions: Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths</a>.</li>


Expand Down
15 changes: 15 additions & 0 deletions java/ql/test/library-tests/Encryption/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ class Test {
"des_function",
"function_using_des",
"EncryptWithDES",
"DESede",
"DESedeWrap",
"DESedeRFC3211Wrap",
"DESEDERFC3211WRAP",
"desederfc3211wrap",
"PBEWithSHA1AndDESedE",
"PBEWITHSHA1ANDDESEDE",
"pbewithsha1anddesede",
"TripleDES",
"3DES",
"SKIPJACK",
"Skipjack",
"RC2",
"RC4",
"ARCFOUR",
Expand All @@ -21,6 +33,9 @@ class Test {
List<String> goodStrings = Arrays.asList(
"AES",
"AES_function",
"ChaCha20",
"ChaCha20-Poly1305",
"ChaCha20Poly1305",
// false negative - can't think of a good way to detect this without
// catching things we shouldn't
"AESEncryption");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| Test.java:41:4:41:17 | super(...) | Test.java:41:10:41:15 | "some" |
| Test.java:45:3:45:38 | getInstance(...) | Test.java:45:29:45:37 | "another" |
| Test.java:56:4:56:17 | super(...) | Test.java:56:10:56:15 | "some" |
| Test.java:60:3:60:38 | getInstance(...) | Test.java:60:29:60:37 | "another" |
24 changes: 18 additions & 6 deletions java/ql/test/library-tests/Encryption/insecure.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
| Test.java:11:4:11:17 | "des_function" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. |
| Test.java:12:4:12:23 | "function_using_des" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. |
| Test.java:13:4:13:19 | "EncryptWithDES" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. |
| Test.java:14:4:14:8 | "RC2" | It is vulnerable to related-key attacks. Consider using AES instead. |
| Test.java:15:4:15:8 | "RC4" | It has multiple vulnerabilities, including biases in its output and susceptibility to several attacks. Consider using AES instead. |
| Test.java:16:4:16:12 | "ARCFOUR" | It has multiple vulnerabilities, including biases in its output and susceptibility to several attacks. Consider using AES instead. |
| Test.java:17:4:17:8 | "RC5" | It is vulnerable to differential and related-key attacks. Consider using AES instead. |
| Test.java:18:4:18:22 | "AES/ECB/NoPadding" | ECB mode, as in AES/ECB/NoPadding for example, is vulnerable to replay and other attacks. Consider using GCM instead. |
| Test.java:19:4:19:25 | "AES/CBC/PKCS5Padding" | CBC mode with PKCS#5 or PKCS#7 padding is vulnerable to padding oracle attacks. Consider using GCM instead. |
| Test.java:14:4:14:11 | "DESede" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:15:4:15:15 | "DESedeWrap" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:16:4:16:22 | "DESedeRFC3211Wrap" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:17:4:17:22 | "DESEDERFC3211WRAP" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:18:4:18:22 | "desederfc3211wrap" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:19:4:19:25 | "PBEWithSHA1AndDESedE" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:20:4:20:25 | "PBEWITHSHA1ANDDESEDE" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:21:4:21:25 | "pbewithsha1anddesede" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:22:4:22:14 | "TripleDES" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:23:4:23:9 | "3DES" | It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:24:4:24:13 | "SKIPJACK" | It has a short key length of 80 bits, making it vulnerable to brute-force attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:25:4:25:13 | "Skipjack" | It has a short key length of 80 bits, making it vulnerable to brute-force attacks, and has been disallowed by NIST. Consider using AES instead. |
| Test.java:26:4:26:8 | "RC2" | It is vulnerable to related-key attacks. Consider using AES instead. |
| Test.java:27:4:27:8 | "RC4" | It has multiple vulnerabilities, including biases in its output and susceptibility to several attacks. Consider using AES instead. |
| Test.java:28:4:28:12 | "ARCFOUR" | It has multiple vulnerabilities, including biases in its output and susceptibility to several attacks. Consider using AES instead. |
| Test.java:29:4:29:8 | "RC5" | It is vulnerable to differential and related-key attacks. Consider using AES instead. |
| Test.java:30:4:30:22 | "AES/ECB/NoPadding" | ECB mode, as in AES/ECB/NoPadding for example, is vulnerable to replay and other attacks. Consider using GCM instead. |
| Test.java:31:4:31:25 | "AES/CBC/PKCS5Padding" | CBC mode with PKCS#5 or PKCS#7 padding is vulnerable to padding oracle attacks. Consider using GCM instead. |
7 changes: 5 additions & 2 deletions java/ql/test/library-tests/Encryption/secure.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
| Test.java:22:4:22:8 | "AES" |
| Test.java:23:4:23:17 | "AES_function" |
| Test.java:34:4:34:8 | "AES" |
| Test.java:35:4:35:17 | "AES_function" |
| Test.java:36:4:36:13 | "ChaCha20" |
| Test.java:37:4:37:22 | "ChaCha20-Poly1305" |
| Test.java:38:4:38:21 | "ChaCha20Poly1305" |
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
| Test.java:47:14:47:55 | getInstance(...) | Test.java:47:33:47:54 | "AES/CBC/PKCS5PADDING" | Test.java:47:33:47:54 | "AES/CBC/PKCS5PADDING" | Cryptographic algorithm $@ is insecure. CBC mode with PKCS#5 or PKCS#7 padding is vulnerable to padding oracle attacks. Consider using GCM instead. | Test.java:47:33:47:54 | "AES/CBC/PKCS5PADDING" | AES/CBC/PKCS5PADDING |
| Test.java:48:14:48:55 | getInstance(...) | Test.java:48:33:48:54 | "aes/cbc/pkcs5padding" | Test.java:48:33:48:54 | "aes/cbc/pkcs5padding" | Cryptographic algorithm $@ is insecure. CBC mode with PKCS#5 or PKCS#7 padding is vulnerable to padding oracle attacks. Consider using GCM instead. | Test.java:48:33:48:54 | "aes/cbc/pkcs5padding" | aes/cbc/pkcs5padding |
| Test.java:49:14:49:55 | getInstance(...) | Test.java:49:33:49:54 | "AES/cbc/Pkcs5Padding" | Test.java:49:33:49:54 | "AES/cbc/Pkcs5Padding" | Cryptographic algorithm $@ is insecure. CBC mode with PKCS#5 or PKCS#7 padding is vulnerable to padding oracle attacks. Consider using GCM instead. | Test.java:49:33:49:54 | "AES/cbc/Pkcs5Padding" | AES/cbc/Pkcs5Padding |
| Test.java:53:14:53:58 | getInstance(...) | Test.java:53:33:53:57 | "DESede/CBC/PKCS5Padding" | Test.java:53:33:53:57 | "DESede/CBC/PKCS5Padding" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:53:33:53:57 | "DESede/CBC/PKCS5Padding" | DESede/CBC/PKCS5Padding |
| Test.java:54:14:54:41 | getInstance(...) | Test.java:54:33:54:40 | "DESEDE" | Test.java:54:33:54:40 | "DESEDE" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:54:33:54:40 | "DESEDE" | DESEDE |
| Test.java:55:14:55:52 | getInstance(...) | Test.java:55:33:55:51 | "DESedeRFC3211Wrap" | Test.java:55:33:55:51 | "DESedeRFC3211Wrap" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:55:33:55:51 | "DESedeRFC3211Wrap" | DESedeRFC3211Wrap |
| Test.java:56:14:56:52 | getInstance(...) | Test.java:56:33:56:51 | "DESEDERFC3211WRAP" | Test.java:56:33:56:51 | "DESEDERFC3211WRAP" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:56:33:56:51 | "DESEDERFC3211WRAP" | DESEDERFC3211WRAP |
| Test.java:57:14:57:52 | getInstance(...) | Test.java:57:33:57:51 | "desederfc3211wrap" | Test.java:57:33:57:51 | "desederfc3211wrap" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:57:33:57:51 | "desederfc3211wrap" | desederfc3211wrap |
| Test.java:58:14:58:55 | getInstance(...) | Test.java:58:33:58:54 | "PBEWithSHA1AndDESedE" | Test.java:58:33:58:54 | "PBEWithSHA1AndDESedE" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:58:33:58:54 | "PBEWithSHA1AndDESedE" | PBEWithSHA1AndDESedE |
| Test.java:59:14:59:55 | getInstance(...) | Test.java:59:33:59:54 | "PBEWITHSHA1ANDDESEDE" | Test.java:59:33:59:54 | "PBEWITHSHA1ANDDESEDE" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:59:33:59:54 | "PBEWITHSHA1ANDDESEDE" | PBEWITHSHA1ANDDESEDE |
| Test.java:60:14:60:55 | getInstance(...) | Test.java:60:33:60:54 | "pbewithsha1anddesede" | Test.java:60:33:60:54 | "pbewithsha1anddesede" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:60:33:60:54 | "pbewithsha1anddesede" | pbewithsha1anddesede |
| Test.java:61:14:61:44 | getInstance(...) | Test.java:61:33:61:43 | "TripleDES" | Test.java:61:33:61:43 | "TripleDES" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:61:33:61:43 | "TripleDES" | TripleDES |
| Test.java:62:14:62:39 | getInstance(...) | Test.java:62:33:62:38 | "3DES" | Test.java:62:33:62:38 | "3DES" | Cryptographic algorithm $@ is insecure. It uses a 64-bit block size, making it vulnerable to birthday attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:62:33:62:38 | "3DES" | 3DES |
| Test.java:63:14:63:43 | getInstance(...) | Test.java:63:33:63:42 | "SKIPJACK" | Test.java:63:33:63:42 | "SKIPJACK" | Cryptographic algorithm $@ is insecure. It has a short key length of 80 bits, making it vulnerable to brute-force attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:63:33:63:42 | "SKIPJACK" | SKIPJACK |
| Test.java:64:14:64:43 | getInstance(...) | Test.java:64:33:64:42 | "Skipjack" | Test.java:64:33:64:42 | "Skipjack" | Cryptographic algorithm $@ is insecure. It has a short key length of 80 bits, making it vulnerable to brute-force attacks, and has been disallowed by NIST. Consider using AES instead. | Test.java:64:33:64:42 | "Skipjack" | Skipjack |
edges
nodes
| Test.java:19:45:19:49 | "DES" | semmle.label | "DES" |
Expand All @@ -13,4 +25,16 @@ nodes
| Test.java:47:33:47:54 | "AES/CBC/PKCS5PADDING" | semmle.label | "AES/CBC/PKCS5PADDING" |
| Test.java:48:33:48:54 | "aes/cbc/pkcs5padding" | semmle.label | "aes/cbc/pkcs5padding" |
| Test.java:49:33:49:54 | "AES/cbc/Pkcs5Padding" | semmle.label | "AES/cbc/Pkcs5Padding" |
| Test.java:53:33:53:57 | "DESede/CBC/PKCS5Padding" | semmle.label | "DESede/CBC/PKCS5Padding" |
| Test.java:54:33:54:40 | "DESEDE" | semmle.label | "DESEDE" |
| Test.java:55:33:55:51 | "DESedeRFC3211Wrap" | semmle.label | "DESedeRFC3211Wrap" |
| Test.java:56:33:56:51 | "DESEDERFC3211WRAP" | semmle.label | "DESEDERFC3211WRAP" |
| Test.java:57:33:57:51 | "desederfc3211wrap" | semmle.label | "desederfc3211wrap" |
| Test.java:58:33:58:54 | "PBEWithSHA1AndDESedE" | semmle.label | "PBEWithSHA1AndDESedE" |
| Test.java:59:33:59:54 | "PBEWITHSHA1ANDDESEDE" | semmle.label | "PBEWITHSHA1ANDDESEDE" |
| Test.java:60:33:60:54 | "pbewithsha1anddesede" | semmle.label | "pbewithsha1anddesede" |
| Test.java:61:33:61:43 | "TripleDES" | semmle.label | "TripleDES" |
| Test.java:62:33:62:38 | "3DES" | semmle.label | "3DES" |
| Test.java:63:33:63:42 | "SKIPJACK" | semmle.label | "SKIPJACK" |
| Test.java:64:33:64:42 | "Skipjack" | semmle.label | "Skipjack" |
subpaths
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ public void test() {
cipher = Cipher.getInstance("aes/cbc/pkcs5padding"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("AES/cbc/Pkcs5Padding"); // $ Alert[java/weak-cryptographic-algorithm]
}
{
// BAD: Triple DES (3TDEA) and Skipjack are disallowed by NIST SP 800-131A Rev. 2
cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("DESEDE"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("DESedeRFC3211Wrap"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("DESEDERFC3211WRAP"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("desederfc3211wrap"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("PBEWithSHA1AndDESedE"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("PBEWITHSHA1ANDDESEDE"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("pbewithsha1anddesede"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("TripleDES"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("3DES"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("SKIPJACK"); // $ Alert[java/weak-cryptographic-algorithm]
cipher = Cipher.getInstance("Skipjack"); // $ Alert[java/weak-cryptographic-algorithm]
}
// GOOD: ChaCha20 and ChaCha20-Poly1305 are strong modern algorithms
keyGenerator = KeyGenerator.getInstance("ChaCha20");
cipher = Cipher.getInstance("ChaCha20-Poly1305");
cipher = Cipher.getInstance("ChaCha20Poly1305");

// GOOD: ECIES is a strong algorithm
cipher = Cipher.getInstance("ECIES");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
Expand Down
Loading