|
12 | 12 | */
|
13 | 13 |
|
14 | 14 | import java
|
15 |
| -import semmle.code.java.security.Encryption |
16 |
| -import semmle.code.java.dataflow.TaintTracking |
17 |
| -import DataFlow |
18 |
| - |
19 |
| -private class ShortStringLiteral extends StringLiteral { |
20 |
| - ShortStringLiteral() { this.getValue().length() < 100 } |
21 |
| -} |
22 |
| - |
23 |
| -class BrokenAlgoLiteral extends ShortStringLiteral { |
24 |
| - BrokenAlgoLiteral() { |
25 |
| - this.getValue().regexpMatch(getInsecureAlgorithmRegex()) and |
26 |
| - // Exclude German and French sentences. |
27 |
| - not this.getValue().regexpMatch(".*\\p{IsLowercase} des \\p{IsLetter}.*") |
28 |
| - } |
29 |
| -} |
30 |
| - |
31 |
| -module InsecureCryptoConfig implements ConfigSig { |
32 |
| - predicate isSource(Node n) { n.asExpr() instanceof BrokenAlgoLiteral } |
33 |
| - |
34 |
| - predicate isSink(Node n) { exists(CryptoAlgoSpec c | n.asExpr() = c.getAlgoSpec()) } |
35 |
| - |
36 |
| - predicate isBarrier(DataFlow::Node node) { |
37 |
| - node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType |
38 |
| - } |
39 |
| -} |
40 |
| - |
41 |
| -module InsecureCryptoFlow = TaintTracking::Global<InsecureCryptoConfig>; |
42 |
| - |
| 15 | +import semmle.code.java.security.BrokenCryptoAlgorithmQuery |
43 | 16 | import InsecureCryptoFlow::PathGraph
|
44 | 17 |
|
45 | 18 | from
|
46 |
| - InsecureCryptoFlow::PathNode source, InsecureCryptoFlow::PathNode sink, CryptoAlgoSpec c, |
47 |
| - BrokenAlgoLiteral s |
| 19 | + InsecureCryptoFlow::PathNode source, InsecureCryptoFlow::PathNode sink, CryptoAlgoSpec spec, |
| 20 | + BrokenAlgoLiteral algo |
48 | 21 | where
|
49 |
| - sink.getNode().asExpr() = c.getAlgoSpec() and |
50 |
| - source.getNode().asExpr() = s and |
| 22 | + sink.getNode().asExpr() = spec.getAlgoSpec() and |
| 23 | + source.getNode().asExpr() = algo and |
51 | 24 | InsecureCryptoFlow::flowPath(source, sink)
|
52 |
| -select c, source, sink, "Cryptographic algorithm $@ is weak and should not be used.", s, |
53 |
| - s.getValue() |
| 25 | +select spec, source, sink, "Cryptographic algorithm $@ is weak and should not be used.", algo, |
| 26 | + algo.getValue() |
0 commit comments