The library allows you to pin the server certificates by using the HttpsURLConnection. You will be able to validate the certificate chain and ensure that one of the pins in the specified/trusted set of SubjectPublicKeyInfos appears in the valid certificate chain.
- 1. Pinning the connection with HttpsPinner.
Passing the IPinnerCallback implementing class to the HttpsPinner: httpsPinner.getPinnedHttpsConnectionTask(this).
private void execPinnedConection()
{
String[] trustedPinsSet = new String[] {"a36012xcc17c231ac1ag6b788e610c8k75418t543"};
String serverUrl = "https://YOUR_SERVER_URL";
HttpsPinner httpsPinner = new HttpsPinner(trustedPinsSet,false);
PinnedConnectionRequest pinnedConnectionRequest = new PinnedConnectionRequest("GET",serverUrl);
httpsPinner.getPinnedHttpsConnectionTask(this).execute(pinnedConnectionRequest);
}
- 2. Add your logic in the iplementing IPinnerCallback class:
@Override
public void onTaskPinningSuccess(PinnedConnectionResponse pinnedConnectionResponse)
{
//Your logic on connection pinning success ...//
}
@Override
public void onTaskPinningFailure(PinnedConnectionResponse pinnedConnectionResponse)
{
//Your logic on connection pinning failure ...//
}
Aivars Dalderis
- e-mail: aivars.dalderis@gmail.com
- LinkedIn: Aivars Dalderis LinkedIn