@@ -18,32 +18,45 @@ abstract class InsufficientKeySizeSink extends DataFlow::Node {
1818// *********************************** SOURCES ***********************************
1919/** A source for an insufficient key size used in RSA, DSA, and DH algorithms. */
2020private class AsymmetricNonEcSource extends InsufficientKeySizeSource {
21- AsymmetricNonEcSource ( ) { getNodeIntValue ( this ) < 2048 }
21+ AsymmetricNonEcSource ( ) { getNodeIntValue ( this ) < getMinAsymNonEcKeySize ( ) }
2222
23- override predicate hasState ( DataFlow:: FlowState state ) { state = "2048" }
23+ override predicate hasState ( DataFlow:: FlowState state ) {
24+ state = getMinAsymNonEcKeySize ( ) .toString ( )
25+ }
2426}
2527
2628/** A source for an insufficient key size used in elliptic curve (EC) algorithms. */
2729private class AsymmetricEcSource extends InsufficientKeySizeSource {
2830 AsymmetricEcSource ( ) {
29- getNodeIntValue ( this ) < 256
31+ getNodeIntValue ( this ) < getMinAsymEcKeySize ( )
3032 or
3133 // the below is needed for cases when the key size is embedded in the curve name
32- getEcKeySize ( this .asExpr ( ) .( StringLiteral ) .getValue ( ) ) < 256
34+ getEcKeySize ( this .asExpr ( ) .( StringLiteral ) .getValue ( ) ) < getMinAsymEcKeySize ( )
3335 }
3436
35- override predicate hasState ( DataFlow:: FlowState state ) { state = "256" }
37+ override predicate hasState ( DataFlow:: FlowState state ) {
38+ state = getMinAsymEcKeySize ( ) .toString ( )
39+ }
3640}
3741
3842/** A source for an insufficient key size used in AES algorithms. */
3943private class SymmetricSource extends InsufficientKeySizeSource {
40- SymmetricSource ( ) { getNodeIntValue ( this ) < 128 }
44+ SymmetricSource ( ) { getNodeIntValue ( this ) < getMinSymKeySize ( ) }
4145
42- override predicate hasState ( DataFlow:: FlowState state ) { state = "128" }
46+ override predicate hasState ( DataFlow:: FlowState state ) { state = getMinSymKeySize ( ) . toString ( ) }
4347}
4448
4549// ************************** SOURCES HELPER PREDICATES **************************
46- /** Returns the integer value of a given Node. */
50+ /** Returns the minimum recommended key size for RSA, DSA, and DH algorithms. */
51+ private int getMinAsymNonEcKeySize ( ) { result = 2048 }
52+
53+ /** Returns the minimum recommended key size for elliptic curve (EC) algorithms. */
54+ private int getMinAsymEcKeySize ( ) { result = 256 }
55+
56+ /** Returns the minimum recommended key size for AES algorithms. */
57+ private int getMinSymKeySize ( ) { result = 128 }
58+
59+ /** Returns the integer value of a given DataFlow::Node. */
4760private int getNodeIntValue ( DataFlow:: Node node ) {
4861 result = node .asExpr ( ) .( IntegerLiteral ) .getIntValue ( )
4962}
@@ -74,7 +87,9 @@ private class AsymmetricNonEcSink extends InsufficientKeySizeSink {
7487 exists ( AsymmetricNonEcSpec spec | this .asExpr ( ) = spec .getKeySizeArg ( ) )
7588 }
7689
77- override predicate hasState ( DataFlow:: FlowState state ) { state = "2048" }
90+ override predicate hasState ( DataFlow:: FlowState state ) {
91+ state = getMinAsymNonEcKeySize ( ) .toString ( )
92+ }
7893}
7994
8095/** A sink for an insufficient key size used in elliptic curve (EC) algorithms. */
@@ -89,21 +104,22 @@ private class AsymmetricEcSink extends InsufficientKeySizeSink {
89104 exists ( AsymmetricEcSpec s | this .asExpr ( ) = s .getKeySizeArg ( ) )
90105 }
91106
92- override predicate hasState ( DataFlow:: FlowState state ) { state = "256" }
107+ override predicate hasState ( DataFlow:: FlowState state ) {
108+ state = getMinAsymEcKeySize ( ) .toString ( )
109+ }
93110}
94111
95112/** A sink for an insufficient key size used in AES algorithms. */
96113private class SymmetricSink extends InsufficientKeySizeSink {
97114 SymmetricSink ( ) {
98- //hasKeySizeInInitMethod(this, "symmetric")
99115 exists ( SymmetricInitMethodAccess ma , SymmetricKeyGenerator kg |
100116 kg .getAlgoName ( ) = "AES" and
101117 DataFlow:: localExprFlow ( kg , ma .getQualifier ( ) ) and
102118 this .asExpr ( ) = ma .getKeySizeArg ( )
103119 )
104120 }
105121
106- override predicate hasState ( DataFlow:: FlowState state ) { state = "128" }
122+ override predicate hasState ( DataFlow:: FlowState state ) { state = getMinSymKeySize ( ) . toString ( ) }
107123}
108124
109125// ********************** SINKS HELPER CLASSES & PREDICATES **********************
0 commit comments