Skip to content

Commit 930b9fe

Browse files
committed
C++: Add triple-DES to the bad algorithms list.
1 parent 57354de commit 930b9fe

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import cpp
1010
string getAnInsecureAlgorithmName() {
1111
result =
1212
[
13-
"DES", "RC2", "RC4", "RC5", "ARCFOUR" // ARCFOUR is a variant of RC4
13+
"DES", "RC2", "RC4", "RC5", "ARCFOUR", // ARCFOUR is a variant of RC4
14+
"3DES", "DES3" // also appears separated, e.g. "TRIPLE-DES", which will be matched as "DES".
1415
]
1516
}
1617

@@ -53,12 +54,7 @@ string getInsecureAlgorithmRegex() {
5354
* insecure encyption algorithm.
5455
*/
5556
bindingset[name]
56-
predicate isInsecureEncryption(string name) {
57-
name.regexpMatch(getInsecureAlgorithmRegex()) and
58-
// Check for evidence that an otherwise matching name may in fact not be
59-
// related to insecure encrpytion, e.g. "Triple-DES" is not "DES".
60-
not name.toUpperCase().regexpMatch(".*TRIPLE.*")
61-
}
57+
predicate isInsecureEncryption(string name) { name.regexpMatch(getInsecureAlgorithmRegex()) }
6258

6359
/**
6460
* Holds if there is additional evidence that `name` looks like it might be

cpp/ql/test/query-tests/Security/CWE/CWE-327/BrokenCryptoAlgorithm.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
| test2.cpp:239:5:239:11 | call to encrypt | This function call specifies a broken or weak cryptographic algorithm. |
1111
| test.cpp:38:2:38:31 | ENCRYPT_WITH_DES(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1212
| test.cpp:39:2:39:31 | ENCRYPT_WITH_RC2(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
13+
| test.cpp:41:2:41:32 | ENCRYPT_WITH_3DES(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
14+
| test.cpp:42:2:42:38 | ENCRYPT_WITH_TRIPLE_DES(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1315
| test.cpp:51:2:51:32 | DES_DO_ENCRYPTION(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1416
| test.cpp:52:2:52:31 | RUN_DES_ENCODING(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1517
| test.cpp:53:2:53:25 | DES_ENCODE(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1618
| test.cpp:54:2:54:26 | DES_SET_KEY(data,amount) | This macro invocation specifies a broken or weak cryptographic algorithm. |
1719
| test.cpp:88:2:88:11 | call to encryptDES | This function call specifies a broken or weak cryptographic algorithm. |
1820
| test.cpp:89:2:89:11 | call to encryptRC2 | This function call specifies a broken or weak cryptographic algorithm. |
21+
| test.cpp:91:2:91:12 | call to encrypt3DES | This function call specifies a broken or weak cryptographic algorithm. |
22+
| test.cpp:92:2:92:17 | call to encryptTripleDES | This function call specifies a broken or weak cryptographic algorithm. |
1923
| test.cpp:101:2:101:15 | call to do_des_encrypt | This function call specifies a broken or weak cryptographic algorithm. |
2024
| test.cpp:102:2:102:12 | call to DES_Set_Key | This function call specifies a broken or weak cryptographic algorithm. |

cpp/ql/test/query-tests/Security/CWE/CWE-327/test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ void test_macros(void *data, size_t amount, const char *str)
3838
ENCRYPT_WITH_DES(data, amount); // BAD
3939
ENCRYPT_WITH_RC2(data, amount); // BAD
4040
ENCRYPT_WITH_AES(data, amount); // GOOD (good algorithm)
41-
ENCRYPT_WITH_3DES(data, amount); // GOOD (good enough algorithm)
42-
ENCRYPT_WITH_TRIPLE_DES(data, amount); // GOOD (good enough algorithm)
41+
ENCRYPT_WITH_3DES(data, amount); // BAD
42+
ENCRYPT_WITH_TRIPLE_DES(data, amount); // BAD
4343
ENCRYPT_WITH_RC20(data, amount); // GOOD (if there ever is an RC20 algorithm, we have no reason to believe it's weak)
4444
ENCRYPT_WITH_DES_REMOVED(data, amount); // GOOD (implementation has been deleted)
4545

4646
DESENCRYPT(data, amount); // BAD [NOT DETECTED]
4747
RC2ENCRYPT(data, amount); // BAD [NOT DETECTED]
4848
AESENCRYPT(data, amount); // GOOD (good algorithm)
49-
DES3ENCRYPT(data, amount); // GOOD (good enough algorithm)
49+
DES3ENCRYPT(data, amount); // BAD [NOT DETECTED]
5050

5151
DES_DO_ENCRYPTION(data, amount); // BAD
5252
RUN_DES_ENCODING(data, amount); // BAD
@@ -88,13 +88,13 @@ void test_functions(void *data, size_t amount, const char *str)
8888
encryptDES(data, amount); // BAD
8989
encryptRC2(data, amount); // BAD
9090
encryptAES(data, amount); // GOOD (good algorithm)
91-
encrypt3DES(data, amount); // GOOD (good enough algorithm)
92-
encryptTripleDES(data, amount); // GOOD (good enough algorithm)
91+
encrypt3DES(data, amount); // BAD
92+
encryptTripleDES(data, amount); // BAD
9393

9494
DESEncrypt(data, amount); // BAD
9595
RC2Encrypt(data, amount); // BAD
9696
AESEncrypt(data, amount); // GOOD (good algorithm)
97-
DES3Encrypt(data, amount); // GOOD (good enough algorithm)
97+
DES3Encrypt(data, amount); // BAD [NOT DETECTED]
9898

9999
DoDESEncryption(data, amount); // BAD [NOT DETECTED]
100100
encryptDes(data, amount); // BAD [NOT DETECTED]

0 commit comments

Comments
 (0)