Skip to content

Commit db0500b

Browse files
committed
Java: Direct port of changes to Java.
1 parent 51db147 commit db0500b

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

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

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides predicates and classes relating to encryption in Java.
3+
*/
4+
15
import java
26

37
class SSLClass extends RefType {
@@ -85,17 +89,22 @@ private string algorithmRegex(string algorithmString) {
8589
"((^|.*[A-Z]{2}|.*[^a-zA-Z])(" + algorithmString.toLowerCase() + ")([^a-z].*|$))"
8690
}
8791

88-
/** Gets a blacklist of algorithms that are known to be insecure. */
89-
private string algorithmBlacklist() {
92+
/**
93+
* Gets the name of an algorithm that is known to be insecure.
94+
*/
95+
string getAnInsecureAlgorithmName() {
9096
result = "DES" or
9197
result = "RC2" or
9298
result = "RC4" or
9399
result = "RC5" or
94100
result = "ARCFOUR" // a variant of RC4
95101
}
96102

97-
// These are only bad if they're being used for encryption.
98-
private string hashAlgorithmBlacklist() {
103+
/**
104+
* Gets the name of a hash algorithm that is insecure if it is being used for
105+
* encryption.
106+
*/
107+
string getAnInsecureHashAlgorithmName() {
99108
result = "SHA1" or
100109
result = "MD5"
101110
}
@@ -112,14 +121,19 @@ private string algorithmBlacklistString(int i) {
112121
result = rankedAlgorithmBlacklist(i) + "|" + algorithmBlacklistString(i - 1)
113122
}
114123

115-
/** Gets a regex for matching strings that look like they contain a blacklisted algorithm. */
116-
string algorithmBlacklistRegex() {
124+
/**
125+
* Gets the regular expression used for matching strings that look like they
126+
* contain an algorithm that is known to be insecure.
127+
*/
128+
string getInsecureAlgorithmRegex() {
117129
result =
118130
algorithmRegex(algorithmBlacklistString(max(int i | exists(rankedAlgorithmBlacklist(i)))))
119131
}
120132

121-
/** Gets a whitelist of algorithms that are known to be secure. */
122-
private string algorithmWhitelist() {
133+
/**
134+
* Gets the name of an algorithm that is known to be secure.
135+
*/
136+
string getASecureAlgorithmName() {
123137
result = "RSA" or
124138
result = "SHA256" or
125139
result = "SHA512" or
@@ -138,12 +152,43 @@ private string algorithmWhitelistString(int i) {
138152
result = rankedAlgorithmWhitelist(i) + "|" + algorithmWhitelistString(i - 1)
139153
}
140154

141-
/** Gets a regex for matching strings that look like they contain a whitelisted algorithm. */
142-
string algorithmWhitelistRegex() {
155+
/**
156+
* Gets a regular expression for matching strings that look like they
157+
* contain an algorithm that is known to be secure.
158+
*/
159+
string getSecureAlgorithmRegex() {
143160
result =
144161
algorithmRegex(algorithmWhitelistString(max(int i | exists(rankedAlgorithmWhitelist(i)))))
145162
}
146163

164+
/**
165+
* DEPRECATED: Terminology has been updated. Use `getAnInsecureAlgorithmName()`
166+
* instead.
167+
*/
168+
deprecated string algorithmBlacklist() { result = getAnInsecureAlgorithmName() }
169+
170+
/**
171+
* DEPRECATED: Terminology has been updated. Use
172+
* `getAnInsecureHashAlgorithmName()` instead.
173+
*/
174+
deprecated string hashAlgorithmBlacklist() { result = getAnInsecureHashAlgorithmName() }
175+
176+
/**
177+
* DEPRECATED: Terminology has been updated. Use `getInsecureAlgorithmRegex()` instead.
178+
*/
179+
deprecated string algorithmBlacklistRegex() { result = getInsecureAlgorithmRegex() }
180+
181+
/**
182+
* DEPRECATED: Terminology has been updated. Use `getASecureAlgorithmName()`
183+
* instead.
184+
*/
185+
deprecated string algorithmWhitelist() { result = getASecureAlgorithmName() }
186+
187+
/**
188+
* DEPRECATED: Terminology has been updated. Use `getSecureAlgorithmRegex()` instead.
189+
*/
190+
deprecated string algorithmWhitelistRegex() { result = getSecureAlgorithmRegex() }
191+
147192
/**
148193
* Any use of a cryptographic element that specifies an encryption
149194
* algorithm. For example, methods returning ciphers, decryption methods,

0 commit comments

Comments
 (0)