Created
June 26, 2017 06:23
-
-
Save omerlh/8ddafbcffc1cc95854d6381ac8c81476 to your computer and use it in GitHub Desktop.
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
import com.datatheorem.android.trustkit.TrustKit; | |
import com.datatheorem.android.trustkit.config.PublicKeyPin; | |
import javax.inject.Inject; | |
import okhttp3.CertificatePinner; | |
import okhttp3.OkHttpClient; | |
public class OkHttpCertPin { | |
private final TrustKit mTrustKit; | |
@Inject | |
public OkHttpCertPin(TrustKit trustKit) | |
{ | |
mTrustKit = trustKit; | |
} | |
public OkHttpClient extend(OkHttpClient currentClient, String hostName) { | |
CertificatePinner.Builder certificatePinnerBuilder = new CertificatePinner.Builder(); | |
for (PublicKeyPin key : mTrustKit.getConfiguration().getPolicyForHostname(hostName).getPublicKeyPins()) { | |
certificatePinnerBuilder.add(hostName, "sha256/" + key.toString()); | |
} | |
return currentClient.newBuilder().certificatePinner(certificatePinnerBuilder.build()).build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to match with @omerlh gist, here's the
MainActivity.java
for react native to use SSL Pinning on AndroidUsing RN 0.51 with Axios