Certificate pinning with OkHttp

Warning: Illegal string offset 'language' in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510 Warning: ksort() expects parameter 1 to be array, string given in /var/www/vhosts/ansuz.nl/subdomains/blog/httpdocs/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513

A while back I wrote about “Using SSL right on Android“. If you are using OkHttp and/or Retrofit, this should be quite simple to implement. You can use the CertificatePinner class when building your OkHttpClient instance.

Example:

  1. CertificatePinner certificatePinner = new CertificatePinner.Builder()
  2.   .add("example.com", "your_pin")
  3.   .build();
  4.  
  5. new OkHttpClient.Builder()
  6.   .certificatePinner(certificatePinner)
  7.   .build();

More details about HTTPS and certificate pinning with OkHttp can be found on their Wiki, as well as a full example.