Skip to content

Commit

Permalink
add trustkit
Browse files Browse the repository at this point in the history
  • Loading branch information
titze committed Feb 18, 2025
1 parent 377844f commit 5eb14dd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Document/0x05g-Testing-Network-Communication.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ val client = OkHttpClient.Builder()
.build()
```

### Certificate Pinning using TrustKit

For Android versions prior to API 24, the [TrustKit library](https://github.com/datatheorem/TrustKit-Android) offers a backward-compatible solution. TrustKit validates pins against the cleaned certificate chain. However, improper configuration — such as enabling non-default options like CA pinning — can reintroduce [vulnerabilities akin to custom implementations](https://www.blackduck.com/blog/ineffective-certificate-pinning-implementations.html).

### Custom Certificate Pinning

Certificate pinning can be implemented manually by overriding `TrustManager` or `HostnameVerifier` in [`HttpsURLConnection`](https://developer.android.com/reference/java/net/HttpURLConnection). This approach is highly error-prone, as it often involves directly inspecting server-sent certificates via `getPeerCertificates()`, which returns unvalidated chains that [attackers can manipulate](https://www.blackduck.com/blog/ineffective-certificate-pinning-implementations.html).
Certificate pinning can be implemented manually by overriding `TrustManager` or `HostnameVerifier` in [`HttpsURLConnection`](https://developer.android.com/reference/java/net/HttpURLConnection). This approach is highly error-prone, as it often involves directly inspecting server-sent certificates via `getPeerCertificates()`, which returns unvalidated chains that [be manipulated by attackers](https://www.blackduck.com/blog/ineffective-certificate-pinning-implementations.html).

!!! warning "Implementing Certificate Pinning Manually"
Implementing certificate pinning manually has a high risk of adding functionality to your application that makes the app even less secure. If you are adding this manually, take extreme care of implementing this correctly.
Expand Down

0 comments on commit 5eb14dd

Please sign in to comment.