33private import semmle.code.java.security.Encryption
44private import semmle.code.java.dataflow.DataFlow
55
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
77/** A source for an insufficient key size. */
88abstract class InsufficientKeySizeSource extends DataFlow:: Node {
99 /** Holds if this source has the specified `state`. */
@@ -64,7 +64,7 @@ private class AsymmetricNonECSink extends InsufficientKeySizeSink {
6464 AsymmetricNonECSink ( ) {
6565 hasKeySizeInInitMethod ( this , "asymmetric-non-ec" )
6666 or
67- hasKeySizeInSpec ( this , "asymmetric-non-ec" )
67+ hasKeySizeInSpec ( this )
6868 }
6969
7070 override predicate hasState ( DataFlow:: FlowState state ) { state = "2048" }
@@ -83,7 +83,7 @@ private class AsymmetricECSink extends InsufficientKeySizeSink {
8383 AsymmetricECSink ( ) {
8484 hasKeySizeInInitMethod ( this , "asymmetric-ec" )
8585 or
86- hasKeySizeInSpec ( this , "asymmetric-ec" )
86+ hasKeySizeInSpec ( this )
8787 }
8888
8989 override predicate hasState ( DataFlow:: FlowState state ) { state = "256" }
@@ -129,20 +129,28 @@ private string getAlgoName(JavaxCryptoAlgoSpec jca) {
129129
130130// 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()...
131131// 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 ) {
133133 exists ( ClassInstanceExpr paramSpec |
134134 (
135- paramSpec .getConstructedType ( ) instanceof AsymmetricNonECSpec and
136- typeFlag = "asymmetric-non-ec"
135+ paramSpec .getConstructedType ( ) instanceof AsymmetricNonECSpec //and
137136 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"
140140 ) and
141141 node .asExpr ( ) = paramSpec .getArgument ( 0 )
142142 )
143143}
144144
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+ }
146154// TODO:
147155// todo #0: look into use of specs without keygen objects; should spec not be a sink in these cases?
148156// 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