6
6
7
7
import python
8
8
private import semmle.python.dataflow.new.DataFlow
9
- private import semmle.python.dataflow.new.DataFlowOnlyInternalUse
10
9
private import semmle.python.dataflow.new.RemoteFlowSources
11
10
private import semmle.python.dataflow.new.TaintTracking
12
11
private import semmle.python.Frameworks
@@ -563,19 +562,34 @@ module Cryptography {
563
562
564
563
/** Provides classes for modeling new key-pair generation APIs. */
565
564
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
+ }
571
581
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
+ }
575
589
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 )
579
593
}
580
594
581
595
/**
@@ -596,11 +610,7 @@ module Cryptography {
596
610
* explains how we obtained this specific key size.
597
611
*/
598
612
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 )
604
614
}
605
615
606
616
/** Gets the minimum key size (in bits) for this algorithm to be considered secure. */
0 commit comments