|
2 | 2 | * @name Weak known key derivation function iteration count |
3 | 3 | * @description Detects key derivation operations with a known weak iteration count. |
4 | 4 | * @id java/quantum/weak-kdf-iteration-count |
5 | | - * @kind problem |
| 5 | + * @kind path-problem |
6 | 6 | * @problem.severity error |
7 | 7 | * @precision high |
8 | 8 | * @tags quantum |
|
12 | 12 | import java |
13 | 13 | import experimental.quantum.Language |
14 | 14 |
|
15 | | -from Crypto::KeyDerivationOperationNode op, Literal l |
| 15 | +module IterationCountConfig implements DataFlow::ConfigSig { |
| 16 | + predicate isSource(DataFlow::Node source) { |
| 17 | + source = any(Crypto::GenericSourceInstance i).getOutputNode() or |
| 18 | + source = any(Crypto::ArtifactInstance artifact).getOutputNode() |
| 19 | + } |
| 20 | + |
| 21 | + predicate isSink(DataFlow::Node sink) { |
| 22 | + exists(Crypto::KeyDerivationOperationInstance kdev | |
| 23 | + sink = kdev.getIterationCountConsumer().getConsumer().getInputNode() |
| 24 | + ) |
| 25 | + } |
| 26 | + |
| 27 | + predicate isBarrierOut(DataFlow::Node node) { |
| 28 | + node = any(Crypto::FlowAwareElement element).getInputNode() |
| 29 | + } |
| 30 | + |
| 31 | + predicate isBarrierIn(DataFlow::Node node) { |
| 32 | + node = any(Crypto::FlowAwareElement element).getOutputNode() |
| 33 | + } |
| 34 | + |
| 35 | + predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 36 | + node1.(AdditionalFlowInputStep).getOutput() = node2 |
| 37 | + or |
| 38 | + exists(MethodCall m | |
| 39 | + m.getMethod().hasQualifiedName("java.lang", "String", "getBytes") and |
| 40 | + node1.asExpr() = m.getQualifier() and |
| 41 | + node2.asExpr() = m |
| 42 | + ) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +module IterationCountFlow = TaintTracking::Global<IterationCountConfig>; |
| 47 | + |
| 48 | +import IterationCountFlow::PathGraph |
| 49 | + |
| 50 | +from |
| 51 | + Crypto::KeyDerivationOperationNode op, Literal l, IterationCountFlow::PathNode srcNode, |
| 52 | + IterationCountFlow::PathNode sinkNode |
16 | 53 | where |
17 | 54 | op.getIterationCount().asElement() = l and |
18 | | - l.getValue().toInt() < 100000 |
19 | | -select op, "Key derivation operation configures iteration count below 100k: $@", l, |
20 | | - l.getValue().toString() |
| 55 | + l.getValue().toInt() < 100000 and |
| 56 | + srcNode.getNode().asExpr() = l and |
| 57 | + sinkNode.getNode() = op.getIterationCountConsumer().getConsumer().getInputNode() and |
| 58 | + IterationCountFlow::flowPath(srcNode, sinkNode) |
| 59 | +select sinkNode, srcNode, sinkNode, |
| 60 | + "Key derivation operation configures iteration count below 100k: $@", l, l.getValue().toString() |
0 commit comments