@@ -10,23 +10,47 @@ private import semmle.code.java.dataflow.RangeUtils
1010private import semmle.code.java.dispatch.VirtualDispatch
1111private import semmle.code.java.frameworks.Properties
1212
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+
1319private class ShortStringLiteral extends StringLiteral {
1420 ShortStringLiteral ( ) { this .getValue ( ) .length ( ) < 100 }
1521}
1622
1723/**
1824 * A string literal that may refer to an insecure cryptographic algorithm.
1925 */
20- class InsecureAlgoLiteral extends ShortStringLiteral {
26+ class InsecureAlgoLiteral extends InsecureAlgorithm , ShortStringLiteral {
2127 InsecureAlgoLiteral ( ) {
22- // Algorithm identifiers should be at least two characters.
23- this .getValue ( ) .length ( ) > 1 and
2428 exists ( string s | s = this .getValue ( ) |
29+ // Algorithm identifiers should be at least two characters.
30+ s .length ( ) > 1 and
2531 not s .regexpMatch ( getSecureAlgorithmRegex ( ) ) and
2632 // Exclude results covered by another query.
2733 not s .regexpMatch ( getInsecureAlgorithmRegex ( ) )
2834 )
2935 }
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 }
3054}
3155
3256private predicate objectToString ( MethodCall ma ) {
@@ -41,17 +65,7 @@ private predicate objectToString(MethodCall ma) {
4165 * A taint-tracking configuration to reason about the use of potentially insecure cryptographic algorithms.
4266 */
4367module 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 }
5569
5670 predicate isSink ( DataFlow:: Node n ) { exists ( CryptoAlgoSpec c | n .asExpr ( ) = c .getAlgoSpec ( ) ) }
5771
0 commit comments