Skip to content

Commit c115169

Browse files
committed
Rust: Move ModelledHashOperation to a more logical location.
1 parent ae26cd6 commit c115169

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

rust/ql/lib/codeql/rust/frameworks/rustcrypto/RustCrypto.qll

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
private import rust
66
private import codeql.rust.Concepts
77
private import codeql.rust.dataflow.DataFlow
8-
private import codeql.rust.dataflow.FlowSource
9-
private import codeql.rust.dataflow.FlowSink
10-
private import codeql.rust.dataflow.internal.DataFlowImpl
118

129
bindingset[algorithmName]
1310
private string simplifyAlgorithmName(string algorithmName) {
@@ -58,28 +55,3 @@ class StreamCipherInit extends Cryptography::CryptographicOperation::Range {
5855

5956
override Cryptography::BlockMode getBlockMode() { result = "" }
6057
}
61-
62-
/**
63-
* An externally modelled operation that hashes data, for example a call to `md5::Md5::digest(data)`.
64-
*/
65-
class ModelledHashOperation extends Cryptography::CryptographicOperation::Range {
66-
DataFlow::Node input;
67-
CallExpr call;
68-
string algorithmName;
69-
70-
ModelledHashOperation() {
71-
sinkNode(input, "hasher-input") and
72-
call = input.(Node::FlowSummaryNode).getSinkElement().getCall() and
73-
call = this.asExpr().getExpr() and
74-
algorithmName =
75-
call.getFunction().(PathExpr).getPath().getQualifier().getPart().getNameRef().getText()
76-
}
77-
78-
override DataFlow::Node getInitialization() { result = this }
79-
80-
override Cryptography::CryptographicAlgorithm getAlgorithm() { result.matchesName(algorithmName) }
81-
82-
override DataFlow::Node getAnInput() { result = input }
83-
84-
override Cryptography::BlockMode getBlockMode() { none() } // (does not apply for hashing)
85-
}

rust/ql/lib/codeql/rust/security/WeakSensitiveDataHashingExtensions.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import rust
1212
private import codeql.rust.Concepts
1313
private import codeql.rust.security.SensitiveData
1414
private import codeql.rust.dataflow.DataFlow
15+
private import codeql.rust.dataflow.FlowSource
16+
private import codeql.rust.dataflow.FlowSink
17+
private import codeql.rust.dataflow.internal.DataFlowImpl
1518

1619
/**
1720
* Provides default sources, sinks and sanitizers for detecting "use of a broken or weak
@@ -169,3 +172,28 @@ module ComputationallyExpensiveHashFunction {
169172
}
170173
}
171174
}
175+
176+
/**
177+
* An externally modelled operation that hashes data, for example a call to `md5::Md5::digest(data)`.
178+
*/
179+
class ModelledHashOperation extends Cryptography::CryptographicOperation::Range {
180+
DataFlow::Node input;
181+
CallExpr call;
182+
string algorithmName;
183+
184+
ModelledHashOperation() {
185+
sinkNode(input, "hasher-input") and
186+
call = input.(Node::FlowSummaryNode).getSinkElement().getCall() and
187+
call = this.asExpr().getExpr() and
188+
algorithmName =
189+
call.getFunction().(PathExpr).getPath().getQualifier().getPart().getNameRef().getText()
190+
}
191+
192+
override DataFlow::Node getInitialization() { result = this }
193+
194+
override Cryptography::CryptographicAlgorithm getAlgorithm() { result.matchesName(algorithmName) }
195+
196+
override DataFlow::Node getAnInput() { result = input }
197+
198+
override Cryptography::BlockMode getBlockMode() { none() } // (does not apply for hashing)
199+
}

0 commit comments

Comments
 (0)