Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinning Support for Volley #21

Open
ajinabraham opened this issue Dec 17, 2014 · 3 comments
Open

Pinning Support for Volley #21

ajinabraham opened this issue Dec 17, 2014 · 3 comments

Comments

@ajinabraham
Copy link

Is there some way i can add SSL pinning support to volley(http://developer.android.com/training/volley/index.html).

@DirtyJerz
Copy link

Did you ever figure this out?

@ajinabraham
Copy link
Author

As of now what I do as a workaround is to run a separate thread every 30 seconds which will send a Pinned request using Android's native SSL library. So if anything goes wrong, It will kill the app.

Here is the Sample code.
try {
String[] pins = "pin_here";
URL url = new URL("URL_here");
HttpsURLConnection connection = PinningHelper.getPinnedHttpsURLConnection(getBaseContext(), pins, url);
byte[] data = new byte[4096];
connection.getInputStream().read(data);
YLog.i("SSL", "Success " + new String(data));
}
catch (SSLKeyException e) {
android.os.Process.killProcess(android.os.Process.myPid());
}
catch (SSLHandshakeException e) {
android.os.Process.killProcess(android.os.Process.myPid());
}
catch (SSLProtocolException e) {
android.os.Process.killProcess(android.os.Process.myPid());
}
catch (SSLPeerUnverifiedException e) {
android.os.Process.killProcess(android.os.Process.myPid());
}
catch (IOException ioe) {
YLog.i("SSL", "IOException: Not Success: " + ioe.getMessage().toString());
} catch (StringIndexOutOfBoundsException sio) {
YLog.i("SSL", "StringIndexOutOfBoundsException: Not Success: " + sio.getMessage().toString());
}
catch (Exception e) {
YLog.i("SSL", "Exception: Not Success: " + e.getMessage().toString());
}

@DirtyJerz
Copy link

Ah ok, your volley request queue is using the default http stack which uses the singleton. My volley instance is using Okhttp. OkHttp creates it's own httpclient (separate ssl context). I think all I need to do is to set the SSLSocketFactory for the OkHttpClient befor passing it to the volley.newRequestQueue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants