A focused Android sample demonstrating SSL/certificate pinning with OkHttp — securing HTTPS connections against man-in-the-middle attacks by trusting only a specific, bundled certificate instead of any CA-signed cert.
- Loads a trusted certificate bundled in the app (
res/raw) into aKeyStore - Builds a
TrustManagerand customSSLContextscoped to that certificate - Configures
OkHttpClientwith the pinnedSSLSocketFactoryand aHostnameVerifierso requests only succeed against the expected host and certificate
- Makes a live HTTPS request to a test endpoint (httpbin.org) using the pinned client
- Demonstrates both the success path (valid pinned cert) and failure path (rejected on mismatch)
Kotlin OkHttp javax.net.ssl
git clone https://github.com/Tabishahmad/Android-SSL-Pinning-Sample.gitOpen in Android Studio and run.
Full walkthrough: Understanding SSL Certificates and Implementing SSL Pinning in Android Applications