Skip to content

Commit 5106d5d

Browse files
authored
Merge pull request github#4833 from luchua-bc/java-broken-crypto-algorithms
Java: Add missing broken crypto algorithms
2 parents de4cdda + bed8a68 commit 5106d5d

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

java/ql/src/Security/CWE/CWE-327/BrokenCryptoAlgorithm.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ data.</p>
1212
</overview>
1313
<recommendation>
1414

15-
<p>Ensure that you use a strong, modern cryptographic algorithm. Use at least AES-128 or RSA-2048.</p>
15+
<p>Ensure that you use a strong, modern cryptographic algorithm. Use at least AES-128 or RSA-2048. Do not use the ECB encryption mode since it is vulnerable to replay and other attacks.</p>
1616

1717
</recommendation>
1818
<example>

java/ql/src/semmle/code/java/security/Encryption.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ string getAnInsecureAlgorithmName() {
9797
result = "RC2" or
9898
result = "RC4" or
9999
result = "RC5" or
100-
result = "ARCFOUR" // a variant of RC4
100+
result = "ARCFOUR" or // a variant of RC4
101+
result = "ECB" or // encryption mode ECB like AES/ECB/NoPadding is vulnerable to replay and other attacks
102+
result = "AES/CBC/PKCS[5|7]Padding" // CBC mode of operation with PKCS#5 (or PKCS#7) padding is vulnerable to padding oracle attacks
101103
}
102104

103105
/**
@@ -139,7 +141,7 @@ string getASecureAlgorithmName() {
139141
result = "SHA512" or
140142
result = "CCM" or
141143
result = "GCM" or
142-
result = "AES" or
144+
result = "AES([^a-zA-Z](?!ECB|CBC/PKCS[5|7]Padding)).*" or
143145
result = "Blowfish" or
144146
result = "ECIES"
145147
}

java/ql/test/library-tests/Encryption/Test.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class Test {
1010
"des",
1111
"des_function",
1212
"function_using_des",
13-
"EncryptWithDES");
13+
"EncryptWithDES",
14+
"AES/ECB/NoPadding",
15+
"AES/CBC/PKCS5Padding");
1416

1517
List<String> goodStrings = Arrays.asList(
1618
"AES",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Test.java:35:4:35:17 | super(...) | Test.java:35:10:35:15 | "some" |
2-
| Test.java:39:3:39:38 | getInstance(...) | Test.java:39:29:39:37 | "another" |
1+
| Test.java:37:4:37:17 | super(...) | Test.java:37:10:37:15 | "some" |
2+
| Test.java:41:3:41:38 | getInstance(...) | Test.java:41:29:41:37 | "another" |

java/ql/test/library-tests/Encryption/insecure.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
| Test.java:11:4:11:17 | "des_function" |
44
| Test.java:12:4:12:23 | "function_using_des" |
55
| Test.java:13:4:13:19 | "EncryptWithDES" |
6+
| Test.java:14:4:14:22 | "AES/ECB/NoPadding" |
7+
| Test.java:15:4:15:25 | "AES/CBC/PKCS5Padding" |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Test.java:16:4:16:8 | "AES" |
2-
| Test.java:17:4:17:17 | "AES_function" |
1+
| Test.java:18:4:18:8 | "AES" |
2+
| Test.java:19:4:19:17 | "AES_function" |

0 commit comments

Comments
 (0)