@@ -20,121 +20,69 @@ 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
- 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 ( ) }
27
-
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 ( ) }
23
+ /** A source for an insufficient key size used in an RSA, DSA, and DH algorithms. */
24
+ private class Source extends InsufficientKeySizeSource {
25
+ string algoName ;
52
26
53
- /** An instance of an RSA algorithm specification. */
54
- private class Spec extends ClassInstanceExpr {
55
- Spec ( ) { this .getConstructedType ( ) instanceof RsaKeyGenParameterSpec }
27
+ Source ( ) { this .asExpr ( ) .( IntegerLiteral ) .getIntValue ( ) < getMinKeySize ( algoName ) }
56
28
57
- /** Gets the `keysize` argument of this instance. */
58
- Argument getKeySizeArg ( ) { result = this . getArgument ( 0 ) }
29
+ override predicate hasState ( DataFlow :: FlowState state ) {
30
+ state = getMinKeySize ( algoName ) . toString ( )
59
31
}
60
32
}
61
33
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 ( ) }
34
+ /** A sink for an insufficient key size used in an RSA, DSA, and DH algorithms. */
35
+ private class Sink extends InsufficientKeySizeSink {
36
+ string algoName ;
66
37
67
- override predicate hasState ( DataFlow:: FlowState state ) {
68
- state = getMinKeySize ( ) .toString ( )
69
- }
38
+ Sink ( ) {
39
+ exists ( KeyPairGenInit kpgInit , KeyPairGen kpg |
40
+ algoName in [ "RSA" , "DSA" , "DH" ] and
41
+ kpg .getAlgoName ( ) .matches ( algoName ) and
42
+ DataFlow:: localExprFlow ( kpg , kpgInit .getQualifier ( ) ) and
43
+ this .asExpr ( ) = kpgInit .getKeySizeArg ( )
44
+ )
45
+ or
46
+ exists ( Spec spec | this .asExpr ( ) = spec .getKeySizeArg ( ) and algoName = spec .getAlgoName ( ) )
70
47
}
71
48
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 ) }
49
+ override predicate hasState ( DataFlow:: FlowState state ) {
50
+ state = getMinKeySize ( algoName ) .toString ( )
98
51
}
99
52
}
100
53
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 ( ) }
54
+ /** Returns the minimum recommended key size for RSA, DSA, and DH algorithms. */
55
+ private int getMinKeySize ( string algoName ) {
56
+ algoName = "RSA" and
57
+ result = minSecureKeySizeRsa ( )
58
+ or
59
+ algoName = "DSA" and
60
+ result = minSecureKeySizeDsa ( )
61
+ or
62
+ algoName = "DH" and
63
+ result = minSecureKeySizeDh ( )
64
+ }
105
65
106
- override predicate hasState ( DataFlow:: FlowState state ) {
107
- state = getMinKeySize ( ) .toString ( )
108
- }
109
- }
66
+ /** An instance of an RSA, DSA, or DH algorithm specification. */
67
+ private class Spec extends ClassInstanceExpr {
68
+ string algoName ;
110
69
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
- }
70
+ Spec ( ) {
71
+ this .getConstructedType ( ) instanceof RsaKeyGenParameterSpec and
72
+ algoName = "RSA"
73
+ or
74
+ this .getConstructedType ( ) instanceof DsaGenParameterSpec and
75
+ algoName = "DSA"
76
+ or
77
+ this .getConstructedType ( ) instanceof DhGenParameterSpec and
78
+ algoName = "DH"
126
79
}
127
80
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 }
81
+ /** Gets the `keysize` argument of this instance. */
82
+ Argument getKeySizeArg ( ) { result = this .getArgument ( 0 ) }
134
83
135
- /** Gets the `keysize` argument of this instance. */
136
- Argument getKeySizeArg ( ) { result = this .getArgument ( 0 ) }
137
- }
84
+ /** Gets the algorithm name of this spec. */
85
+ string getAlgoName ( ) { result = algoName }
138
86
}
139
87
}
140
88
0 commit comments