Skip to content

Commit fc69c16

Browse files
committed
C++: Deprecate some old terminology.
1 parent 71492f9 commit fc69c16

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

cpp/ql/src/Security/CWE/CWE-327/BrokenCryptoAlgorithm.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class InsecureCryptoSpec extends Locatable {
1818
}
1919

2020
Function getAnInsecureFunction() {
21-
result.getName().regexpMatch(algorithmBlacklistRegex()) and
21+
result.getName().regexpMatch(getInsecureAlgorithmRegex()) and
2222
exists(result.getACallToThisFunction())
2323
}
2424

@@ -33,7 +33,7 @@ class InsecureFunctionCall extends InsecureCryptoSpec, FunctionCall {
3333
}
3434

3535
Macro getAnInsecureMacro() {
36-
result.getName().regexpMatch(algorithmBlacklistRegex()) and
36+
result.getName().regexpMatch(getInsecureAlgorithmRegex()) and
3737
exists(result.getAnInvocation())
3838
}
3939

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

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/**
22
* Provides predicates relating to encryption in C and C++.
33
*/
4+
45
import cpp
56

67
/**
78
* Returns an algorithm that is known to be insecure.
89
*/
9-
string algorithmBlacklist() {
10+
string getAnInsecureAlgorithmName() {
1011
result = "DES" or
1112
result = "RC2" or
1213
result = "RC4" or
@@ -18,7 +19,7 @@ string algorithmBlacklist() {
1819
* Returns the name of a hash algorithm that is insecure if it is being used for
1920
* encryption (but it is hard to know when that is happening).
2021
*/
21-
string hashAlgorithmBlacklist() {
22+
string getAnInsecureHashAlgorithmName() {
2223
result = "SHA1" or
2324
result = "MD5"
2425
}
@@ -27,23 +28,23 @@ string hashAlgorithmBlacklist() {
2728
* Returns a regular expression for matching strings that look like they
2829
* contain an algorithm that is known to be insecure.
2930
*/
30-
string algorithmBlacklistRegex() {
31+
string getInsecureAlgorithmRegex() {
3132
result =
3233
// algorithms usually appear in names surrounded by characters that are not
3334
// alphabetical characters in the same case. This handles the upper and lower
3435
// case cases
35-
"(^|.*[^A-Z])(" + strictconcat(algorithmBlacklist(), "|") + ")([^A-Z].*|$)" + "|" +
36+
"(^|.*[^A-Z])(" + strictconcat(getAnInsecureAlgorithmName(), "|") + ")([^A-Z].*|$)" + "|" +
3637
// for lowercase, we want to be careful to avoid being confused by camelCase
3738
// hence we require two preceding uppercase letters to be sure of a case switch,
3839
// or a preceding non-alphabetic character
39-
"(^|.*[A-Z]{2}|.*[^a-zA-Z])(" + strictconcat(algorithmBlacklist().toLowerCase(), "|") +
40+
"(^|.*[A-Z]{2}|.*[^a-zA-Z])(" + strictconcat(getAnInsecureAlgorithmName().toLowerCase(), "|") +
4041
")([^a-z].*|$)"
4142
}
4243

4344
/**
4445
* Returns an algorithms that is known to be secure.
4546
*/
46-
string algorithmWhitelist() {
47+
string getASecureAlgorithmName() {
4748
result = "RSA" or
4849
result = "SHA256" or
4950
result = "CCM" or
@@ -57,16 +58,44 @@ string algorithmWhitelist() {
5758
* Returns a regular expression for matching strings that look like they
5859
* contain an algorithm that is known to be secure.
5960
*/
60-
string algorithmWhitelistRegex() {
61-
// The implementation of this is a duplicate of algorithmBlacklistRegex, as
61+
string getSecureAlgorithmRegex() {
62+
// The implementation of this is a duplicate of getInsecureAlgorithmRegex, as
6263
// it isn't possible to have string -> string functions at the moment
6364
// algorithms usually appear in names surrounded by characters that are not
6465
// alphabetical characters in the same case. This handles the upper and lower
6566
// case cases
66-
result = "(^|.*[^A-Z])" + algorithmWhitelist() + "([^A-Z].*|$)"
67+
result = "(^|.*[^A-Z])" + getASecureAlgorithmName() + "([^A-Z].*|$)"
6768
or
6869
// for lowercase, we want to be careful to avoid being confused by camelCase
6970
// hence we require two preceding uppercase letters to be sure of a case
7071
// switch, or a preceding non-alphabetic character
71-
result = "(^|.*[A-Z]{2}|.*[^a-zA-Z])" + algorithmWhitelist().toLowerCase() + "([^a-z].*|$)"
72+
result = "(^|.*[A-Z]{2}|.*[^a-zA-Z])" + getASecureAlgorithmName().toLowerCase() + "([^a-z].*|$)"
7273
}
74+
75+
/**
76+
* DEPRECATED: Terminology has been updated. Use `getAnInsecureAlgorithmName()`
77+
* instead.
78+
*/
79+
deprecated string algorithmBlacklist() { result = getAnInsecureAlgorithmName() }
80+
81+
/**
82+
* DEPRECATED: Terminology has been updated. Use
83+
* `getAnInsecureHashAlgorithmName()` instead.
84+
*/
85+
deprecated string hashAlgorithmBlacklist() { result = getAnInsecureHashAlgorithmName() }
86+
87+
/**
88+
* DEPRECATED: Terminology has been updated. Use `getInsecureAlgorithmRegex()` instead.
89+
*/
90+
deprecated string algorithmBlacklistRegex() { result = getInsecureAlgorithmRegex() }
91+
92+
/**
93+
* DEPRECATED: Terminology has been updated. Use `getASecureAlgorithmName()`
94+
* instead.
95+
*/
96+
deprecated string algorithmWhitelist() { result = getASecureAlgorithmName() }
97+
98+
/**
99+
* DEPRECATED: Terminology has been updated. Use `getSecureAlgorithmRegex()` instead.
100+
*/
101+
deprecated string algorithmWhitelistRegex() { result = getSecureAlgorithmRegex() }

0 commit comments

Comments
 (0)