2
2
3
3
import java
4
4
import semmle.code.java.dataflow.TaintTracking
5
- import semmle.code.java.dataflow.DataFlow2
5
+ private import semmle.code.java.dataflow.ExternalFlow
6
6
7
7
/**
8
8
* Holds if `array` is initialized only with constants.
@@ -99,7 +99,7 @@ private module ArrayUpdateFlow = DataFlow::Global<ArrayUpdateConfig>;
99
99
private class StaticInitializationVectorSource extends DataFlow:: Node {
100
100
StaticInitializationVectorSource ( ) {
101
101
exists ( StaticByteArrayCreation array | array = this .asExpr ( ) |
102
- not ArrayUpdateFlow:: flow ( DataFlow2 :: exprNode ( array ) , _) and
102
+ not ArrayUpdateFlow:: flow ( DataFlow :: exprNode ( array ) , _) and
103
103
// Reduce FPs from utility methods that return an empty array in an exceptional case
104
104
not exists ( ReturnStmt ret |
105
105
array .getADimension ( ) .( CompileTimeConstantExpr ) .getIntValue ( ) = 0 and
@@ -113,34 +113,7 @@ private class StaticInitializationVectorSource extends DataFlow::Node {
113
113
* A sink that initializes a cipher with unsafe parameters.
114
114
*/
115
115
private class EncryptionInitializationSink extends DataFlow:: Node {
116
- EncryptionInitializationSink ( ) {
117
- exists ( MethodAccess ma , Method m | m = ma .getMethod ( ) |
118
- m .hasQualifiedName ( "javax.crypto" , "Cipher" , "init" ) and
119
- m .getParameterType ( 2 )
120
- .( RefType )
121
- .hasQualifiedName ( "java.security.spec" , "AlgorithmParameterSpec" ) and
122
- ma .getArgument ( 2 ) = this .asExpr ( )
123
- )
124
- }
125
- }
126
-
127
- /**
128
- * Holds if `fromNode` to `toNode` is a dataflow step
129
- * that creates cipher's parameters with initialization vector.
130
- */
131
- private predicate createInitializationVectorSpecStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
132
- exists ( ConstructorCall cc , RefType type |
133
- cc = toNode .asExpr ( ) and type = cc .getConstructedType ( )
134
- |
135
- type .hasQualifiedName ( "javax.crypto.spec" , "IvParameterSpec" ) and
136
- cc .getArgument ( 0 ) = fromNode .asExpr ( )
137
- or
138
- type .hasQualifiedName ( "javax.crypto.spec" , [ "GCMParameterSpec" , "RC2ParameterSpec" ] ) and
139
- cc .getArgument ( 1 ) = fromNode .asExpr ( )
140
- or
141
- type .hasQualifiedName ( "javax.crypto.spec" , "RC5ParameterSpec" ) and
142
- cc .getArgument ( 3 ) = fromNode .asExpr ( )
143
- )
116
+ EncryptionInitializationSink ( ) { sinkNode ( this , "encryption-iv" ) }
144
117
}
145
118
146
119
/**
@@ -156,10 +129,6 @@ deprecated class StaticInitializationVectorConfig extends TaintTracking::Configu
156
129
}
157
130
158
131
override predicate isSink ( DataFlow:: Node sink ) { sink instanceof EncryptionInitializationSink }
159
-
160
- override predicate isAdditionalTaintStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
161
- createInitializationVectorSpecStep ( fromNode , toNode )
162
- }
163
132
}
164
133
165
134
/**
@@ -169,10 +138,6 @@ module StaticInitializationVectorConfig implements DataFlow::ConfigSig {
169
138
predicate isSource ( DataFlow:: Node source ) { source instanceof StaticInitializationVectorSource }
170
139
171
140
predicate isSink ( DataFlow:: Node sink ) { sink instanceof EncryptionInitializationSink }
172
-
173
- predicate isAdditionalFlowStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
174
- createInitializationVectorSpecStep ( fromNode , toNode )
175
- }
176
141
}
177
142
178
143
/** Tracks the flow from a static initialization vector to the initialization of a cipher */
0 commit comments