File tree Expand file tree Collapse file tree 6 files changed +34
-13
lines changed
src/semmle/code/java/security
test/library-tests/Encryption Expand file tree Collapse file tree 6 files changed +34
-13
lines changed Original file line number Diff line number Diff line change @@ -220,11 +220,16 @@ abstract class JavaSecurityAlgoSpec extends CryptoAlgoSpec { }
220220class JavaSecurityMessageDigest extends JavaSecurityAlgoSpec {
221221 JavaSecurityMessageDigest ( ) {
222222 exists ( Constructor c | c .getAReference ( ) = this |
223- c .getDeclaringType ( ) .getQualifiedName ( ) = "java.security.MessageDigest"
223+ c .getDeclaringType ( ) .hasQualifiedName ( "java.security" , "MessageDigest" )
224+ )
225+ or
226+ exists ( Method m | m .getAReference ( ) = this |
227+ m .getDeclaringType ( ) .hasQualifiedName ( "java.security" , "MessageDigest" ) and
228+ m .getName ( ) = "getInstance"
224229 )
225230 }
226231
227- override Expr getAlgoSpec ( ) { result = this .( ConstructorCall ) .getArgument ( 0 ) }
232+ override Expr getAlgoSpec ( ) { result = this .( Call ) .getArgument ( 0 ) }
228233}
229234
230235class JavaSecuritySignature extends JavaSecurityAlgoSpec {
Original file line number Diff line number Diff line change 22
33import java .util .Arrays ;
44import java .util .List ;
5+ import java .security .MessageDigest ;
56
67class Test {
78 List <String > badStrings = Arrays .asList (
8- "DES" ,
9+ "DES" ,
910 "des" ,
1011 "des_function" ,
1112 "function_using_des" ,
1213 "EncryptWithDES" );
13-
14+
1415 List <String > goodStrings = Arrays .asList (
1516 "AES" ,
1617 "AES_function" ,
1718 // false negative - can't think of a good way to detect this without
1819 // catching things we shouldn't
1920 "AESEncryption" );
20-
21+
2122 List <String > unknownStrings = Arrays .asList (
2223 // not a use of RC2 (camelCase is tricky)
2324 "GetPrc2" ,
@@ -29,4 +30,12 @@ class Test {
2930 "species" ,
3031 // can't detect unknown algorithms
3132 "SOMENEWACRONYM" );
32- }
33+ public static abstract class SomeDigest extends MessageDigest {
34+ public SomeDigest () {
35+ super ("some" );
36+ }
37+ }
38+ public void test () throws Exception {
39+ MessageDigest .getInstance ("another" );
40+ }
41+ }
Original file line number Diff line number Diff line change 1- | Test.java:8 :4:8 :8 | "DES" |
2- | Test.java:9 :4:9 :8 | "des" |
3- | Test.java:10 :4:10 :17 | "des_function" |
4- | Test.java:11 :4:11 :23 | "function_using_des" |
5- | Test.java:12 :4:12 :19 | "EncryptWithDES" |
1+ | Test.java:9 :4:9 :8 | "DES" |
2+ | Test.java:10 :4:10 :8 | "des" |
3+ | Test.java:11 :4:11 :17 | "des_function" |
4+ | Test.java:12 :4:12 :23 | "function_using_des" |
5+ | Test.java:13 :4:13 :19 | "EncryptWithDES" |
Original file line number Diff line number Diff line change 1+ | Test.java:35:4:35:17 | super(...) | Test.java:35:10:35:15 | "some" |
2+ | Test.java:39:3:39:38 | getInstance(...) | Test.java:39:29:39:37 | "another" |
Original file line number Diff line number Diff line change 1+ import default
2+ import semmle.code.java.security.Encryption
3+
4+ from CryptoAlgoSpec s
5+ select s , s .getAlgoSpec ( )
Original file line number Diff line number Diff line change 1- | Test.java:15 :4:15 :8 | "AES" |
2- | Test.java:16 :4:16 :17 | "AES_function" |
1+ | Test.java:16 :4:16 :8 | "AES" |
2+ | Test.java:17 :4:17 :17 | "AES_function" |
You can’t perform that action at this time.
0 commit comments