Skip to content

Instantly share code, notes, and snippets.

@faruktoptas
Last active September 25, 2018 10:29
Show Gist options
  • Save faruktoptas/0833822a2d443c903f12 to your computer and use it in GitHub Desktop.
Save faruktoptas/0833822a2d443c903f12 to your computer and use it in GitHub Desktop.
Public Key Pinning Run
private void sendRequest() {
requestQueue = Volley.newRequestQueue(this, new HurlStack(null, pinnedSSLSocketFactory()));
StringRequest request = new StringRequest(Request.Method.GET, SECURE_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, "Response: " + response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "Failed!", Toast.LENGTH_SHORT).show();
Log.e(TAG, "Request failed: " + error.toString());
}
});
requestQueue.add(request);
}
private SSLSocketFactory pinnedSSLSocketFactory() {
try {
return new TLSSocketFactory(PUBLIC_KEY);
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment