Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 7f980a4

Browse files
author
dilanbhalla
committed
pr fixes
1 parent 40d3f22 commit 7f980a4

File tree

2 files changed

+27
-43
lines changed

2 files changed

+27
-43
lines changed

ql/src/experimental/CWE-327/CryptoLibraries.qll

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
127127
bindingset[name]
128128
predicate matchesName(string name) {
129129
exists(name.regexpReplaceAll("[-_]", "").regexpFind("(?i)\\Q" + getName() + "\\E", _, _))
130-
// name.toUpperCase().regexpReplaceAll("[-_ ]", "").regexpMatch(".*" + getName() + ".*")
131130
}
132131

133132
/**
@@ -194,70 +193,53 @@ abstract class CryptographicOperation extends DataFlow::Node {
194193
}
195194

196195
/**
197-
* Below are the cryptographic functions that have been implemented so far for this library.
198-
* Class that checks for use of Md5 package.
196+
* Models cryptographic operations of the `crypto/md5` package.
199197
*/
200198
class Md5 extends CryptographicOperation, DataFlow::CallNode {
201-
Expr input;
202-
CryptographicAlgorithm algorithm;
199+
Md5() { getTarget().hasQualifiedName("crypto/md5", ["New", "Sum"]) }
203200

204-
Md5() {
205-
getTarget().hasQualifiedName("crypto/md5", ["New", "Sum"]) and
206-
this.getArgument(0).asExpr() = input
207-
}
208-
209-
override Expr getInput() { result = input }
201+
override Expr getInput() { result = this.getArgument(0).asExpr() }
210202

211-
override CryptographicAlgorithm getAlgorithm() { result = algorithm }
203+
override CryptographicAlgorithm getAlgorithm() {
204+
result.matchesName(this.getTarget().getPackage().getName())
205+
}
212206
}
213207

214208
/**
215-
* Class that checks for use of Sha1 package.
209+
* Models cryptographic operations of the `crypto/sha1` package.
216210
*/
217211
class Sha1 extends CryptographicOperation, DataFlow::CallNode {
218-
Expr input;
219-
CryptographicAlgorithm algorithm;
212+
Sha1() { getTarget().hasQualifiedName("crypto/sha1", ["New", "Sum"]) }
220213

221-
Sha1() {
222-
getTarget().hasQualifiedName("crypto/sha1", ["New", "Sum"]) and
223-
this.getArgument(0).asExpr() = input
224-
}
225-
226-
override Expr getInput() { result = input }
214+
override Expr getInput() { result = this.getArgument(0).asExpr() }
227215

228-
override CryptographicAlgorithm getAlgorithm() { result = algorithm }
216+
override CryptographicAlgorithm getAlgorithm() {
217+
result.matchesName(this.getTarget().getPackage().getName())
218+
}
229219
}
230220

231221
/**
232-
* Class that checks for use of Des package.
222+
* Models cryptographic operations of the `crypto/des` package.
233223
*/
234224
class Des extends CryptographicOperation, DataFlow::CallNode {
235-
Expr input;
236-
CryptographicAlgorithm algorithm;
225+
Des() { getTarget().hasQualifiedName("crypto/des", ["NewCipher", "NewTripleDESCipher"]) }
237226

238-
Des() {
239-
getTarget().hasQualifiedName("crypto/des", ["NewCipher", "NewTripleDESCipher"]) and
240-
this.getArgument(0).asExpr() = input
241-
}
242-
243-
override Expr getInput() { result = input }
227+
override Expr getInput() { result = this.getArgument(0).asExpr() }
244228

245-
override CryptographicAlgorithm getAlgorithm() { result = algorithm }
229+
override CryptographicAlgorithm getAlgorithm() {
230+
result.matchesName(this.getTarget().getPackage().getName())
231+
}
246232
}
247233

248234
/**
249-
* Class that checks for use of Rc4 package.
235+
* Models cryptographic operations of the `crypto/rc4` package.
250236
*/
251237
class Rc4 extends CryptographicOperation, DataFlow::CallNode {
252-
Expr input;
253-
CryptographicAlgorithm algorithm;
238+
Rc4() { getTarget().hasQualifiedName("crypto/rc4", ["NewCipher"]) }
254239

255-
Rc4() {
256-
getTarget().hasQualifiedName("crypto/rc4", ["NewCipher"]) and
257-
this.getArgument(0).asExpr() = input
258-
}
259-
260-
override Expr getInput() { result = input }
240+
override Expr getInput() { result = this.getArgument(0).asExpr() }
261241

262-
override CryptographicAlgorithm getAlgorithm() { result = algorithm }
242+
override CryptographicAlgorithm getAlgorithm() {
243+
result.matchesName(this.getTarget().getPackage().getName())
244+
}
263245
}

ql/src/experimental/CWE-327/WeakCryptoAlgorithm.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @problem.severity error
66
* @id go/weak-crypto-algorithm
77
* @tags security
8+
* external/cwe/cwe-327
89
*/
910

1011
import go
@@ -13,4 +14,5 @@ import DataFlow::PathGraph
1314

1415
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
1516
where cfg.hasFlowPath(source, sink)
16-
select sink.getNode(), source, sink, "Sensitive data is used in a weak cryptographic algorithm."
17+
select sink.getNode(), source, sink, "$@ is used in a weak cryptographic algorithm.",
18+
source.getNode(), "Sensitive data"

0 commit comments

Comments
 (0)