Skip to content

Instantly share code, notes, and snippets.

@phamquyhai
Last active December 5, 2016 02:23
Show Gist options
  • Save phamquyhai/a5c6a69fa9a9f317549139f3d9052033 to your computer and use it in GitHub Desktop.
Save phamquyhai/a5c6a69fa9a9f317549139f3d9052033 to your computer and use it in GitHub Desktop.
Retrofit Trusting SSL with Certificate Pinner
# How to create Pin ?
# Using OpenSSL
# Example with api github
# Open terminal
# openssl s_client -connect api.github.com:443 | openssl x509 -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
# Get a key
CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add("api.github.com", "sha256/6wJsqVDF8K19zxfLxV5DGRneLyzso9adVdUN/exDacw=")
.build();
final OkHttpClient client = httpBuilder.certificatePinner(certificatePinner).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(END_POINT)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment