Last active
December 5, 2016 02:23
-
-
Save phamquyhai/a5c6a69fa9a9f317549139f3d9052033 to your computer and use it in GitHub Desktop.
Retrofit Trusting SSL with Certificate Pinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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