|
6 | 6 | * is any static nonce, or any known insecure source for a nonce/iv if |
7 | 7 | * the value is used for an encryption operation (decryption operations are ignored |
8 | 8 | * as the nonce/iv would be provided alongside the ciphertext). |
9 | | - * @kind problem |
| 9 | + * @kind path-problem |
10 | 10 | * @problem.severity error |
11 | 11 | * @precision high |
12 | 12 | * @tags quantum |
|
15 | 15 |
|
16 | 16 | import experimental.quantum.Language |
17 | 17 |
|
18 | | -from Crypto::NonceArtifactNode nonce, Crypto::NodeBase src, Crypto::NodeBase op, string msg |
| 18 | +module NonceSrcFlowConfig implements DataFlow::ConfigSig { |
| 19 | + predicate isSource(DataFlow::Node source) { |
| 20 | + source = any(Crypto::GenericSourceInstance i).getOutputNode() or |
| 21 | + source = any(Crypto::ArtifactInstance artifact).getOutputNode() |
| 22 | + } |
| 23 | + |
| 24 | + predicate isSink(DataFlow::Node sink) { |
| 25 | + exists(Crypto::NonceArtifactNode nonce | sink.asExpr() = nonce.asElement()) |
| 26 | + } |
| 27 | + |
| 28 | + predicate isBarrierOut(DataFlow::Node node) { |
| 29 | + node = any(Crypto::FlowAwareElement element).getInputNode() |
| 30 | + } |
| 31 | + |
| 32 | + predicate isBarrierIn(DataFlow::Node node) { |
| 33 | + node = any(Crypto::FlowAwareElement element).getOutputNode() |
| 34 | + } |
| 35 | + |
| 36 | + predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 37 | + node1.(AdditionalFlowInputStep).getOutput() = node2 |
| 38 | + or |
| 39 | + exists(MethodCall m | |
| 40 | + m.getMethod().hasQualifiedName("java.lang", "String", "getBytes") and |
| 41 | + node1.asExpr() = m.getQualifier() and |
| 42 | + node2.asExpr() = m |
| 43 | + ) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +module NonceSrcFlow = TaintTracking::Global<NonceSrcFlowConfig>; |
| 48 | + |
| 49 | +import NonceSrcFlow::PathGraph |
| 50 | + |
| 51 | +from |
| 52 | + Crypto::NonceArtifactNode nonce, Crypto::NodeBase src, Crypto::NodeBase op, string msg, |
| 53 | + NonceSrcFlow::PathNode srcNode, NonceSrcFlow::PathNode sinkNode |
19 | 54 | where |
20 | 55 | nonce.getSourceNode() = src and |
21 | 56 | // NOTE: null nonces should be handled seaparately, often used for default values prior to initialization |
|
25 | 60 | ( |
26 | 61 | // Case 1: Any constant nonce/iv is bad, regardless of how it is used |
27 | 62 | src.asElement() instanceof Crypto::GenericConstantSourceInstance and |
28 | | - op = nonce and // binding op by not using it |
| 63 | + op = nonce and // binding op but not using it |
29 | 64 | msg = "Nonce or IV uses constant source $@" |
30 | 65 | or |
31 | 66 | // Case 2: The nonce has a non-random source and there is no known operation for the nonce |
|
47 | 82 | op.(Crypto::CipherOperationNode).getKeyOperationSubtype() instanceof Crypto::TWrapMode |
48 | 83 | ) and |
49 | 84 | msg = "Nonce or IV uses insecure source $@ at encryption operation $@" |
50 | | - ) |
51 | | -select nonce, msg, src, src.toString(), op, op.toString() |
| 85 | + ) and |
| 86 | + srcNode.getNode().asExpr() = src.asElement() and |
| 87 | + sinkNode.getNode().asExpr() = nonce.asElement() and |
| 88 | + NonceSrcFlow::flowPath(srcNode, sinkNode) |
| 89 | +select sinkNode, srcNode, sinkNode, msg, src, src.toString(), op, op.toString() |
0 commit comments