Skip to content

Commit 2b1b90c

Browse files
authored
Merge pull request #4 from nicolaswill/brodes/cipher_operation
Adding a sketch for a CipherOperation concept to model encryption/dec…
2 parents 3871c6a + dd2f53f commit 2b1b90c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+8315
-1079
lines changed
Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,121 @@
11
private import codeql.cryptography.Model
2+
import semmle.code.cpp.ir.IR
3+
import semmle.code.cpp.security.FlowSources as FlowSources
24
private import cpp as Lang
35

46
module CryptoInput implements InputSig<Lang::Location> {
7+
class DataFlowNode = DataFlow::Node;
8+
59
class LocatableElement = Lang::Locatable;
610

711
class UnknownLocation = Lang::UnknownDefaultLocation;
12+
13+
LocatableElement dfn_to_element(DataFlow::Node node) {
14+
result = node.asExpr() or
15+
result = node.asParameter() or
16+
result = node.asVariable()
17+
}
818
}
919

1020
module Crypto = CryptographyBase<Lang::Location, CryptoInput>;
1121

12-
import OpenSSL
22+
/**
23+
* Artifact output to node input configuration
24+
*/
25+
abstract class AdditionalFlowInputStep extends DataFlow::Node {
26+
abstract DataFlow::Node getOutput();
27+
28+
final DataFlow::Node getInput() { result = this }
29+
}
30+
31+
/**
32+
* Generic data source to node input configuration
33+
*/
34+
module GenericDataSourceUniversalFlowConfig implements DataFlow::ConfigSig {
35+
predicate isSource(DataFlow::Node source) {
36+
source = any(Crypto::GenericDataSourceInstance i).getOutputNode()
37+
}
38+
39+
predicate isSink(DataFlow::Node sink) {
40+
sink = any(Crypto::FlowAwareElement other).getInputNode()
41+
}
42+
43+
predicate isBarrierOut(DataFlow::Node node) {
44+
node = any(Crypto::FlowAwareElement element).getInputNode()
45+
}
46+
47+
predicate isBarrierIn(DataFlow::Node node) {
48+
node = any(Crypto::FlowAwareElement element).getOutputNode()
49+
}
50+
51+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
52+
node1.(AdditionalFlowInputStep).getOutput() = node2
53+
}
54+
}
55+
56+
// // // TODO: I think this will be inefficient, no?
57+
// // class ConstantDataSource extends Crypto::GenericConstantOrAllocationSource instanceof Literal {
58+
// // override DataFlow::Node getOutputNode() {
59+
// // result.asExpr() = this
60+
// // }
61+
// // override predicate flowsTo(Crypto::FlowAwareElement other) {
62+
// // // TODO: separate config to avoid blowing up data-flow analysis
63+
// // GenericDataSourceUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
64+
// // }
65+
// // override string getAdditionalDescription() { result = this.toString() }
66+
// // }
67+
// /**
68+
// * Definitions of various generic data sources
69+
// */
70+
// // final class DefaultFlowSource = SourceNode;
71+
// // final class DefaultRemoteFlowSource = RemoteFlowSource;
72+
// // class GenericLocalDataSource extends Crypto::GenericLocalDataSource {
73+
// // GenericLocalDataSource() {
74+
// // any(DefaultFlowSource src | not src instanceof DefaultRemoteFlowSource).asExpr() = this
75+
// // }
76+
// // override DataFlow::Node getOutputNode() { result.asExpr() = this }
77+
// // override predicate flowsTo(Crypto::FlowAwareElement other) {
78+
// // GenericDataSourceUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
79+
// // }
80+
// // override string getAdditionalDescription() { result = this.toString() }
81+
// // }
82+
// // class GenericRemoteDataSource extends Crypto::GenericRemoteDataSource {
83+
// // GenericRemoteDataSource() { any(DefaultRemoteFlowSource src).asExpr() = this }
84+
// // override DataFlow::Node getOutputNode() { result.asExpr() = this }
85+
// // override predicate flowsTo(Crypto::FlowAwareElement other) {
86+
// // GenericDataSourceUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
87+
// // }
88+
// // override string getAdditionalDescription() { result = this.toString() }
89+
// // }
90+
// module GenericDataSourceUniversalFlow = DataFlow::Global<GenericDataSourceUniversalFlowConfig>;
91+
module ArtifactUniversalFlowConfig implements DataFlow::ConfigSig {
92+
predicate isSource(DataFlow::Node source) {
93+
source = any(Crypto::ArtifactInstance artifact).getOutputNode()
94+
}
95+
96+
predicate isSink(DataFlow::Node sink) {
97+
sink = any(Crypto::FlowAwareElement other).getInputNode()
98+
}
99+
100+
predicate isBarrierOut(DataFlow::Node node) {
101+
node = any(Crypto::FlowAwareElement element).getInputNode()
102+
}
103+
104+
predicate isBarrierIn(DataFlow::Node node) {
105+
node = any(Crypto::FlowAwareElement element).getOutputNode()
106+
}
107+
108+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
109+
node1.(AdditionalFlowInputStep).getOutput() = node2
110+
}
111+
}
112+
113+
module ArtifactUniversalFlow = DataFlow::Global<ArtifactUniversalFlowConfig>;
114+
115+
abstract class CipherOutputArtifact extends Crypto::KeyOperationOutputArtifactInstance {
116+
override predicate flowsTo(Crypto::FlowAwareElement other) {
117+
ArtifactUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
118+
}
119+
}
120+
121+
import OpenSSL.OpenSSL

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

Lines changed: 0 additions & 244 deletions
This file was deleted.

0 commit comments

Comments
 (0)