@@ -22,7 +22,7 @@ private module CryptographyModel {
22
22
* Gets a predefined curve class from
23
23
* `cryptography.hazmat.primitives.asymmetric.ec` with a specific key size (in bits).
24
24
*/
25
- private API:: Node predefinedCurveClass ( int keySize ) {
25
+ API:: Node predefinedCurveClass ( int keySize ) {
26
26
exists ( string curveName |
27
27
result =
28
28
API:: moduleImport ( "cryptography" )
@@ -73,41 +73,6 @@ private module CryptographyModel {
73
73
curveName = "BrainpoolP512R1" and keySize = 512
74
74
)
75
75
}
76
-
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:: TypeTrackingNode 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
-
95
- /** Gets a reference to a predefined curve class instance with a specific key size (in bits), as well as the origin of the class. */
96
- private DataFlow:: TypeTrackingNode curveClassInstanceWithKeySize (
97
- DataFlow:: TypeTracker t , int keySize , DataFlow:: Node origin
98
- ) {
99
- t .start ( ) and
100
- result .( DataFlow:: CallCfgNode ) .getFunction ( ) = curveClassWithKeySize ( keySize , origin )
101
- or
102
- exists ( DataFlow:: TypeTracker t2 |
103
- result = curveClassInstanceWithKeySize ( t2 , keySize , origin ) .track ( t2 , t )
104
- )
105
- }
106
-
107
- /** Gets a reference to a predefined curve class instance with a specific key size (in bits), as well as the origin of the class. */
108
- DataFlow:: Node curveClassInstanceWithKeySize ( int keySize , DataFlow:: Node origin ) {
109
- curveClassInstanceWithKeySize ( DataFlow:: TypeTracker:: end ( ) , keySize , origin ) .flowsTo ( result )
110
- }
111
76
}
112
77
113
78
// ---------------------------------------------------------------------------
@@ -179,9 +144,13 @@ private module CryptographyModel {
179
144
DataFlow:: Node getCurveArg ( ) { result in [ this .getArg ( 0 ) , this .getArgByName ( "curve" ) ] }
180
145
181
146
override int getKeySizeWithOrigin ( DataFlow:: Node origin ) {
182
- this .getCurveArg ( ) = Ecc:: curveClassInstanceWithKeySize ( result , origin )
183
- or
184
- this .getCurveArg ( ) = Ecc:: curveClassWithKeySize ( result , origin )
147
+ exists ( API:: Node n |
148
+ n = Ecc:: predefinedCurveClass ( result ) and origin = n .getAnImmediateUse ( )
149
+ |
150
+ this .getCurveArg ( ) = n .getAUse ( )
151
+ or
152
+ this .getCurveArg ( ) = n .getReturn ( ) .getAUse ( )
153
+ )
185
154
}
186
155
187
156
// Note: There is not really a key-size argument, since it's always specified by the curve.
@@ -202,9 +171,8 @@ private module CryptographyModel {
202
171
}
203
172
204
173
/** Gets a reference to a Cipher instance using algorithm with `algorithmName`. */
205
- DataFlow:: TypeTrackingNode cipherInstance ( DataFlow:: TypeTracker t , string algorithmName ) {
206
- t .start ( ) and
207
- exists ( DataFlow:: CallCfgNode call | result = call |
174
+ API:: Node cipherInstance ( string algorithmName ) {
175
+ exists ( API:: CallNode call | result = call .getReturn ( ) |
208
176
call =
209
177
API:: moduleImport ( "cryptography" )
210
178
.getMember ( "hazmat" )
@@ -216,47 +184,6 @@ private module CryptographyModel {
216
184
call .getArg ( 0 ) , call .getArgByName ( "algorithm" )
217
185
]
218
186
)
219
- or
220
- exists ( DataFlow:: TypeTracker t2 | result = cipherInstance ( t2 , algorithmName ) .track ( t2 , t ) )
221
- }
222
-
223
- /** Gets a reference to a Cipher instance using algorithm with `algorithmName`. */
224
- DataFlow:: Node cipherInstance ( string algorithmName ) {
225
- cipherInstance ( DataFlow:: TypeTracker:: end ( ) , algorithmName ) .flowsTo ( result )
226
- }
227
-
228
- /** Gets a reference to the encryptor of a Cipher instance using algorithm with `algorithmName`. */
229
- DataFlow:: TypeTrackingNode cipherEncryptor ( DataFlow:: TypeTracker t , string algorithmName ) {
230
- t .start ( ) and
231
- result .( DataFlow:: MethodCallNode ) .calls ( cipherInstance ( algorithmName ) , "encryptor" )
232
- or
233
- exists ( DataFlow:: TypeTracker t2 | result = cipherEncryptor ( t2 , algorithmName ) .track ( t2 , t ) )
234
- }
235
-
236
- /**
237
- * Gets a reference to the encryptor of a Cipher instance using algorithm with `algorithmName`.
238
- *
239
- * You obtain an encryptor by using the `encryptor()` method on a Cipher instance.
240
- */
241
- DataFlow:: Node cipherEncryptor ( string algorithmName ) {
242
- cipherEncryptor ( DataFlow:: TypeTracker:: end ( ) , algorithmName ) .flowsTo ( result )
243
- }
244
-
245
- /** Gets a reference to the dncryptor of a Cipher instance using algorithm with `algorithmName`. */
246
- DataFlow:: TypeTrackingNode cipherDecryptor ( DataFlow:: TypeTracker t , string algorithmName ) {
247
- t .start ( ) and
248
- result .( DataFlow:: MethodCallNode ) .calls ( cipherInstance ( algorithmName ) , "decryptor" )
249
- or
250
- exists ( DataFlow:: TypeTracker t2 | result = cipherDecryptor ( t2 , algorithmName ) .track ( t2 , t ) )
251
- }
252
-
253
- /**
254
- * Gets a reference to the decryptor of a Cipher instance using algorithm with `algorithmName`.
255
- *
256
- * You obtain an decryptor by using the `decryptor()` method on a Cipher instance.
257
- */
258
- DataFlow:: Node cipherDecryptor ( string algorithmName ) {
259
- cipherDecryptor ( DataFlow:: TypeTracker:: end ( ) , algorithmName ) .flowsTo ( result )
260
187
}
261
188
262
189
/**
@@ -267,11 +194,12 @@ private module CryptographyModel {
267
194
string algorithmName ;
268
195
269
196
CryptographyGenericCipherOperation ( ) {
270
- exists ( DataFlow:: Node object , string method |
271
- object in [ cipherEncryptor ( algorithmName ) , cipherDecryptor ( algorithmName ) ] and
272
- method in [ "update" , "update_into" ] and
273
- this .calls ( object , method )
274
- )
197
+ this =
198
+ cipherInstance ( algorithmName )
199
+ .getMember ( [ "decryptor" , "encryptor" ] )
200
+ .getReturn ( )
201
+ .getMember ( [ "update" , "update_into" ] )
202
+ .getACall ( )
275
203
}
276
204
277
205
override Cryptography:: CryptographicAlgorithm getAlgorithm ( ) {
@@ -298,9 +226,8 @@ private module CryptographyModel {
298
226
}
299
227
300
228
/** Gets a reference to a Hash instance using algorithm with `algorithmName`. */
301
- private DataFlow:: TypeTrackingNode hashInstance ( DataFlow:: TypeTracker t , string algorithmName ) {
302
- t .start ( ) and
303
- exists ( DataFlow:: CallCfgNode call | result = call |
229
+ private API:: Node hashInstance ( string algorithmName ) {
230
+ exists ( API:: CallNode call | result = call .getReturn ( ) |
304
231
call =
305
232
API:: moduleImport ( "cryptography" )
306
233
.getMember ( "hazmat" )
@@ -312,13 +239,6 @@ private module CryptographyModel {
312
239
call .getArg ( 0 ) , call .getArgByName ( "algorithm" )
313
240
]
314
241
)
315
- or
316
- exists ( DataFlow:: TypeTracker t2 | result = hashInstance ( t2 , algorithmName ) .track ( t2 , t ) )
317
- }
318
-
319
- /** Gets a reference to a Hash instance using algorithm with `algorithmName`. */
320
- DataFlow:: Node hashInstance ( string algorithmName ) {
321
- hashInstance ( DataFlow:: TypeTracker:: end ( ) , algorithmName ) .flowsTo ( result )
322
242
}
323
243
324
244
/**
@@ -328,7 +248,9 @@ private module CryptographyModel {
328
248
DataFlow:: MethodCallNode {
329
249
string algorithmName ;
330
250
331
- CryptographyGenericHashOperation ( ) { this .calls ( hashInstance ( algorithmName ) , "update" ) }
251
+ CryptographyGenericHashOperation ( ) {
252
+ this = hashInstance ( algorithmName ) .getMember ( "update" ) .getACall ( )
253
+ }
332
254
333
255
override Cryptography:: CryptographicAlgorithm getAlgorithm ( ) {
334
256
result .matchesName ( algorithmName )
0 commit comments