Skip to content

Commit cae5637

Browse files
committed
Refactor InsufficientKeySize
1 parent fa2f0db commit cae5637

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import semmle.code.java.dataflow.DataFlow
44
import semmle.code.java.security.InsufficientKeySize
55

6-
/** A data flow configuration for tracking key sizes used in cryptographic algorithms. */
7-
class KeySizeConfiguration extends DataFlow::Configuration {
6+
/**
7+
* DEPRECATED: Use `KeySizeFlow` instead.
8+
*
9+
* A data flow configuration for tracking key sizes used in cryptographic algorithms.
10+
*/
11+
deprecated class KeySizeConfiguration extends DataFlow::Configuration {
812
KeySizeConfiguration() { this = "KeySizeConfiguration" }
913

1014
override predicate isSource(DataFlow::Node source, DataFlow::FlowState state) {
@@ -15,3 +19,30 @@ class KeySizeConfiguration extends DataFlow::Configuration {
1519
sink.(InsufficientKeySizeSink).hasState(state)
1620
}
1721
}
22+
23+
/**
24+
* A data flow configuration for tracking key sizes used in cryptographic algorithms.
25+
*/
26+
private module KeySizeConfig implements DataFlow::StateConfigSig {
27+
class FlowState = DataFlow::FlowState;
28+
29+
predicate isSource(DataFlow::Node source, DataFlow::FlowState state) {
30+
source.(InsufficientKeySizeSource).hasState(state)
31+
}
32+
33+
predicate isSink(DataFlow::Node sink, DataFlow::FlowState state) {
34+
sink.(InsufficientKeySizeSink).hasState(state)
35+
}
36+
37+
predicate isBarrier(DataFlow::Node node, DataFlow::FlowState state) { none() }
38+
39+
predicate isAdditionalFlowStep(
40+
DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2,
41+
DataFlow::FlowState state2
42+
) {
43+
none()
44+
}
45+
}
46+
47+
/** Tracks key sizes used in cryptographic algorithms. */
48+
module KeySizeFlow = DataFlow::GlobalWithState<KeySizeConfig>;

java/ql/src/Security/CWE/CWE-326/InsufficientKeySize.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
import java
1515
import semmle.code.java.security.InsufficientKeySizeQuery
16-
import DataFlow::PathGraph
16+
import KeySizeFlow::PathGraph
1717

18-
from DataFlow::PathNode source, DataFlow::PathNode sink, KeySizeConfiguration cfg
19-
where cfg.hasFlowPath(source, sink)
18+
from KeySizeFlow::PathNode source, KeySizeFlow::PathNode sink
19+
where KeySizeFlow::flowPath(source, sink)
2020
select sink.getNode(), source, sink,
2121
"This $@ is less than the recommended key size of " + source.getState() + " bits.",
2222
source.getNode(), "key size"

java/ql/test/query-tests/security/CWE-326/InsufficientKeySizeTest.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class InsufficientKeySizeTest extends InlineExpectationsTest {
99

1010
override predicate hasActualResult(Location location, string element, string tag, string value) {
1111
tag = "hasInsufficientKeySize" and
12-
exists(DataFlow::PathNode sink | exists(KeySizeConfiguration cfg | cfg.hasFlowPath(_, sink)) |
12+
exists(KeySizeFlow::PathNode sink | KeySizeFlow::flowPath(_, sink) |
1313
sink.getNode().getLocation() = location and
1414
element = sink.getNode().toString() and
1515
value = ""

0 commit comments

Comments
 (0)