@@ -127,7 +127,6 @@ abstract class CryptographicAlgorithm extends TCryptographicAlgorithm {
127127 bindingset [ name]
128128 predicate matchesName ( string name ) {
129129 exists ( name .regexpReplaceAll ( "[-_]" , "" ) .regexpFind ( "(?i)\\Q" + getName ( ) + "\\E" , _, _) )
130- // name.toUpperCase().regexpReplaceAll("[-_ ]", "").regexpMatch(".*" + getName() + ".*")
131130 }
132131
133132 /**
@@ -194,70 +193,53 @@ abstract class CryptographicOperation extends DataFlow::Node {
194193}
195194
196195/**
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.
199197 */
200198class Md5 extends CryptographicOperation , DataFlow:: CallNode {
201- Expr input ;
202- CryptographicAlgorithm algorithm ;
199+ Md5 ( ) { getTarget ( ) .hasQualifiedName ( "crypto/md5" , [ "New" , "Sum" ] ) }
203200
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 ( ) }
210202
211- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
203+ override CryptographicAlgorithm getAlgorithm ( ) {
204+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
205+ }
212206}
213207
214208/**
215- * Class that checks for use of Sha1 package.
209+ * Models cryptographic operations of the `crypto/sha1` package.
216210 */
217211class Sha1 extends CryptographicOperation , DataFlow:: CallNode {
218- Expr input ;
219- CryptographicAlgorithm algorithm ;
212+ Sha1 ( ) { getTarget ( ) .hasQualifiedName ( "crypto/sha1" , [ "New" , "Sum" ] ) }
220213
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 ( ) }
227215
228- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
216+ override CryptographicAlgorithm getAlgorithm ( ) {
217+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
218+ }
229219}
230220
231221/**
232- * Class that checks for use of Des package.
222+ * Models cryptographic operations of the `crypto/des` package.
233223 */
234224class Des extends CryptographicOperation , DataFlow:: CallNode {
235- Expr input ;
236- CryptographicAlgorithm algorithm ;
225+ Des ( ) { getTarget ( ) .hasQualifiedName ( "crypto/des" , [ "NewCipher" , "NewTripleDESCipher" ] ) }
237226
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 ( ) }
244228
245- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
229+ override CryptographicAlgorithm getAlgorithm ( ) {
230+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
231+ }
246232}
247233
248234/**
249- * Class that checks for use of Rc4 package.
235+ * Models cryptographic operations of the `crypto/rc4` package.
250236 */
251237class Rc4 extends CryptographicOperation , DataFlow:: CallNode {
252- Expr input ;
253- CryptographicAlgorithm algorithm ;
238+ Rc4 ( ) { getTarget ( ) .hasQualifiedName ( "crypto/rc4" , [ "NewCipher" ] ) }
254239
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 ( ) }
261241
262- override CryptographicAlgorithm getAlgorithm ( ) { result = algorithm }
242+ override CryptographicAlgorithm getAlgorithm ( ) {
243+ result .matchesName ( this .getTarget ( ) .getPackage ( ) .getName ( ) )
244+ }
263245}
0 commit comments