66
77import python
88private import semmle.python.dataflow.new.DataFlow
9- private import semmle.python.dataflow.new.DataFlowOnlyInternalUse
109private import semmle.python.dataflow.new.RemoteFlowSources
1110private import semmle.python.dataflow.new.TaintTracking
1211private import semmle.python.Frameworks
@@ -563,19 +562,34 @@ module Cryptography {
563562
564563 /** Provides classes for modeling new key-pair generation APIs. */
565564 module KeyGeneration {
566- /**
567- * A data-flow configuration for tracking integer literals.
568- */
569- private class IntegerLiteralTrackerConfiguration extends DataFlowOnlyInternalUse:: Configuration {
570- IntegerLiteralTrackerConfiguration ( ) { this = "IntegerLiteralTrackerConfiguration" }
565+ /** Gets a reference to an integer literal, as well as the origin of the integer literal. */
566+ private DataFlow:: Node keysizeTracker (
567+ DataFlow:: TypeTracker t , int keySize , DataFlow:: Node origin
568+ ) {
569+ t .start ( ) and
570+ result .asExpr ( ) .( IntegerLiteral ) .getValue ( ) = keySize and
571+ origin = result
572+ or
573+ // Due to bad performance when using normal setup with we have inlined that code and forced a join
574+ exists ( DataFlow:: TypeTracker t2 |
575+ exists ( DataFlow:: StepSummary summary |
576+ keysizeTracker_first_join ( t2 , keySize , origin , result , summary ) and
577+ t = t2 .append ( summary )
578+ )
579+ )
580+ }
571581
572- override predicate isSource ( DataFlow:: Node source ) {
573- source = DataFlow:: exprNode ( any ( IntegerLiteral size ) )
574- }
582+ pragma [ nomagic]
583+ private predicate keysizeTracker_first_join (
584+ DataFlow:: TypeTracker t2 , int keySize , DataFlow:: Node origin , DataFlow:: Node res ,
585+ DataFlow:: StepSummary summary
586+ ) {
587+ DataFlow:: StepSummary:: step ( keysizeTracker ( t2 , keySize , origin ) , res , summary )
588+ }
575589
576- override predicate isSink ( DataFlow :: Node sink ) {
577- sink = any ( KeyGeneration :: Range kg ) . getKeySizeArg ( )
578- }
590+ /** Gets a reference to an integer literal, as well as the origin of the integer literal. */
591+ private DataFlow :: Node keysizeTracker ( int keySize , DataFlow :: Node origin ) {
592+ result = keysizeTracker ( DataFlow :: TypeTracker :: end ( ) , keySize , origin )
579593 }
580594
581595 /**
@@ -596,11 +610,7 @@ module Cryptography {
596610 * explains how we obtained this specific key size.
597611 */
598612 int getKeySizeWithOrigin ( DataFlow:: Node origin ) {
599- exists ( IntegerLiteral size , IntegerLiteralTrackerConfiguration config |
600- origin .asExpr ( ) = size and
601- config .hasFlow ( origin , this .getKeySizeArg ( ) ) and
602- result = size .getValue ( )
603- )
613+ this .getKeySizeArg ( ) = keysizeTracker ( result , origin )
604614 }
605615
606616 /** Gets the minimum key size (in bits) for this algorithm to be considered secure. */
0 commit comments