Skip to content

Commit 40423da

Browse files
GrosQuildumschwager
authored andcommitted
start fixing in MsgNotHashedBeforeSigVerfication
1 parent 23da6f6 commit 40423da

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

go/src/crypto/MsgNotHashedBeforeSigVerfication/MsgNotHashedBeforeSigVerfication.ql

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
*/
1212

1313
import go
14-
import DataFlow::PathGraph
15-
import semmle.go.dataflow.DataFlow2
1614

1715
/**
1816
* Function that performs signing or signature verification on a hash of a message
@@ -90,27 +88,25 @@ class HashFunction extends Function {
9088
}
9189
}
9290

93-
class LongestFlowConfig extends DataFlow2::Configuration {
94-
LongestFlowConfig() { this = "LongestFlowConfig" }
95-
override predicate isSource(DataFlow::Node source) { source = source }
96-
override predicate isSink(DataFlow::Node sink) { sink = sink }
91+
private module LongestFlowConfig implements DataFlow::ConfigSig {
92+
predicate isSource(DataFlow::Node source) { source = source }
93+
predicate isSink(DataFlow::Node sink) { sink = sink }
9794
}
95+
module LongestFlowFlow = TaintTracking::Global<LongestFlowConfig>;
9896

9997
/**
10098
* Flows from anything to SignatureMsgTruncationFunction
10199
* that do not cross a hash function or slicing expression
102100
*/
103-
class AnythingToSignatureMsgTrunFuncFlow extends DataFlow::Configuration {
104-
AnythingToSignatureMsgTrunFuncFlow() { this = "AnythingToSignatureMsgTrunFuncFlow" }
105-
101+
module AnythingToSignatureMsgTrunFuncConfig implements DataFlow::ConfigSig {
106102
// anything that is not a function's argument
107103
// TODO: alternatively, set sources to be ExternalInputs
108-
override predicate isSource(DataFlow::Node source) {
109-
not this.isSink(source, _)
104+
predicate isSource(DataFlow::Node source) {
105+
not isSink(source)
110106
and not source.asInstruction() instanceof IR::ReadArgumentInstruction
111107
}
112108

113-
override predicate isSink(DataFlow::Node sink) {
109+
predicate isSink(DataFlow::Node sink) {
114110
exists(SignatureMsgTruncationFunction sigUseF, CallExpr sigUseCall, int position |
115111
sigUseCall.getTarget() = sigUseF
116112
and sigUseF.hashArgPosition(position)
@@ -122,7 +118,7 @@ class AnythingToSignatureMsgTrunFuncFlow extends DataFlow::Configuration {
122118
// * data goes through a hash function
123119
// * data is truncated with a hardcoded value
124120
// * TODO: data is of type Hash
125-
override predicate isBarrier(DataFlow::Node node) {
121+
predicate isBarrier(DataFlow::Node node) {
126122
// direct hash function call
127123
exists(HashFunction hf | hf.getACall().getResult(_) = node or hf.getACall().getArgument(_) = node)
128124
or
@@ -142,14 +138,15 @@ class AnythingToSignatureMsgTrunFuncFlow extends DataFlow::Configuration {
142138
node.asExpr().getType().getUnderlyingType().(ArrayType).getLength() <= 66
143139
}
144140
}
141+
module AnythingToSignatureMsgTrunFuncFlow = TaintTracking::Global<AnythingToSignatureMsgTrunFuncConfig>;
145142

146-
from AnythingToSignatureMsgTrunFuncFlow config, DataFlow::PathNode source, DataFlow::PathNode sink
143+
from AnythingToSignatureMsgTrunFuncFlow::PathNode source, AnythingToSignatureMsgTrunFuncFlow::PathNode sink
147144
where
148-
config.hasFlowPath(source, sink)
145+
AnythingToSignatureMsgTrunFuncFlow::flowPath(source, sink)
149146

150147
// only the longest flow
151-
and not exists(LongestFlowConfig config2, DataFlow::Node source2 |
152-
config2.hasFlow(source2, source.getNode())
148+
and not exists(DataFlow::Node source2 |
149+
LongestFlowFlow::flow(source2, source.getNode())
153150
and source2 != source.getNode()
154151
)
155152

0 commit comments

Comments
 (0)