Rewrite handling of known unknowns and data-flow

This commit is contained in:
Nicolas Will
2025-02-27 05:42:02 +01:00
parent f55f27b0d9
commit 04f4683399
5 changed files with 864 additions and 718 deletions

View File

@@ -6,18 +6,16 @@
import experimental.Quantum.Language
import semmle.code.java.dataflow.DataFlow
Element getNonceOrigin(Crypto::NonceArtifactInstance nonce) {
Crypto::NodeBase getNonceOrigin(Crypto::NonceNode nonce) {
// TODO: this check is currently ultra hacky just for demoing
result = nonce.getInput().asExpr().(VarAccess).getVariable()
result = nonce.getSourceNode()
}
from
Crypto::CipherOperationInstance op, Crypto::NonceArtifactInstance nonce1,
Crypto::NonceArtifactInstance nonce2
from Crypto::CipherOperationNode op, Crypto::NonceNode nonce1, Crypto::NonceNode nonce2
where
op.(Expr).getEnclosingCallable().getName() = "encrypt" and
nonce1 = op.getNonce() and
nonce2 = op.getNonce() and
op.asElement().(Expr).getEnclosingCallable().getName() = "encrypt" and
nonce1 = op.getANonce() and
nonce2 = op.getANonce() and
not nonce1 = nonce2 and
getNonceOrigin(nonce1) = getNonceOrigin(nonce2)
select op, nonce1, nonce2

View File

@@ -5,12 +5,12 @@
import experimental.Quantum.Language
from
Crypto::CipherOperation op, Crypto::CipherAlgorithm a, Crypto::ModeOfOperationAlgorithm m,
Crypto::PaddingAlgorithm p, Crypto::Nonce nonce
Crypto::CipherOperationNode op, Crypto::CipherAlgorithmNode a,
Crypto::ModeOfOperationAlgorithmNode m, Crypto::PaddingAlgorithmNode p, Crypto::NonceNode nonce
where
a = op.getAlgorithm() and
a = op.getAKnownCipherAlgorithm() and
m = a.getModeOfOperation() and
p = a.getPadding() and
nonce = op.getNonce()
select op, op.getCipherOperationMode(), a, a.getRawAlgorithmName(), m, m.getRawAlgorithmName(), p,
p.getRawAlgorithmName(), nonce
p = a.getPaddingAlgorithm() and
nonce = op.getANonce()
select op, op.getCipherOperationSubtype(), a, a.getRawAlgorithmName(), m, m.getRawAlgorithmName(),
p, p.getRawAlgorithmName(), nonce