@@ -18,32 +18,45 @@ abstract class InsufficientKeySizeSink extends DataFlow::Node {
18
18
// *********************************** SOURCES ***********************************
19
19
/** A source for an insufficient key size used in RSA, DSA, and DH algorithms. */
20
20
private class AsymmetricNonEcSource extends InsufficientKeySizeSource {
21
- AsymmetricNonEcSource ( ) { getNodeIntValue ( this ) < 2048 }
21
+ AsymmetricNonEcSource ( ) { getNodeIntValue ( this ) < getMinAsymNonEcKeySize ( ) }
22
22
23
- override predicate hasState ( DataFlow:: FlowState state ) { state = "2048" }
23
+ override predicate hasState ( DataFlow:: FlowState state ) {
24
+ state = getMinAsymNonEcKeySize ( ) .toString ( )
25
+ }
24
26
}
25
27
26
28
/** A source for an insufficient key size used in elliptic curve (EC) algorithms. */
27
29
private class AsymmetricEcSource extends InsufficientKeySizeSource {
28
30
AsymmetricEcSource ( ) {
29
- getNodeIntValue ( this ) < 256
31
+ getNodeIntValue ( this ) < getMinAsymEcKeySize ( )
30
32
or
31
33
// 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 ( )
33
35
}
34
36
35
- override predicate hasState ( DataFlow:: FlowState state ) { state = "256" }
37
+ override predicate hasState ( DataFlow:: FlowState state ) {
38
+ state = getMinAsymEcKeySize ( ) .toString ( )
39
+ }
36
40
}
37
41
38
42
/** A source for an insufficient key size used in AES algorithms. */
39
43
private class SymmetricSource extends InsufficientKeySizeSource {
40
- SymmetricSource ( ) { getNodeIntValue ( this ) < 128 }
44
+ SymmetricSource ( ) { getNodeIntValue ( this ) < getMinSymKeySize ( ) }
41
45
42
- override predicate hasState ( DataFlow:: FlowState state ) { state = "128" }
46
+ override predicate hasState ( DataFlow:: FlowState state ) { state = getMinSymKeySize ( ) . toString ( ) }
43
47
}
44
48
45
49
// ************************** 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. */
47
60
private int getNodeIntValue ( DataFlow:: Node node ) {
48
61
result = node .asExpr ( ) .( IntegerLiteral ) .getIntValue ( )
49
62
}
@@ -74,7 +87,9 @@ private class AsymmetricNonEcSink extends InsufficientKeySizeSink {
74
87
exists ( AsymmetricNonEcSpec spec | this .asExpr ( ) = spec .getKeySizeArg ( ) )
75
88
}
76
89
77
- override predicate hasState ( DataFlow:: FlowState state ) { state = "2048" }
90
+ override predicate hasState ( DataFlow:: FlowState state ) {
91
+ state = getMinAsymNonEcKeySize ( ) .toString ( )
92
+ }
78
93
}
79
94
80
95
/** A sink for an insufficient key size used in elliptic curve (EC) algorithms. */
@@ -89,21 +104,22 @@ private class AsymmetricEcSink extends InsufficientKeySizeSink {
89
104
exists ( AsymmetricEcSpec s | this .asExpr ( ) = s .getKeySizeArg ( ) )
90
105
}
91
106
92
- override predicate hasState ( DataFlow:: FlowState state ) { state = "256" }
107
+ override predicate hasState ( DataFlow:: FlowState state ) {
108
+ state = getMinAsymEcKeySize ( ) .toString ( )
109
+ }
93
110
}
94
111
95
112
/** A sink for an insufficient key size used in AES algorithms. */
96
113
private class SymmetricSink extends InsufficientKeySizeSink {
97
114
SymmetricSink ( ) {
98
- //hasKeySizeInInitMethod(this, "symmetric")
99
115
exists ( SymmetricInitMethodAccess ma , SymmetricKeyGenerator kg |
100
116
kg .getAlgoName ( ) = "AES" and
101
117
DataFlow:: localExprFlow ( kg , ma .getQualifier ( ) ) and
102
118
this .asExpr ( ) = ma .getKeySizeArg ( )
103
119
)
104
120
}
105
121
106
- override predicate hasState ( DataFlow:: FlowState state ) { state = "128" }
122
+ override predicate hasState ( DataFlow:: FlowState state ) { state = getMinSymKeySize ( ) . toString ( ) }
107
123
}
108
124
109
125
// ********************** SINKS HELPER CLASSES & PREDICATES **********************
0 commit comments