22
33import java
44import semmle.code.java.dataflow.TaintTracking
5- import semmle.code.java.dataflow.DataFlow2
5+ private import semmle.code.java.dataflow.ExternalFlow
66
77/**
88 * Holds if `array` is initialized only with constants.
@@ -99,7 +99,7 @@ private module ArrayUpdateFlow = DataFlow::Global<ArrayUpdateConfig>;
9999private class StaticInitializationVectorSource extends DataFlow:: Node {
100100 StaticInitializationVectorSource ( ) {
101101 exists ( StaticByteArrayCreation array | array = this .asExpr ( ) |
102- not ArrayUpdateFlow:: flow ( DataFlow2 :: exprNode ( array ) , _) and
102+ not ArrayUpdateFlow:: flow ( DataFlow :: exprNode ( array ) , _) and
103103 // Reduce FPs from utility methods that return an empty array in an exceptional case
104104 not exists ( ReturnStmt ret |
105105 array .getADimension ( ) .( CompileTimeConstantExpr ) .getIntValue ( ) = 0 and
@@ -113,34 +113,7 @@ private class StaticInitializationVectorSource extends DataFlow::Node {
113113 * A sink that initializes a cipher with unsafe parameters.
114114 */
115115private 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" ) }
144117}
145118
146119/**
@@ -156,10 +129,6 @@ deprecated class StaticInitializationVectorConfig extends TaintTracking::Configu
156129 }
157130
158131 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- }
163132}
164133
165134/**
@@ -169,10 +138,6 @@ module StaticInitializationVectorConfig implements DataFlow::ConfigSig {
169138 predicate isSource ( DataFlow:: Node source ) { source instanceof StaticInitializationVectorSource }
170139
171140 predicate isSink ( DataFlow:: Node sink ) { sink instanceof EncryptionInitializationSink }
172-
173- predicate isAdditionalFlowStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
174- createInitializationVectorSpecStep ( fromNode , toNode )
175- }
176141}
177142
178143/** Tracks the flow from a static initialization vector to the initialization of a cipher */
0 commit comments