@@ -6,120 +6,43 @@ import semmle.code.java.dataflow.TaintTracking
66import semmle.code.java.security.InsufficientKeySize
77
88/**
9- * A data flow configuration for tracking non-elliptic curve asymmetric algorithms
9+ * A data flow configuration for tracking non-elliptic curve asymmetric algorithm
1010 * (RSA, DSA, and DH) key sizes.
1111 */
12- class AsymmetricNonECKeyTrackingConfiguration extends DataFlow:: Configuration {
13- AsymmetricNonECKeyTrackingConfiguration ( ) { this = "AsymmetricNonECKeyTrackingConfiguration" }
14-
15- override predicate isSource ( DataFlow:: Node source ) { source instanceof AsymmetricNonECSource }
16-
17- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof AsymmetricNonECSink }
18- }
19-
20- /**
21- * A data flow configuration for tracking elliptic curve (EC) asymmetric
22- * algorithm key sizes.
23- */
24- class AsymmetricECKeyTrackingConfiguration extends DataFlow:: Configuration {
25- AsymmetricECKeyTrackingConfiguration ( ) { this = "AsymmetricECKeyTrackingConfiguration" }
26-
27- override predicate isSource ( DataFlow:: Node source ) { source instanceof AsymmetricECSource }
28-
29- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof AsymmetricECSink }
12+ class KeySizeConfiguration extends DataFlow:: Configuration {
13+ KeySizeConfiguration ( ) { this = "KeySizeConfiguration" }
14+
15+ override predicate isSource ( DataFlow:: Node source , DataFlow:: FlowState state ) {
16+ source .( InsufficientKeySizeSource ) .hasState ( state )
17+ //source instanceof InsufficientKeySizeSource
18+ }
19+
20+ override predicate isSink ( DataFlow:: Node sink , DataFlow:: FlowState state ) {
21+ sink .( InsufficientKeySizeSink ) .hasState ( state )
22+ //sink instanceof InsufficientKeySizeSink
23+ }
3024}
31-
32- /** A data flow configuration for tracking symmetric algorithm (AES) key sizes. */
33- class SymmetricKeyTrackingConfiguration extends DataFlow:: Configuration {
34- SymmetricKeyTrackingConfiguration ( ) { this = "SymmetricKeyTrackingConfiguration" }
35-
36- override predicate isSource ( DataFlow:: Node source ) { source instanceof SymmetricSource }
37-
38- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof SymmetricSink }
39- }
40- // ******* 3 DATAFLOW CONFIGS ABOVE *************************************************************************
41- // ******* SINGLE CONFIG ATTEMPT BELOW *************************************************************************
4225// /**
43- // * A key length data flow tracking configuration.
26+ // * A data flow configuration for tracking non-elliptic curve asymmetric algorithm
27+ // * (RSA, DSA, and DH) key sizes.
4428// */
45- // class KeyTrackingConfiguration extends DataFlow::Configuration {
46- // KeyTrackingConfiguration() { this = "KeyTrackingConfiguration" }
47- // override predicate isSource(DataFlow::Node source, DataFlow::FlowState state) {
48- // //state instanceof DataFlow::FlowStateEmpty and
49- // // SYMMETRIC
50- // source.asExpr().(IntegerLiteral).getIntValue() < 128 and state = "128"
51- // or
52- // // ASYMMETRIC
53- // source.asExpr().(IntegerLiteral).getIntValue() < 2048 and state = "2048"
54- // or
55- // source.asExpr().(IntegerLiteral).getIntValue() < 256 and state = "256"
56- // or
57- // getECKeySize(source.asExpr().(StringLiteral).getValue()) < 256 and state = "256" // need this for the cases when the key size is embedded in the curve name.
58- // }
59- // override predicate isSink(DataFlow::Node sink, DataFlow::FlowState state) {
60- // // SYMMETRIC
61- // exists(MethodAccess ma, JavaxCryptoKeyGenerator jcg |
62- // ma.getMethod() instanceof KeyGeneratorInitMethod and
63- // jcg.getAlgoSpec().(StringLiteral).getValue().toUpperCase() = "AES" and
64- // DataFlow::localExprFlow(jcg, ma.getQualifier()) and
65- // sink.asExpr() = ma.getArgument(0) and
66- // state = "128"
67- // )
68- // or
69- // // ASYMMETRIC
70- // exists(MethodAccess ma, JavaSecurityKeyPairGenerator jpg |
71- // ma.getMethod() instanceof KeyPairGeneratorInitMethod and
72- // (
73- // jpg.getAlgoSpec().(StringLiteral).getValue().toUpperCase().matches(["RSA", "DSA", "DH"]) and
74- // DataFlow::localExprFlow(jpg, ma.getQualifier()) and
75- // sink.asExpr() = ma.getArgument(0) and
76- // //ma.getArgument(0).(LocalSourceNode).flowsTo(sink) and
77- // //ma.getArgument(0).(CompileTimeConstantExpr).getIntValue() < 2048 and
78- // state = "2048"
79- // )
80- // or
81- // jpg.getAlgoSpec().(StringLiteral).getValue().toUpperCase().matches("EC%") and
82- // DataFlow::localExprFlow(jpg, ma.getQualifier()) and
83- // sink.asExpr() = ma.getArgument(0) and
84- // //ma.getArgument(0).(CompileTimeConstantExpr).getIntValue() < 256 and
85- // state = "256"
86- // )
87- // or
88- // // TODO: combine below three for less duplicated code
89- // exists(ClassInstanceExpr rsaKeyGenParamSpec |
90- // rsaKeyGenParamSpec.getConstructedType() instanceof RsaKeyGenParameterSpec and
91- // sink.asExpr() = rsaKeyGenParamSpec.getArgument(0) and
92- // state = "2048"
93- // )
94- // or
95- // exists(ClassInstanceExpr dsaGenParamSpec |
96- // dsaGenParamSpec.getConstructedType() instanceof DsaGenParameterSpec and
97- // sink.asExpr() = dsaGenParamSpec.getArgument(0) and
98- // state = "2048"
99- // )
100- // or
101- // exists(ClassInstanceExpr dhGenParamSpec |
102- // dhGenParamSpec.getConstructedType() instanceof DhGenParameterSpec and
103- // sink.asExpr() = dhGenParamSpec.getArgument(0) and
104- // state = "2048"
105- // )
106- // or
107- // exists(ClassInstanceExpr ecGenParamSpec |
108- // ecGenParamSpec.getConstructedType() instanceof EcGenParameterSpec and
109- // sink.asExpr() = ecGenParamSpec.getArgument(0) and
110- // state = "256"
111- // )
112- // }
113- // // ! FlowStates seem to work without even including a step like the below... hmmm
114- // override predicate isAdditionalFlowStep(
115- // DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2,
116- // DataFlow::FlowState state2
117- // ) {
118- // exists(IntegerLiteral intLiteral |
119- // state1 = "" and
120- // state2 = intLiteral.toString() and
121- // node1.asExpr() = intLiteral and
122- // node2.asExpr() = intLiteral
123- // )
124- // }
29+ // class AsymmetricNonECKeyTrackingConfiguration extends DataFlow::Configuration {
30+ // AsymmetricNonECKeyTrackingConfiguration() { this = "AsymmetricNonECKeyTrackingConfiguration" }
31+ // override predicate isSource(DataFlow::Node source) { source instanceof AsymmetricNonECSource }
32+ // override predicate isSink(DataFlow::Node sink) { sink instanceof AsymmetricNonECSink }
33+ // }
34+ // /**
35+ // * A data flow configuration for tracking elliptic curve (EC) asymmetric
36+ // * algorithm key sizes.
37+ // */
38+ // class AsymmetricECKeyTrackingConfiguration extends DataFlow::Configuration {
39+ // AsymmetricECKeyTrackingConfiguration() { this = "AsymmetricECKeyTrackingConfiguration" }
40+ // override predicate isSource(DataFlow::Node source) { source instanceof AsymmetricECSource }
41+ // override predicate isSink(DataFlow::Node sink) { sink instanceof AsymmetricECSink }
42+ // }
43+ // /** A data flow configuration for tracking symmetric algorithm (AES) key sizes. */
44+ // class SymmetricKeyTrackingConfiguration extends DataFlow::Configuration {
45+ // SymmetricKeyTrackingConfiguration() { this = "SymmetricKeyTrackingConfiguration" }
46+ // override predicate isSource(DataFlow::Node source) { source instanceof SymmetricSource }
47+ // override predicate isSink(DataFlow::Node sink) { sink instanceof SymmetricSink }
12548// }
0 commit comments