Skip to content

Tabishahmad/Android-SSL-Pinning-Sample

Repository files navigation

Android SSL Pinning Sample

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.

How it works

  • Loads a trusted certificate bundled in the app (res/raw) into a KeyStore
  • Builds a TrustManager and custom SSLContext scoped to that certificate
  • Configures OkHttpClient with the pinned SSLSocketFactory and a HostnameVerifier so requests only succeed against the expected host and certificate

Features

  • 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)

Tech stack

Kotlin OkHttp javax.net.ssl

Running it

git clone https://github.com/Tabishahmad/Android-SSL-Pinning-Sample.git

Open in Android Studio and run.

Write-up

Full walkthrough: Understanding SSL Certificates and Implementing SSL Pinning in Android Applications

About

SSL/certificate pinning demo with OkHttp, protecting HTTPS requests against man-in-the-middle attacks

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages