|
| 1 | +/** Provides classes and predicates to reason about property files and weak hashing algorithms. */ |
| 2 | + |
| 3 | +import java |
| 4 | +private import semmle.code.configfiles.ConfigFiles |
| 5 | +private import semmle.code.java.dataflow.DataFlow |
| 6 | +private import semmle.code.java.dataflow.TaintTracking |
| 7 | +private import semmle.code.java.security.Encryption |
| 8 | +private import semmle.code.java.frameworks.Properties |
| 9 | +private import semmle.code.java.dataflow.RangeUtils |
| 10 | + |
| 11 | +class GetPropertyMethodAccess extends MethodAccess { |
| 12 | + GetPropertyMethodAccess() { this.getMethod() instanceof PropertiesGetPropertyMethod } |
| 13 | + |
| 14 | + private ConfigPair getPair() { |
| 15 | + this.getArgument(0).(ConstantStringExpr).getStringValue() = result.getNameElement().getName() |
| 16 | + } |
| 17 | + |
| 18 | + string getValue() { |
| 19 | + result = this.getPair().getValueElement().getValue() or |
| 20 | + result = this.getArgument(1).(ConstantStringExpr).getStringValue() |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +string getWeakHashingAlgorithm(DataFlow::Node node) { |
| 25 | +/** |
| 26 | + * Get the name of the weak cryptographic algorithm represented by `node`. |
| 27 | + */ |
| 28 | +string getWeakHashingAlgorithmName(DataFlow::Node node) { |
| 29 | + exists(MethodAccess ma, ConfigPair pair | |
| 30 | + node.asExpr() = ma and ma.getMethod() instanceof PropertiesGetPropertyMethod |
| 31 | + | |
| 32 | + ma.getArgument(0).(ConstantStringExpr).getStringValue() = pair.getNameElement().getName() and |
| 33 | + pair.getValueElement().getValue() = result and |
| 34 | + not pair.getValueElement().getValue().regexpMatch(getSecureAlgorithmRegex()) |
| 35 | + ) |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * Dataflow configuration from a configuration pair in a properties file to the use of a cryptographic algorithm. |
| 40 | + */ |
| 41 | +module InsecureAlgorithmPropertyConfig implements DataFlow::ConfigSig { |
| 42 | + predicate isSource(DataFlow::Node n) { |
| 43 | + exists(MethodAccess ma, ConfigPair pair | |
| 44 | + n.asExpr() = ma and ma.getMethod() instanceof PropertiesGetPropertyMethod |
| 45 | + | |
| 46 | + ma.getArgument(0).(ConstantStringExpr).getStringValue() = pair.getNameElement().getName() and |
| 47 | + not pair.getValueElement().getValue().regexpMatch(getSecureAlgorithmRegex()) |
| 48 | + ) |
| 49 | + } |
| 50 | + |
| 51 | + predicate isSink(DataFlow::Node n) { n.asExpr() = any(CryptoAlgoSpec c).getAlgoSpec() } |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Dataflow from a configuration pair in a properties file to the use of a cryptographic algorithm. |
| 56 | + */ |
| 57 | +module InsecureAlgorithmPropertyFlow = TaintTracking::Global<InsecureAlgorithmPropertyConfig>; |
0 commit comments