1
1
private import codeql.cryptography.Model
2
2
import semmle.code.cpp.ir.IR
3
3
import semmle.code.cpp.security.FlowSources as FlowSources
4
+ import semmle.code.cpp.dataflow.new.DataFlow
4
5
private import cpp as Lang
5
6
6
7
module CryptoInput implements InputSig< Lang:: Location > {
@@ -15,10 +16,44 @@ module CryptoInput implements InputSig<Lang::Location> {
15
16
result = node .asParameter ( ) or
16
17
result = node .asVariable ( )
17
18
}
19
+
20
+ string locationToFileBaseNameAndLineNumberString ( Location location ) {
21
+ result = location .getFile ( ) .getBaseName ( ) + ":" + location .getStartLine ( )
22
+ }
23
+
24
+ predicate artifactOutputFlowsToGenericInput (
25
+ DataFlow:: Node artifactOutput , DataFlow:: Node otherInput
26
+ ) {
27
+ ArtifactFlow:: flow ( artifactOutput , otherInput )
28
+ }
18
29
}
19
30
20
31
module Crypto = CryptographyBase< Lang:: Location , CryptoInput > ;
21
32
33
+ module ArtifactFlowConfig implements DataFlow:: ConfigSig {
34
+ predicate isSource ( DataFlow:: Node source ) {
35
+ source = any ( Crypto:: ArtifactInstance artifact ) .getOutputNode ( )
36
+ }
37
+
38
+ predicate isSink ( DataFlow:: Node sink ) {
39
+ sink = any ( Crypto:: FlowAwareElement other ) .getInputNode ( )
40
+ }
41
+
42
+ predicate isBarrierOut ( DataFlow:: Node node ) {
43
+ node = any ( Crypto:: FlowAwareElement element ) .getInputNode ( )
44
+ }
45
+
46
+ predicate isBarrierIn ( DataFlow:: Node node ) {
47
+ node = any ( Crypto:: FlowAwareElement element ) .getOutputNode ( )
48
+ }
49
+
50
+ predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
51
+ node1 .( AdditionalFlowInputStep ) .getOutput ( ) = node2
52
+ }
53
+ }
54
+
55
+ module ArtifactFlow = DataFlow:: Global< ArtifactFlowConfig > ;
56
+
22
57
/**
23
58
* Artifact output to node input configuration
24
59
*/
@@ -31,9 +66,9 @@ abstract class AdditionalFlowInputStep extends DataFlow::Node {
31
66
/**
32
67
* Generic data source to node input configuration
33
68
*/
34
- module GenericDataSourceUniversalFlowConfig implements DataFlow:: ConfigSig {
69
+ module GenericDataSourceFlowConfig implements DataFlow:: ConfigSig {
35
70
predicate isSource ( DataFlow:: Node source ) {
36
- source = any ( Crypto:: GenericDataSourceInstance i ) .getOutputNode ( )
71
+ source = any ( Crypto:: GenericSourceInstance i ) .getOutputNode ( )
37
72
}
38
73
39
74
predicate isSink ( DataFlow:: Node sink ) {
@@ -53,41 +88,6 @@ module GenericDataSourceUniversalFlowConfig implements DataFlow::ConfigSig {
53
88
}
54
89
}
55
90
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
91
module ArtifactUniversalFlowConfig implements DataFlow:: ConfigSig {
92
92
predicate isSource ( DataFlow:: Node source ) {
93
93
source = any ( Crypto:: ArtifactInstance artifact ) .getOutputNode ( )
@@ -112,10 +112,12 @@ module ArtifactUniversalFlowConfig implements DataFlow::ConfigSig {
112
112
113
113
module ArtifactUniversalFlow = DataFlow:: Global< ArtifactUniversalFlowConfig > ;
114
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
-
115
+ // abstract class CipherOutputArtifact extends Crypto::KeyOperationOutputArtifactInstance {
116
+ // override predicate flowsTo(Crypto::FlowAwareElement other) {
117
+ // ArtifactUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
118
+ // }
119
+ // }
120
+ // // final override predicate flowsTo(FlowAwareElement other) {
121
+ // // Input::artifactOutputFlowsToGenericInput(this.getOutputNode(), other.getInputNode())
122
+ // // }
121
123
import OpenSSL.OpenSSL
0 commit comments