Skip to content

Commit 9cc121f

Browse files
authored
Merge pull request #19545 from bdrodes/missing_openssl_hash_algorithm_consumers
Quantum: Model missing OpenSSL EVP digest consumers
2 parents 9637aec + acb1962 commit 9cc121f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/DirectAlgorithmValueConsumer.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ private import experimental.quantum.Language
33
private import experimental.quantum.OpenSSL.AlgorithmInstances.KnownAlgorithmConstants
44
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase
55

6-
// TODO: can self referential to itself, which is also an algorithm (Known algorithm)
76
/**
87
* Cases like EVP_MD5(),
98
* there is no input, rather it directly gets an algorithm

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/HashAlgorithmValueConsumer.qll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,34 @@ class EVP_Q_Digest_Algorithm_Consumer extends OpenSSLAlgorithmValueConsumer {
3030
none()
3131
}
3232
}
33+
34+
/**
35+
* The EVP digest algorithm getters
36+
* https://docs.openssl.org/3.0/man3/EVP_DigestInit/#synopsis
37+
*/
38+
class EVPDigestAlgorithmValueConsumer extends OpenSSLAlgorithmValueConsumer {
39+
DataFlow::Node valueArgNode;
40+
DataFlow::Node resultNode;
41+
42+
EVPDigestAlgorithmValueConsumer() {
43+
resultNode.asExpr() = this and
44+
isPossibleOpenSSLFunction(this.(Call).getTarget()) and
45+
(
46+
this.(Call).getTarget().getName() in [
47+
"EVP_get_digestbyname", "EVP_get_digestbynid", "EVP_get_digestbyobj"
48+
] and
49+
valueArgNode.asExpr() = this.(Call).getArgument(0)
50+
or
51+
this.(Call).getTarget().getName() = "EVP_MD_fetch" and
52+
valueArgNode.asExpr() = this.(Call).getArgument(1)
53+
)
54+
}
55+
56+
override DataFlow::Node getResultNode() { result = resultNode }
57+
58+
override Crypto::ConsumerInputDataFlowNode getInputNode() { result = valueArgNode }
59+
60+
override Crypto::AlgorithmInstance getAKnownAlgorithmSource() {
61+
exists(OpenSSLAlgorithmInstance i | i.getAVC() = this and result = i)
62+
}
63+
}

0 commit comments

Comments
 (0)