Skip to content

Commit a906346

Browse files
authored
Merge pull request #22 from gsutherland-trailofbits/gsutherland-trailofbits-cpp-legacy-algorithm
Improve C++ legacy crypto algorithm query
2 parents bac0acc + 9cd9ef3 commit a906346

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed
Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Use of legacy cryptographic algorithm
33
* @id tob/cpp/use-of-legacy-algorithm
4-
* @description Detects potential calls to legacy cryptographic algorithms
4+
* @description Detects potential instantiations of legacy cryptographic algorithms
55
* @kind problem
66
* @tags correctness crypto
77
* @problem.severity warning
@@ -11,19 +11,35 @@
1111

1212
import cpp
1313

14-
from FunctionCall call
14+
from FunctionCall call, string functionName, string cipherName
1515
where
16-
call.getTarget()
17-
.getQualifiedName()
18-
.toLowerCase()
19-
.matches([
20-
// Hash functions
21-
"%md2%", "%md4%", "%md5%", "%ripemd%", "%sha1%", "%whirlpool%", "%streebog%",
22-
// KDFs
23-
"%pbkdf1%",
24-
// Symmetric ciphers
25-
"%arcfour%", "%blowfish%", "%kasumi%", "%magma%", "%rc2%", "%rc4%", "%tdea%"
26-
])
16+
functionName = call.getTarget()
17+
.getQualifiedName()
18+
.toLowerCase()
19+
and
20+
(
21+
exists(string cn |
22+
cn in [
23+
"MD2", "MD4", "MD5", "RIPEMD", "SHA1", "Whirlpool", "Streebog",
24+
"PBKDF1",
25+
"ArcFour", "Blowfish", "CAST", "IDEA", "Kasumi",
26+
"Magma", "RC2", "RC4", "TDEA"
27+
]
28+
and cipherName = cn
29+
and functionName.matches("%" + cn.toLowerCase() + "%")
30+
)
31+
/* match DES, but avoid false positives by not matching common terms containing it:
32+
nodes
33+
modes
34+
codes
35+
describe
36+
description
37+
descriptor
38+
design
39+
descend
40+
destroy
41+
*/
42+
or cipherName = "DES" and functionName.regexpMatch(".*(?<!no|mo|co)des(?!cri(be|ption|ptor)|ign|cend|troy).*")
43+
)
2744
select call.getLocation(),
28-
"Potential use of legacy cryptographic algorithm " + call.getTarget().getQualifiedName() +
29-
" detected"
45+
"Potential use of legacy cryptographic algorithm " + cipherName + " detected in function name " + call.getTarget().getQualifiedName()

0 commit comments

Comments
 (0)