@@ -10,23 +10,47 @@ private import semmle.code.java.dataflow.RangeUtils
10
10
private import semmle.code.java.dispatch.VirtualDispatch
11
11
private import semmle.code.java.frameworks.Properties
12
12
13
+ /** A reference to an insecure cryptographic algorithm. */
14
+ abstract class InsecureAlgorithm extends Expr {
15
+ /** Gets the string representation of this insecure cryptographic algorithm. */
16
+ abstract string getStringValue ( ) ;
17
+ }
18
+
13
19
private class ShortStringLiteral extends StringLiteral {
14
20
ShortStringLiteral ( ) { this .getValue ( ) .length ( ) < 100 }
15
21
}
16
22
17
23
/**
18
24
* A string literal that may refer to an insecure cryptographic algorithm.
19
25
*/
20
- class InsecureAlgoLiteral extends ShortStringLiteral {
26
+ class InsecureAlgoLiteral extends InsecureAlgorithm , ShortStringLiteral {
21
27
InsecureAlgoLiteral ( ) {
22
- // Algorithm identifiers should be at least two characters.
23
- this .getValue ( ) .length ( ) > 1 and
24
28
exists ( string s | s = this .getValue ( ) |
29
+ // Algorithm identifiers should be at least two characters.
30
+ s .length ( ) > 1 and
25
31
not s .regexpMatch ( getSecureAlgorithmRegex ( ) ) and
26
32
// Exclude results covered by another query.
27
33
not s .regexpMatch ( getInsecureAlgorithmRegex ( ) )
28
34
)
29
35
}
36
+
37
+ override string getStringValue ( ) { result = this .getValue ( ) }
38
+ }
39
+
40
+ /**
41
+ * A property access that may refer to an insecure cryptographic algorithm.
42
+ */
43
+ class InsecureAlgoProperty extends InsecureAlgorithm , PropertiesGetPropertyMethodCall {
44
+ string value ;
45
+
46
+ InsecureAlgoProperty ( ) {
47
+ value = this .getPropertyValue ( ) and
48
+ // Since properties pairs are not included in the java/weak-cryptographic-algorithm,
49
+ // the check for values from properties files can be less strict than `InsecureAlgoLiteral`.
50
+ not value .regexpMatch ( getSecureAlgorithmRegex ( ) )
51
+ }
52
+
53
+ override string getStringValue ( ) { result = value }
30
54
}
31
55
32
56
private predicate objectToString ( MethodCall ma ) {
@@ -41,17 +65,7 @@ private predicate objectToString(MethodCall ma) {
41
65
* A taint-tracking configuration to reason about the use of potentially insecure cryptographic algorithms.
42
66
*/
43
67
module InsecureCryptoConfig implements DataFlow:: ConfigSig {
44
- predicate isSource ( DataFlow:: Node n ) {
45
- n .asExpr ( ) instanceof InsecureAlgoLiteral
46
- or
47
- exists ( PropertiesGetPropertyMethodCall mc , string value |
48
- n .asExpr ( ) = mc and value = mc .getPropertyValue ( )
49
- |
50
- // Since properties pairs are not included in the java/weak-crypto-algorithm,
51
- // The check for values from properties files can be less strict than `InsecureAlgoLiteral`.
52
- not value .regexpMatch ( getSecureAlgorithmRegex ( ) )
53
- )
54
- }
68
+ predicate isSource ( DataFlow:: Node n ) { n .asExpr ( ) instanceof InsecureAlgorithm }
55
69
56
70
predicate isSink ( DataFlow:: Node n ) { exists ( CryptoAlgoSpec c | n .asExpr ( ) = c .getAlgoSpec ( ) ) }
57
71
0 commit comments