3
3
private import semmle.code.java.security.Encryption
4
4
private import semmle.code.java.dataflow.DataFlow
5
5
6
- // TODO: only update key sizes (and key size strings in one place in the code)
6
+ // TODO: only update key sizes (and key size strings) in one place in the code
7
7
/** A source for an insufficient key size. */
8
8
abstract class InsufficientKeySizeSource extends DataFlow:: Node {
9
9
/** Holds if this source has the specified `state`. */
@@ -64,7 +64,7 @@ private class AsymmetricNonECSink extends InsufficientKeySizeSink {
64
64
AsymmetricNonECSink ( ) {
65
65
hasKeySizeInInitMethod ( this , "asymmetric-non-ec" )
66
66
or
67
- hasKeySizeInSpec ( this , "asymmetric-non-ec" )
67
+ hasKeySizeInSpec ( this )
68
68
}
69
69
70
70
override predicate hasState ( DataFlow:: FlowState state ) { state = "2048" }
@@ -83,7 +83,7 @@ private class AsymmetricECSink extends InsufficientKeySizeSink {
83
83
AsymmetricECSink ( ) {
84
84
hasKeySizeInInitMethod ( this , "asymmetric-ec" )
85
85
or
86
- hasKeySizeInSpec ( this , "asymmetric-ec" )
86
+ hasKeySizeInSpec ( this )
87
87
}
88
88
89
89
override predicate hasState ( DataFlow:: FlowState state ) { state = "256" }
@@ -129,20 +129,28 @@ private string getAlgoName(JavaxCryptoAlgoSpec jca) {
129
129
130
130
// TODO: rethink the predicate name; also think about whether this could/should be a class instead; or a predicate within the sink class so can do sink.predicate()...
131
131
// TODO: can prbly re-work way using the typeFlag to be better and less repetitive...
132
- private predicate hasKeySizeInSpec ( DataFlow:: Node node , string typeFlag ) {
132
+ private predicate hasKeySizeInSpec ( DataFlow:: Node node ) {
133
133
exists ( ClassInstanceExpr paramSpec |
134
134
(
135
- paramSpec .getConstructedType ( ) instanceof AsymmetricNonECSpec and
136
- typeFlag = "asymmetric-non-ec"
135
+ paramSpec .getConstructedType ( ) instanceof AsymmetricNonECSpec //and
137
136
or
138
- paramSpec .getConstructedType ( ) instanceof EcGenParameterSpec and
139
- typeFlag = "asymmetric-ec"
137
+ //typeFlag = "asymmetric-non-ec"
138
+ paramSpec .getConstructedType ( ) instanceof EcGenParameterSpec //and
139
+ //typeFlag = "asymmetric-ec"
140
140
) and
141
141
node .asExpr ( ) = paramSpec .getArgument ( 0 )
142
142
)
143
143
}
144
144
145
- class SpecWithKeySize extends RefType { }
145
+ // ! use below instead of/in above??
146
+ class Spec extends ClassInstanceExpr {
147
+ Spec ( ) {
148
+ this .getConstructedType ( ) instanceof AsymmetricNonECSpec or
149
+ this .getConstructedType ( ) instanceof EcGenParameterSpec
150
+ }
151
+
152
+ Argument getKeySizeArg ( ) { result = this .getArgument ( 0 ) }
153
+ }
146
154
// TODO:
147
155
// todo #0: look into use of specs without keygen objects; should spec not be a sink in these cases?
148
156
// todo #3: make list of algo names more easily reusable (either as constant-type variable at top of file, or model as own class to share, etc.)
0 commit comments