@@ -127,7 +127,6 @@ abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
127
127
bindingset [ name]
128
128
predicate matchesName ( string name ) {
129
129
exists ( name .regexpReplaceAll ( "[-_]" , "" ) .regexpFind ( "(?i)\\Q" + getName ( ) + "\\E" , _, _) )
130
- // name.toUpperCase().regexpReplaceAll("[-_ ]", "").regexpMatch(".*" + getName() + ".*")
131
130
}
132
131
133
132
/**
@@ -194,70 +193,53 @@ abstract class CryptographicOperation extends DataFlow::Node {
194
193
}
195
194
196
195
/**
197
- * Below are the cryptographic functions that have been implemented so far for this library.
198
- * Class that checks for use of Md5 package.
196
+ * Models cryptographic operations of the `crypto/md5` package.
199
197
*/
200
198
class Md5 extends CryptographicOperation , DataFlow:: CallNode {
201
- Expr input ;
202
- CryptographicAlgorithm algorithm ;
199
+ Md5 ( ) { getTarget ( ) .hasQualifiedName ( "crypto/md5" , [ "New" , "Sum" ] ) }
203
200
204
- Md5 ( ) {
205
- getTarget ( ) .hasQualifiedName ( "crypto/md5" , [ "New" , "Sum" ] ) and
206
- this .getArgument ( 0 ) .asExpr ( ) = input
207
- }
208
-
209
- override Expr getInput ( ) { result = input }
201
+ override Expr getInput ( ) { result = this .getArgument ( 0 ) .asExpr ( ) }
210
202
211
- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
203
+ override CryptographicAlgorithm getAlgorithm ( ) {
204
+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
205
+ }
212
206
}
213
207
214
208
/**
215
- * Class that checks for use of Sha1 package.
209
+ * Models cryptographic operations of the `crypto/sha1` package.
216
210
*/
217
211
class Sha1 extends CryptographicOperation , DataFlow:: CallNode {
218
- Expr input ;
219
- CryptographicAlgorithm algorithm ;
212
+ Sha1 ( ) { getTarget ( ) .hasQualifiedName ( "crypto/sha1" , [ "New" , "Sum" ] ) }
220
213
221
- Sha1 ( ) {
222
- getTarget ( ) .hasQualifiedName ( "crypto/sha1" , [ "New" , "Sum" ] ) and
223
- this .getArgument ( 0 ) .asExpr ( ) = input
224
- }
225
-
226
- override Expr getInput ( ) { result = input }
214
+ override Expr getInput ( ) { result = this .getArgument ( 0 ) .asExpr ( ) }
227
215
228
- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
216
+ override CryptographicAlgorithm getAlgorithm ( ) {
217
+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
218
+ }
229
219
}
230
220
231
221
/**
232
- * Class that checks for use of Des package.
222
+ * Models cryptographic operations of the `crypto/des` package.
233
223
*/
234
224
class Des extends CryptographicOperation , DataFlow:: CallNode {
235
- Expr input ;
236
- CryptographicAlgorithm algorithm ;
225
+ Des ( ) { getTarget ( ) .hasQualifiedName ( "crypto/des" , [ "NewCipher" , "NewTripleDESCipher" ] ) }
237
226
238
- Des ( ) {
239
- getTarget ( ) .hasQualifiedName ( "crypto/des" , [ "NewCipher" , "NewTripleDESCipher" ] ) and
240
- this .getArgument ( 0 ) .asExpr ( ) = input
241
- }
242
-
243
- override Expr getInput ( ) { result = input }
227
+ override Expr getInput ( ) { result = this .getArgument ( 0 ) .asExpr ( ) }
244
228
245
- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
229
+ override CryptographicAlgorithm getAlgorithm ( ) {
230
+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
231
+ }
246
232
}
247
233
248
234
/**
249
- * Class that checks for use of Rc4 package.
235
+ * Models cryptographic operations of the `crypto/rc4` package.
250
236
*/
251
237
class Rc4 extends CryptographicOperation , DataFlow:: CallNode {
252
- Expr input ;
253
- CryptographicAlgorithm algorithm ;
238
+ Rc4 ( ) { getTarget ( ) .hasQualifiedName ( "crypto/rc4" , [ "NewCipher" ] ) }
254
239
255
- Rc4 ( ) {
256
- getTarget ( ) .hasQualifiedName ( "crypto/rc4" , [ "NewCipher" ] ) and
257
- this .getArgument ( 0 ) .asExpr ( ) = input
258
- }
259
-
260
- override Expr getInput ( ) { result = input }
240
+ override Expr getInput ( ) { result = this .getArgument ( 0 ) .asExpr ( ) }
261
241
262
- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
242
+ override CryptographicAlgorithm getAlgorithm ( ) {
243
+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
244
+ }
263
245
}
0 commit comments