11private import codeql.cryptography.Model
22import semmle.code.cpp.ir.IR
33import semmle.code.cpp.security.FlowSources as FlowSources
4+ import semmle.code.cpp.dataflow.new.DataFlow
45private import cpp as Lang
56
67module CryptoInput implements InputSig< Lang:: Location > {
@@ -15,10 +16,44 @@ module CryptoInput implements InputSig<Lang::Location> {
1516 result = node .asParameter ( ) or
1617 result = node .asVariable ( )
1718 }
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+ }
1829}
1930
2031module Crypto = CryptographyBase< Lang:: Location , CryptoInput > ;
2132
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+
2257/**
2358 * Artifact output to node input configuration
2459 */
@@ -31,9 +66,9 @@ abstract class AdditionalFlowInputStep extends DataFlow::Node {
3166/**
3267 * Generic data source to node input configuration
3368 */
34- module GenericDataSourceUniversalFlowConfig implements DataFlow:: ConfigSig {
69+ module GenericDataSourceFlowConfig implements DataFlow:: ConfigSig {
3570 predicate isSource ( DataFlow:: Node source ) {
36- source = any ( Crypto:: GenericDataSourceInstance i ) .getOutputNode ( )
71+ source = any ( Crypto:: GenericSourceInstance i ) .getOutputNode ( )
3772 }
3873
3974 predicate isSink ( DataFlow:: Node sink ) {
@@ -53,41 +88,6 @@ module GenericDataSourceUniversalFlowConfig implements DataFlow::ConfigSig {
5388 }
5489}
5590
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>;
9191module ArtifactUniversalFlowConfig implements DataFlow:: ConfigSig {
9292 predicate isSource ( DataFlow:: Node source ) {
9393 source = any ( Crypto:: ArtifactInstance artifact ) .getOutputNode ( )
@@ -112,10 +112,12 @@ module ArtifactUniversalFlowConfig implements DataFlow::ConfigSig {
112112
113113module ArtifactUniversalFlow = DataFlow:: Global< ArtifactUniversalFlowConfig > ;
114114
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+ // // }
121123import OpenSSL.OpenSSL
0 commit comments