@@ -22,7 +22,7 @@ private module CryptographyModel {
2222 * Gets a predefined curve class from
2323 * `cryptography.hazmat.primitives.asymmetric.ec` with a specific key size (in bits).
2424 */
25- private DataFlow :: Node curveClassWithKeySize ( int keySize ) {
25+ private API :: Node predefinedCurveClass ( int keySize ) {
2626 exists ( string curveName |
2727 result =
2828 API:: moduleImport ( "cryptography" )
@@ -31,7 +31,6 @@ private module CryptographyModel {
3131 .getMember ( "asymmetric" )
3232 .getMember ( "ec" )
3333 .getMember ( curveName )
34- .getAUse ( )
3534 |
3635 // obtained by manually looking at source code in
3736 // https://github.com/pyca/cryptography/blob/cba69f1922803f4f29a3fde01741890d88b8e217/src/cryptography/hazmat/primitives/asymmetric/ec.py#L208-L300
@@ -75,13 +74,30 @@ private module CryptographyModel {
7574 )
7675 }
7776
77+ /** Gets a reference to a predefined curve class with a specific key size (in bits), as well as the origin of the class. */
78+ private DataFlow:: LocalSourceNode curveClassWithKeySize (
79+ DataFlow:: TypeTracker t , int keySize , DataFlow:: Node origin
80+ ) {
81+ t .start ( ) and
82+ result = predefinedCurveClass ( keySize ) .getAnImmediateUse ( ) and
83+ origin = result
84+ or
85+ exists ( DataFlow:: TypeTracker t2 |
86+ result = curveClassWithKeySize ( t2 , keySize , origin ) .track ( t2 , t )
87+ )
88+ }
89+
90+ /** Gets a reference to a predefined curve class with a specific key size (in bits), as well as the origin of the class. */
91+ DataFlow:: Node curveClassWithKeySize ( int keySize , DataFlow:: Node origin ) {
92+ curveClassWithKeySize ( DataFlow:: TypeTracker:: end ( ) , keySize , origin ) .flowsTo ( result )
93+ }
94+
7895 /** Gets a reference to a predefined curve class instance with a specific key size (in bits), as well as the origin of the class. */
7996 private DataFlow:: LocalSourceNode curveClassInstanceWithKeySize (
8097 DataFlow:: TypeTracker t , int keySize , DataFlow:: Node origin
8198 ) {
8299 t .start ( ) and
83- result .( DataFlow:: CallCfgNode ) .getFunction ( ) = curveClassWithKeySize ( keySize ) and
84- origin = result
100+ result .( DataFlow:: CallCfgNode ) .getFunction ( ) = curveClassWithKeySize ( keySize , origin )
85101 or
86102 exists ( DataFlow:: TypeTracker t2 |
87103 result = curveClassInstanceWithKeySize ( t2 , keySize , origin ) .track ( t2 , t )
@@ -164,6 +180,8 @@ private module CryptographyModel {
164180
165181 override int getKeySizeWithOrigin ( DataFlow:: Node origin ) {
166182 this .getCurveArg ( ) = Ecc:: curveClassInstanceWithKeySize ( result , origin )
183+ or
184+ this .getCurveArg ( ) = Ecc:: curveClassWithKeySize ( result , origin )
167185 }
168186
169187 // Note: There is not really a key-size argument, since it's always specified by the curve.
0 commit comments