Skip to content

Commit 8826eaf

Browse files
committed
Move test case to query tests
1 parent afefccf commit 8826eaf

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
edges
22
nodes
33
| Test.java:34:48:34:52 | "foo" | semmle.label | "foo" |
4+
| WeakHashing.java:15:55:15:83 | getProperty(...) | semmle.label | getProperty(...) |
45
subpaths
56
#select
67
| Test.java:34:21:34:53 | new SecretKeySpec(...) | Test.java:34:48:34:52 | "foo" | Test.java:34:48:34:52 | "foo" | Cryptographic algorithm $@ may not be secure, consider using a different algorithm. | Test.java:34:48:34:52 | "foo" | foo |
8+
| WeakHashing.java:15:29:15:84 | getInstance(...) | WeakHashing.java:15:55:15:83 | getProperty(...) | WeakHashing.java:15:55:15:83 | getProperty(...) | Cryptographic algorithm $@ may not be secure, consider using a different algorithm. | WeakHashing.java:15:55:15:83 | getProperty(...) | MD5 |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test.cwe327.semmle.tests;
2+
3+
import java.util.Properties;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.security.MessageDigest;
7+
import java.security.NoSuchAlgorithmException;
8+
9+
public class WeakHashing {
10+
void hashing() throws NoSuchAlgorithmException, IOException {
11+
java.util.Properties props = new java.util.Properties();
12+
props.load(new FileInputStream("example.properties"));
13+
14+
// BAD: Using a weak hashing algorithm
15+
MessageDigest bad = MessageDigest.getInstance(props.getProperty("hashAlg1"));
16+
17+
// GOOD: Using a strong hashing algorithm
18+
MessageDigest ok = MessageDigest.getInstance(props.getProperty("hashAlg2"));
19+
}
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hashAlg1=MD5
2+
hashAlg2=SHA-256

0 commit comments

Comments
 (0)