diff --git a/java/ql/lib/change-notes/2026-11-24-encryption-nist-800-131ar2.md b/java/ql/lib/change-notes/2026-11-24-encryption-nist-800-131ar2.md new file mode 100644 index 000000000000..f9f16902391d --- /dev/null +++ b/java/ql/lib/change-notes/2026-11-24-encryption-nist-800-131ar2.md @@ -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. diff --git a/java/ql/lib/semmle/code/java/security/Encryption.qll b/java/ql/lib/semmle/code/java/security/Encryption.qll index 24fd949b5222..f1f2b55d95ed 100644 --- a/java/ql/lib/semmle/code/java/security/Encryption.qll +++ b/java/ql/lib/semmle/code/java/security/Encryption.qll @@ -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 = "(?
  • NIST, FIPS 140 Annex a: Approved Security Functions.
  • -
  • NIST, SP 800-131A: +
  • NIST, SP 800-131A: Transitions: Recommendation for Transitioning the Use of Cryptographic Algorithms and Key Lengths.
  • diff --git a/java/ql/test/library-tests/Encryption/Test.java b/java/ql/test/library-tests/Encryption/Test.java index 91bc293c9640..ca79a3472816 100644 --- a/java/ql/test/library-tests/Encryption/Test.java +++ b/java/ql/test/library-tests/Encryption/Test.java @@ -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", @@ -21,6 +33,9 @@ class Test { List 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"); diff --git a/java/ql/test/library-tests/Encryption/cryptoalgospec.expected b/java/ql/test/library-tests/Encryption/cryptoalgospec.expected index ab6bb4081bbd..59368e5dd945 100644 --- a/java/ql/test/library-tests/Encryption/cryptoalgospec.expected +++ b/java/ql/test/library-tests/Encryption/cryptoalgospec.expected @@ -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" | diff --git a/java/ql/test/library-tests/Encryption/insecure.expected b/java/ql/test/library-tests/Encryption/insecure.expected index eda453984376..8c98d7f19959 100644 --- a/java/ql/test/library-tests/Encryption/insecure.expected +++ b/java/ql/test/library-tests/Encryption/insecure.expected @@ -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. | diff --git a/java/ql/test/library-tests/Encryption/secure.expected b/java/ql/test/library-tests/Encryption/secure.expected index 18291dd062a8..1dbf16c51fe5 100644 --- a/java/ql/test/library-tests/Encryption/secure.expected +++ b/java/ql/test/library-tests/Encryption/secure.expected @@ -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" | diff --git a/java/ql/test/query-tests/security/CWE-327/semmle/tests/BrokenCryptoAlgorithm.expected b/java/ql/test/query-tests/security/CWE-327/semmle/tests/BrokenCryptoAlgorithm.expected index 7780618a0bec..c2817753eec6 100644 --- a/java/ql/test/query-tests/security/CWE-327/semmle/tests/BrokenCryptoAlgorithm.expected +++ b/java/ql/test/query-tests/security/CWE-327/semmle/tests/BrokenCryptoAlgorithm.expected @@ -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" | @@ -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 diff --git a/java/ql/test/query-tests/security/CWE-327/semmle/tests/Test.java b/java/ql/test/query-tests/security/CWE-327/semmle/tests/Test.java index d4809693d378..1ec28ef22817 100644 --- a/java/ql/test/query-tests/security/CWE-327/semmle/tests/Test.java +++ b/java/ql/test/query-tests/security/CWE-327/semmle/tests/Test.java @@ -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);