Skip to content

Commit 40cf29b

Browse files
committed
C++: Rearrange the library.
1 parent 0450caa commit 40cf29b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
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(getInsecureAlgorithmRegex()) and
21+
isInsecureEncryption(result.getName()) and
2222
exists(result.getACallToThisFunction())
2323
}
2424

@@ -36,7 +36,7 @@ class InsecureFunctionCall extends InsecureCryptoSpec, FunctionCall {
3636
}
3737

3838
Macro getAnInsecureMacro() {
39-
result.getName().regexpMatch(getInsecureAlgorithmRegex()) and
39+
isInsecureEncryption(result.getName()) and
4040
exists(result.getAnInvocation())
4141
}
4242

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ string getAnInsecureAlgorithmName() {
1414
]
1515
}
1616

17+
/**
18+
* Gets the name of an algorithm that is known to be secure.
19+
*/
20+
string getASecureAlgorithmName() {
21+
result = ["RSA", "SHA256", "CCM", "GCM", "AES", "Blowfish", "ECIES"]
22+
}
23+
1724
/**
1825
* Gets the name of a hash algorithm that is insecure if it is being used for
1926
* encryption (but it is hard to know when that is happening).
@@ -39,10 +46,11 @@ string getInsecureAlgorithmRegex() {
3946
}
4047

4148
/**
42-
* Gets the name of an algorithm that is known to be secure.
49+
* Holds if `name` looks like it might be related to operations with an
50+
* insecure encyption algorithm.
4351
*/
44-
string getASecureAlgorithmName() {
45-
result = ["RSA", "SHA256", "CCM", "GCM", "AES", "Blowfish", "ECIES"]
52+
bindingset[name] predicate isInsecureEncryption(string name) {
53+
name.regexpMatch(getInsecureAlgorithmRegex())
4654
}
4755

4856
/**

0 commit comments

Comments
 (0)