Last active
September 25, 2018 10:29
-
-
Save faruktoptas/0833822a2d443c903f12 to your computer and use it in GitHub Desktop.
Public Key Pinning Run
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
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