Skip to content

Commit 6408d7c

Browse files
committed
Java: Refactor RsaWithoutOaep.
1 parent b3b5c2c commit 6408d7c

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

java/ql/lib/semmle/code/java/security/RsaWithoutOaepQuery.qll

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import java
44
import Encryption
55
import semmle.code.java.dataflow.DataFlow
66

7-
/** A configuration for finding RSA ciphers initialized without using OAEP padding. */
8-
class RsaWithoutOaepConfig extends DataFlow::Configuration {
7+
/**
8+
* DEPRECATED: Use `RsaWithoutOaepFlow` instead.
9+
*
10+
* A configuration for finding RSA ciphers initialized without using OAEP padding.
11+
*/
12+
deprecated class RsaWithoutOaepConfig extends DataFlow::Configuration {
913
RsaWithoutOaepConfig() { this = "RsaWithoutOaepConfig" }
1014

1115
override predicate isSource(DataFlow::Node src) {
@@ -21,3 +25,21 @@ class RsaWithoutOaepConfig extends DataFlow::Configuration {
2125
exists(CryptoAlgoSpec cr | sink.asExpr() = cr.getAlgoSpec())
2226
}
2327
}
28+
29+
private module RsaWithoutOaepConfig implements DataFlow::ConfigSig {
30+
predicate isSource(DataFlow::Node src) {
31+
exists(CompileTimeConstantExpr specExpr, string spec |
32+
specExpr.getStringValue() = spec and
33+
specExpr = src.asExpr() and
34+
spec.matches("RSA/%") and
35+
not spec.matches("%OAEP%")
36+
)
37+
}
38+
39+
predicate isSink(DataFlow::Node sink) {
40+
exists(CryptoAlgoSpec cr | sink.asExpr() = cr.getAlgoSpec())
41+
}
42+
}
43+
44+
/** Flow for finding RSA ciphers initialized without using OAEP padding. */
45+
module RsaWithoutOaepFlow = DataFlow::Make<RsaWithoutOaepConfig>;

java/ql/src/Security/CWE/CWE-780/RsaWithoutOaep.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
import java
1414
import semmle.code.java.security.RsaWithoutOaepQuery
15-
import DataFlow::PathGraph
15+
import RsaWithoutOaepFlow::PathGraph
1616

17-
from RsaWithoutOaepConfig conf, DataFlow::PathNode source, DataFlow::PathNode sink
18-
where conf.hasFlowPath(source, sink)
17+
from RsaWithoutOaepFlow::PathNode source, RsaWithoutOaepFlow::PathNode sink
18+
where RsaWithoutOaepFlow::hasFlowPath(source, sink)
1919
select source, source, sink, "This specification is used to $@ without OAEP padding.", sink,
2020
"initialize an RSA cipher"

java/ql/test/query-tests/security/CWE-780/RsaWithoutOaepTest.ql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import TestUtilities.InlineExpectationsTest
33
import TestUtilities.InlineFlowTest
44
import semmle.code.java.security.RsaWithoutOaepQuery
55

6-
class EnableLegacy extends EnableLegacyConfiguration {
7-
EnableLegacy() { exists(this) }
8-
}
9-
106
class HasFlowTest extends InlineFlowTest {
11-
override DataFlow::Configuration getTaintFlowConfig() { result instanceof RsaWithoutOaepConfig }
7+
override predicate hasValueFlow(DataFlow::Node src, DataFlow::Node sink) { none() }
128

13-
override DataFlow::Configuration getValueFlowConfig() { none() }
9+
override predicate hasTaintFlow(DataFlow::Node src, DataFlow::Node sink) {
10+
RsaWithoutOaepFlow::hasFlow(src, sink)
11+
}
1412
}

0 commit comments

Comments
 (0)