Skip to content

Commit 6083df2

Browse files
committed
Completed tying algorithm instances to consumers. Now the model should have known literals for cipher instances, and it traces those instances to consumers (inits) and those inits are traced to cipher operations.
1 parent de3ff45 commit 6083df2

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

cpp/ql/lib/experimental/Quantum/OpenSSL/EVPCipherAlgorithmSource.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ predicate literalToCipherFamilyType(Literal e, Crypto::TCipherType type) {
5252
)
5353
}
5454

55+
5556
class CipherKnownAlgorithmLiteralAlgorithmInstance extends Crypto::CipherAlgorithmInstance instanceof Literal
5657
{
58+
OpenSSLAlgorithmGetterCall cipherGetterCall;
5759
CipherKnownAlgorithmLiteralAlgorithmInstance() {
58-
exists(EVPCipherGetterCall c, DataFlow::Node src, DataFlow::Node sink |
59-
sink = c.getValueArgNode() and
60+
exists(DataFlow::Node src, DataFlow::Node sink |
61+
sink = cipherGetterCall.getValueArgNode() and
6062
src.asExpr() = this and
6163
KnownAlgorithmLiteralToAlgorithmGetterFlow::flow(src, sink) and
6264
// Not just any known value, but specifically a known cipher operation
@@ -67,7 +69,9 @@ class CipherKnownAlgorithmLiteralAlgorithmInstance extends Crypto::CipherAlgorit
6769
)
6870
}
6971

70-
Crypto::AlgorithmConsumer getConsumer() { none() } //result = consumer }
72+
Crypto::AlgorithmConsumer getConsumer() {
73+
AlgGetterToAlgConsumerFlow::flow(cipherGetterCall.getResultNode(), DataFlow::exprNode(result))
74+
}
7175

7276
override Crypto::ModeOfOperationAlgorithmInstance getModeOfOperationAlgorithm() {
7377
none() // TODO: provider defaults

cpp/ql/lib/experimental/Quantum/OpenSSL/OpenSSLAlgorithmGetter.qll

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import cpp
22
import semmle.code.cpp.dataflow.new.DataFlow
33
import LibraryDetector
44
import OpenSSLKnownAlgorithmConstants
5+
import experimental.Quantum.Language
6+
7+
module AlgGetterToAlgConsumerConfig implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node source) {
9+
exists(OpenSSLAlgorithmGetterCall c | c.getResultNode() = source)
10+
}
11+
12+
predicate isSink(DataFlow::Node sink) {
13+
exists(Crypto::AlgorithmConsumer c | c.getInputNode() = sink)
14+
}
15+
}
16+
17+
module AlgGetterToAlgConsumerFlow = DataFlow::Global<AlgGetterToAlgConsumerConfig>;
518

619
abstract class AlgorithmPassthroughCall extends Call {
720
abstract DataFlow::Node getInNode();
@@ -116,14 +129,7 @@ abstract class OpenSSLAlgorithmGetterCall extends Call {
116129
}
117130

118131
module KnownAlgorithmLiteralToAlgorithmGetterConfig implements DataFlow::ConfigSig {
119-
predicate isSource(DataFlow::Node source) {
120-
(
121-
source.asExpr() instanceof Literal and
122-
// 0 sources, for nid are unknown, and 0 otherwise represents a null assignment (ignore as unknown)
123-
exists(source.asExpr().(Literal).getValue().toInt()) implies source.asExpr().(Literal).getValue().toInt() != 0
124-
//resolveAlgorithmFromLiteral(source.asExpr(),_,_)
125-
)
126-
}
132+
predicate isSource(DataFlow::Node source) { resolveAlgorithmFromLiteral(source.asExpr(), _, _) }
127133

128134
predicate isSink(DataFlow::Node sink) {
129135
exists(OpenSSLAlgorithmGetterCall c | c.getValueArgNode() = sink)

0 commit comments

Comments
 (0)