AndroidPinning icon indicating copy to clipboard operation
AndroidPinning copied to clipboard

Pinning Support for Volley

Open ajinabraham opened this issue 10 years ago • 3 comments

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

ajinabraham avatar Dec 17 '14 07:12 ajinabraham

Did you ever figure this out?

DirtyJerz avatar Apr 05 '15 16:04 DirtyJerz

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()); }

ajinabraham avatar Apr 07 '15 06:04 ajinabraham

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.

DirtyJerz avatar Apr 07 '15 16:04 DirtyJerz