forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeakHashing.ql
More file actions
34 lines (32 loc) · 1002 Bytes
/
WeakHashing.ql
File metadata and controls
34 lines (32 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @name Weak hashes
* @description Finds uses of cryptographic hashing algorithms that are unapproved or otherwise weak.
* @id java/quantum/weak-hashes
* @kind problem
* @problem.severity error
* @precision high
* @tags external/cwe/cwe-327
* quantum
* experimental
*/
import java
import experimental.quantum.Language
from Crypto::HashAlgorithmNode alg, Crypto::HashType htype, string msg
where
htype = alg.getHashType() and
(
htype != Crypto::SHA2() and
msg = "Use of unapproved hash algorithm or API " + htype.toString() + "."
or
htype = Crypto::SHA2() and
not exists(alg.getDigestLength()) and
msg =
"Use of approved hash algorithm or API type " + htype.toString() + " but unknown digest size."
or
htype = Crypto::SHA2() and
alg.getDigestLength() < 256 and
msg =
"Use of approved hash algorithm or API type " + htype.toString() + " but weak digest size (" +
alg.getDigestLength() + ")."
)
select alg, msg