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 { }
220
220
class JavaSecurityMessageDigest extends JavaSecurityAlgoSpec {
221
221
JavaSecurityMessageDigest ( ) {
222
222
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"
224
229
)
225
230
}
226
231
227
- override Expr getAlgoSpec ( ) { result = this .( ConstructorCall ) .getArgument ( 0 ) }
232
+ override Expr getAlgoSpec ( ) { result = this .( Call ) .getArgument ( 0 ) }
228
233
}
229
234
230
235
class JavaSecuritySignature extends JavaSecurityAlgoSpec {
Original file line number Diff line number Diff line change 2
2
3
3
import java .util .Arrays ;
4
4
import java .util .List ;
5
+ import java .security .MessageDigest ;
5
6
6
7
class Test {
7
8
List <String > badStrings = Arrays .asList (
8
- "DES" ,
9
+ "DES" ,
9
10
"des" ,
10
11
"des_function" ,
11
12
"function_using_des" ,
12
13
"EncryptWithDES" );
13
-
14
+
14
15
List <String > goodStrings = Arrays .asList (
15
16
"AES" ,
16
17
"AES_function" ,
17
18
// false negative - can't think of a good way to detect this without
18
19
// catching things we shouldn't
19
20
"AESEncryption" );
20
-
21
+
21
22
List <String > unknownStrings = Arrays .asList (
22
23
// not a use of RC2 (camelCase is tricky)
23
24
"GetPrc2" ,
@@ -29,4 +30,12 @@ class Test {
29
30
"species" ,
30
31
// can't detect unknown algorithms
31
32
"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