-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathWeakKDFIterationCount.ql
More file actions
59 lines (50 loc) · 1.94 KB
/
WeakKDFIterationCount.ql
File metadata and controls
59 lines (50 loc) · 1.94 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @name Weak known key derivation function iteration count
* @description Detects key derivation operations with a known weak iteration count.
* @id java/quantum/examples/weak-kdf-iteration-count
* @kind path-problem
* @problem.severity error
* @tags quantum
* experimental
*/
import java
import experimental.quantum.Language
module IterationCountConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source = any(Crypto::GenericSourceInstance i).getOutputNode() or
source = any(Crypto::ArtifactInstance artifact).getOutputNode()
}
predicate isSink(DataFlow::Node sink) {
exists(Crypto::KeyDerivationOperationInstance kdev |
sink = kdev.getIterationCountConsumer().getConsumer().getInputNode()
)
}
predicate isBarrierOut(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getInputNode()
}
predicate isBarrierIn(DataFlow::Node node) {
node = any(Crypto::FlowAwareElement element).getOutputNode()
}
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
node1.(AdditionalFlowInputStep).getOutput() = node2
or
exists(MethodCall m |
m.getMethod().hasQualifiedName("java.lang", "String", "getBytes") and
node1.asExpr() = m.getQualifier() and
node2.asExpr() = m
)
}
}
module IterationCountFlow = TaintTracking::Global<IterationCountConfig>;
import IterationCountFlow::PathGraph
from
Crypto::KeyDerivationOperationNode op, Literal l, IterationCountFlow::PathNode srcNode,
IterationCountFlow::PathNode sinkNode
where
op.getIterationCount().asElement() = l and
l.getValue().toInt() < 100000 and
srcNode.getNode().asExpr() = l and
sinkNode.getNode() = op.getIterationCountConsumer().getConsumer().getInputNode() and
IterationCountFlow::flowPath(srcNode, sinkNode)
select sinkNode, srcNode, sinkNode,
"Key derivation operation configures iteration count below 100k: $@", l, l.getValue().toString()