33import java
44import semmle.code.java.dataflow.TaintTracking
55import semmle.code.java.dataflow.DataFlow2
6+ private import semmle.code.java.dataflow.ExternalFlow
67
78/**
89 * Holds if `array` is initialized only with constants.
@@ -113,34 +114,7 @@ private class StaticInitializationVectorSource extends DataFlow::Node {
113114 * A sink that initializes a cipher with unsafe parameters.
114115 */
115116private 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- )
117+ EncryptionInitializationSink ( ) { sinkNode ( this , "encryption-iv" ) }
144118}
145119
146120/**
@@ -156,10 +130,6 @@ deprecated class StaticInitializationVectorConfig extends TaintTracking::Configu
156130 }
157131
158132 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- }
163133}
164134
165135/**
@@ -169,10 +139,6 @@ module StaticInitializationVectorConfig implements DataFlow::ConfigSig {
169139 predicate isSource ( DataFlow:: Node source ) { source instanceof StaticInitializationVectorSource }
170140
171141 predicate isSink ( DataFlow:: Node sink ) { sink instanceof EncryptionInitializationSink }
172-
173- predicate isAdditionalFlowStep ( DataFlow:: Node fromNode , DataFlow:: Node toNode ) {
174- createInitializationVectorSpecStep ( fromNode , toNode )
175- }
176142}
177143
178144/** Tracks the flow from a static initialization vector to the initialization of a cipher */
0 commit comments