Skip to content

Commit 9ae652d

Browse files
Add tests
1 parent 41bdd6d commit 9ae652d

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// BAD: No padding scheme is used
2-
Cipher rsa = Cipher.getInstance("RSA/ECB/NoPadding")
2+
Cipher rsa = Cipher.getInstance("RSA/ECB/NoPadding");
33
...
44

55
//GOOD: OAEP padding is used
6-
Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding")
6+
Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
77
...

java/ql/test/query-tests/security/CWE-780/RsaWithoutOaepTest.expected

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import javax.crypto.Cipher;
2+
3+
class RsaWithoutOaep {
4+
public void test() throws Exception {
5+
Cipher rsaBad = Cipher.getInstance("RSA/ECB/NoPadding"); // $hasResult
6+
7+
Cipher rsaGood = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
8+
}
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java
2+
import TestUtilities.InlineExpectationsTest
3+
import semmle.code.java.security.RsaWithoutOaepQuery
4+
5+
class HasResult extends InlineExpectationsTest {
6+
HasResult() { this = "HasResult" }
7+
8+
override string getARelevantTag() { result = "hasResult" }
9+
10+
override predicate hasActualResult(Location location, string element, string tag, string value) {
11+
tag = "hasResult" and
12+
value = "" and
13+
exists(MethodAccess ma |
14+
rsaWithoutOaepCall(ma) and
15+
location = ma.getLocation() and
16+
element = ma.toString()
17+
)
18+
}
19+
}

0 commit comments

Comments
 (0)