Skip to content

Commit 523c15c

Browse files
committed
don't include mode-of-operation into the algorithm names
1 parent 5975e19 commit 523c15c

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

javascript/ql/lib/semmle/javascript/security/CryptoAlgorithms.qll

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,14 @@ private module AlgorithmNames {
3131
}
3232

3333
predicate isStrongEncryptionAlgorithm(string name) {
34-
name = [appendMode("AES"), "AES128", "AES192", "AES256", "AES512", "RSA", "RABBIT", "BLOWFISH"]
35-
}
36-
37-
/**
38-
* Gets the name with a mode of operation added as a suffix.
39-
*/
40-
bindingset[name]
41-
private string appendMode(string name) {
42-
result = name + ["", "CBC", "ECB", "CFB", "OFB", "CTR", "GCM"]
34+
name = ["AES", "AES128", "AES192", "AES256", "AES512", "RSA", "RABBIT", "BLOWFISH"]
4335
}
4436

4537
predicate isWeakEncryptionAlgorithm(string name) {
4638
name =
4739
[
48-
appendMode("DES"), appendMode("3DES"), "TRIPLEDES", "TDEA", "TRIPLEDEA", "ARC2", "RC2",
49-
"ARC4", "RC4", "ARCFOUR", "ARC5", "RC5"
40+
"DES", "3DES", "TRIPLEDES", "TDEA", "TRIPLEDEA", "ARC2", "RC2", "ARC4", "RC4", "ARCFOUR",
41+
"ARC5", "RC5"
5042
]
5143
}
5244

@@ -93,11 +85,12 @@ abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
9385

9486
/**
9587
* Holds if the name of this algorithm matches `name` modulo case,
96-
* white space, dashes, and underscores.
88+
* white space, dashes, underscores, and anything after a dash in the name.
9789
*/
9890
bindingset[name]
9991
predicate matchesName(string name) {
100-
name.toUpperCase().regexpReplaceAll("[-_ ]", "") = getName()
92+
name.toUpperCase().regexpCapture("^(\\w+)(?:-.*)?$", 1).regexpReplaceAll("[-_ ]", "") =
93+
getName()
10194
}
10295

10396
/**

javascript/ql/test/query-tests/Security/CWE-326/InsufficientKeySize.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
| tst.js:14:14:14:60 | CryptoJ ... e: 2 }) | Creation of an symmetric PBKDF2 key uses 64 bits, which is below 128 and considered breakable. |
55
| tst.js:15:14:15:60 | CryptoJ ... e: 2 }) | Creation of an symmetric EVPKDF key uses 64 bits, which is below 128 and considered breakable. |
66
| tst.js:19:12:19:57 | forge.r ... rd, 64) | Creation of an symmetric RC2 key uses 64 bits, which is below 128 and considered breakable. |
7-
| tst.js:26:12:26:53 | forge.c ... , key2) | Creation of an symmetric AESCBC key uses 64 bits, which is below 128 and considered breakable. |
8-
| tst.js:30:12:30:56 | forge.c ... , key3) | Creation of an symmetric 3DESCBC key uses 64 bits, which is below 128 and considered breakable. |
7+
| tst.js:26:12:26:53 | forge.c ... , key2) | Creation of an symmetric AES key uses 64 bits, which is below 128 and considered breakable. |
8+
| tst.js:30:12:30:56 | forge.c ... , key3) | Creation of an symmetric 3DES key uses 64 bits, which is below 128 and considered breakable. |
99
| tst.js:35:13:35:43 | crypto. ... an(512) | Creation of an asymmetric key uses 512 bits, which is below 2048 and considered breakable. |
1010
| tst.js:39:13:39:33 | new Nod ... : 512}) | Creation of an asymmetric RSA key uses 512 bits, which is below 2048 and considered breakable. |
1111
| tst.js:43:1:43:31 | key.gen ... 65537) | Creation of an asymmetric RSA key uses 512 bits, which is below 2048 and considered breakable. |

python/ql/lib/semmle/python/concepts/CryptoAlgorithms.qll

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,14 @@ private module AlgorithmNames {
3131
}
3232

3333
predicate isStrongEncryptionAlgorithm(string name) {
34-
name = [appendMode("AES"), "AES128", "AES192", "AES256", "AES512", "RSA", "RABBIT", "BLOWFISH"]
35-
}
36-
37-
/**
38-
* Gets the name with a mode of operation added as a suffix.
39-
*/
40-
bindingset[name]
41-
private string appendMode(string name) {
42-
result = name + ["", "CBC", "ECB", "CFB", "OFB", "CTR", "GCM"]
34+
name = ["AES", "AES128", "AES192", "AES256", "AES512", "RSA", "RABBIT", "BLOWFISH"]
4335
}
4436

4537
predicate isWeakEncryptionAlgorithm(string name) {
4638
name =
4739
[
48-
appendMode("DES"), appendMode("3DES"), "TRIPLEDES", "TDEA", "TRIPLEDEA", "ARC2", "RC2",
49-
"ARC4", "RC4", "ARCFOUR", "ARC5", "RC5"
40+
"DES", "3DES", "TRIPLEDES", "TDEA", "TRIPLEDEA", "ARC2", "RC2", "ARC4", "RC4", "ARCFOUR",
41+
"ARC5", "RC5"
5042
]
5143
}
5244

@@ -93,11 +85,12 @@ abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
9385

9486
/**
9587
* Holds if the name of this algorithm matches `name` modulo case,
96-
* white space, dashes, and underscores.
88+
* white space, dashes, underscores, and anything after a dash in the name.
9789
*/
9890
bindingset[name]
9991
predicate matchesName(string name) {
100-
name.toUpperCase().regexpReplaceAll("[-_ ]", "") = getName()
92+
name.toUpperCase().regexpCapture("^(\\w+)(?:-.*)?$", 1).regexpReplaceAll("[-_ ]", "") =
93+
getName()
10194
}
10295

10396
/**

0 commit comments

Comments
 (0)