Skip to content

Commit 53c4ada

Browse files
Add okhttp tests
1 parent c32dc1e commit 53c4ada

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.app"
3+
android:installLocation="auto"
4+
android:versionCode="1"
5+
android:versionName="0.1" >
6+
7+
<application android:networkSecurityConfig="@xml/NetworkSecurityConfig">
8+
</application>
9+
10+
</manifest>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import okhttp3.OkHttpClient;
2+
import okhttp3.CertificatePinner;
3+
import okhttp3.Request;
4+
5+
class Test{
6+
void test1() throws Exception {
7+
CertificatePinner certificatePinner = new CertificatePinner.Builder()
8+
.add("good.example.com", "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
9+
.build();
10+
OkHttpClient client = OkHttpClient.Builder()
11+
.certificatePinner(certificatePinner)
12+
.build();
13+
14+
client.newCall(new Request.Builder().url("https://good.example.com").build()).execute();
15+
client.newCall(new Request.Builder().url("https://bad.example.com").build()).execute(); // $hasUntrustedResult
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/google-android-9.0.0:${testdir}/../../../../../stubs/okhttp-4.9.3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
4+
</network-security-config>

java/ql/test/query-tests/security/CWE-295/AndroidMissingCertificatePinning_/Test3/test.expected

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java
2+
import TestUtilities.InlineExpectationsTest
3+
import semmle.code.java.security.AndroidCertificatePinningQuery
4+
5+
class Test extends InlineExpectationsTest {
6+
Test() { this = "AndroidMissingCertificatePinningTest" }
7+
8+
override string getARelevantTag() { result = ["hasNoTrustedResult", "hasUntrustedResult"] }
9+
10+
override predicate hasActualResult(Location loc, string el, string tag, string value) {
11+
exists(DataFlow::Node node |
12+
missingPinning(node) and
13+
loc = node.getLocation() and
14+
el = node.toString() and
15+
value = "" and
16+
(
17+
if exists(string x | trustedDomain(x))
18+
then tag = "hasUntrustedResult"
19+
else tag = "hasNoTrustedResult"
20+
)
21+
)
22+
}
23+
}

0 commit comments

Comments
 (0)