@@ -20,41 +20,121 @@ abstract class InsufficientKeySizeSink extends DataFlow::Node {
20
20
private module Asymmetric {
21
21
/** Provides models for non-elliptic-curve asymmetric cryptography. */
22
22
private module NonEllipticCurve {
23
- /** A source for an insufficient key size used in RSA, DSA, and DH algorithms. */
24
- private class Source extends InsufficientKeySizeSource {
25
- Source ( ) { this .asExpr ( ) .( IntegerLiteral ) .getIntValue ( ) < getMinKeySize ( ) }
23
+ private module Rsa {
24
+ /** A source for an insufficient key size used in an RSA algorithm. */
25
+ private class Source extends InsufficientKeySizeSource {
26
+ Source ( ) { this .asExpr ( ) .( IntegerLiteral ) .getIntValue ( ) < getMinKeySize ( ) }
26
27
27
- override predicate hasState ( DataFlow:: FlowState state ) { state = getMinKeySize ( ) .toString ( ) }
28
+ override predicate hasState ( DataFlow:: FlowState state ) {
29
+ state = getMinKeySize ( ) .toString ( )
30
+ }
31
+ }
32
+
33
+ /** A sink for an insufficient key size used in an RSA algorithm. */
34
+ private class Sink extends InsufficientKeySizeSink {
35
+ Sink ( ) {
36
+ exists ( KeyPairGenInit kpgInit , KeyPairGen kpg |
37
+ kpg .getAlgoName ( ) = "RSA" and
38
+ DataFlow:: localExprFlow ( kpg , kpgInit .getQualifier ( ) ) and
39
+ this .asExpr ( ) = kpgInit .getKeySizeArg ( )
40
+ )
41
+ or
42
+ exists ( Spec spec | this .asExpr ( ) = spec .getKeySizeArg ( ) )
43
+ }
44
+
45
+ override predicate hasState ( DataFlow:: FlowState state ) {
46
+ state = getMinKeySize ( ) .toString ( )
47
+ }
48
+ }
49
+
50
+ /** Returns the minimum recommended key size for an RSA algorithm. */
51
+ private int getMinKeySize ( ) { result = minSecureKeySizeRsa ( ) }
52
+
53
+ /** An instance of an RSA algorithm specification. */
54
+ private class Spec extends ClassInstanceExpr {
55
+ Spec ( ) { this .getConstructedType ( ) instanceof RsaKeyGenParameterSpec }
56
+
57
+ /** Gets the `keysize` argument of this instance. */
58
+ Argument getKeySizeArg ( ) { result = this .getArgument ( 0 ) }
59
+ }
28
60
}
29
61
30
- /** A sink for an insufficient key size used in RSA, DSA, and DH algorithms. */
31
- private class Sink extends InsufficientKeySizeSink {
32
- Sink ( ) {
33
- exists ( KeyPairGenInit kpgInit , KeyPairGen kpg |
34
- kpg .getAlgoName ( ) .matches ( [ "RSA" , "DSA" , "DH" ] ) and
35
- DataFlow:: localExprFlow ( kpg , kpgInit .getQualifier ( ) ) and
36
- this .asExpr ( ) = kpgInit .getKeySizeArg ( )
37
- )
38
- or
39
- exists ( Spec spec | this .asExpr ( ) = spec .getKeySizeArg ( ) )
62
+ private module Dsa {
63
+ /** A source for an insufficient key size used a DSA algorithm. */
64
+ private class Source extends InsufficientKeySizeSource {
65
+ Source ( ) { this .asExpr ( ) .( IntegerLiteral ) .getIntValue ( ) < getMinKeySize ( ) }
66
+
67
+ override predicate hasState ( DataFlow:: FlowState state ) {
68
+ state = getMinKeySize ( ) .toString ( )
69
+ }
40
70
}
41
71
42
- override predicate hasState ( DataFlow:: FlowState state ) { state = getMinKeySize ( ) .toString ( ) }
72
+ /** A sink for an insufficient key size used in a DSA algorithm. */
73
+ private class Sink extends InsufficientKeySizeSink {
74
+ Sink ( ) {
75
+ exists ( KeyPairGenInit kpgInit , KeyPairGen kpg |
76
+ kpg .getAlgoName ( ) = "DSA" and
77
+ DataFlow:: localExprFlow ( kpg , kpgInit .getQualifier ( ) ) and
78
+ this .asExpr ( ) = kpgInit .getKeySizeArg ( )
79
+ )
80
+ or
81
+ exists ( Spec spec | this .asExpr ( ) = spec .getKeySizeArg ( ) )
82
+ }
83
+
84
+ override predicate hasState ( DataFlow:: FlowState state ) {
85
+ state = getMinKeySize ( ) .toString ( )
86
+ }
87
+ }
88
+
89
+ /** Returns the minimum recommended key size for a DSA algorithm. */
90
+ private int getMinKeySize ( ) { result = minSecureKeySizeDsa ( ) }
91
+
92
+ /** An instance of a DSA algorithm specification. */
93
+ private class Spec extends ClassInstanceExpr {
94
+ Spec ( ) { this .getConstructedType ( ) instanceof DsaGenParameterSpec }
95
+
96
+ /** Gets the `keysize` argument of this instance. */
97
+ Argument getKeySizeArg ( ) { result = this .getArgument ( 0 ) }
98
+ }
43
99
}
44
100
45
- /** Returns the minimum recommended key size for RSA, DSA, and DH algorithms. */
46
- private int getMinKeySize ( ) { result = minSecureKeySizeAsymmetricNonEc ( ) }
101
+ private module Dh {
102
+ /** A source for an insufficient key size used in a DH algorithm. */
103
+ private class Source extends InsufficientKeySizeSource {
104
+ Source ( ) { this .asExpr ( ) .( IntegerLiteral ) .getIntValue ( ) < getMinKeySize ( ) }
47
105
48
- /** An instance of an RSA, DSA, or DH algorithm specification. */
49
- private class Spec extends ClassInstanceExpr {
50
- Spec ( ) {
51
- this .getConstructedType ( ) instanceof RsaKeyGenParameterSpec or
52
- this .getConstructedType ( ) instanceof DsaGenParameterSpec or
53
- this .getConstructedType ( ) instanceof DhGenParameterSpec
106
+ override predicate hasState ( DataFlow:: FlowState state ) {
107
+ state = getMinKeySize ( ) .toString ( )
108
+ }
54
109
}
55
110
56
- /** Gets the `keysize` argument of this instance. */
57
- Argument getKeySizeArg ( ) { result = this .getArgument ( 0 ) }
111
+ /** A sink for an insufficient key size used in a DH algorithm. */
112
+ private class Sink extends InsufficientKeySizeSink {
113
+ Sink ( ) {
114
+ exists ( KeyPairGenInit kpgInit , KeyPairGen kpg |
115
+ kpg .getAlgoName ( ) = "DH" and
116
+ DataFlow:: localExprFlow ( kpg , kpgInit .getQualifier ( ) ) and
117
+ this .asExpr ( ) = kpgInit .getKeySizeArg ( )
118
+ )
119
+ or
120
+ exists ( Spec spec | this .asExpr ( ) = spec .getKeySizeArg ( ) )
121
+ }
122
+
123
+ override predicate hasState ( DataFlow:: FlowState state ) {
124
+ state = getMinKeySize ( ) .toString ( )
125
+ }
126
+ }
127
+
128
+ /** Returns the minimum recommended key size for a DH algorithm. */
129
+ private int getMinKeySize ( ) { result = minSecureKeySizeDh ( ) }
130
+
131
+ /** An instance of an RSA, DSA, or DH algorithm specification. */
132
+ private class Spec extends ClassInstanceExpr {
133
+ Spec ( ) { this .getConstructedType ( ) instanceof DhGenParameterSpec }
134
+
135
+ /** Gets the `keysize` argument of this instance. */
136
+ Argument getKeySizeArg ( ) { result = this .getArgument ( 0 ) }
137
+ }
58
138
}
59
139
}
60
140
@@ -88,7 +168,7 @@ private module Asymmetric {
88
168
}
89
169
90
170
/** Returns the minimum recommended key size for elliptic curve (EC) algorithms. */
91
- private int getMinKeySize ( ) { result = minSecureKeySizeAsymmetricEc ( ) }
171
+ private int getMinKeySize ( ) { result = minSecureKeySizeEcc ( ) }
92
172
93
173
/** Returns the key size from an EC algorithm's curve name string */
94
174
bindingset [ algorithm]
@@ -169,7 +249,7 @@ private module Symmetric {
169
249
}
170
250
171
251
/** Returns the minimum recommended key size for AES algorithms. */
172
- private int getMinKeySize ( ) { result = minSecureKeySizeSymmetric ( ) }
252
+ private int getMinKeySize ( ) { result = minSecureKeySizeAes ( ) }
173
253
174
254
/** A call to the `init` method declared in `javax.crypto.KeyGenerator`. */
175
255
private class KeyGenInit extends MethodAccess {
0 commit comments