I'm trying throw my VolleySingleton make requests to my https server, I used keystore to save the certificate to .bks file but still getting no response from the request I'm doing the keystore with the certificate I got from ssl company, without the intermediate certs. I'm using:
keytool -importcert -v -trustcacerts -file "C:/cert.cer" -alias test -keystore "C:/certificate.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "C:/bcprov-jdk16-145.jar" -storetype BKS -storepass testpass
my volley singleton:
public class VolleySingleton{
private static VolleySingleton instance;
private RequestQueue requestQueue;
private static Context ctx;
private VolleySingleton(Context context) {
ctx = context;
requestQueue = getRequestQueue();
}
public static synchronized VolleySingleton getInstance(Context context) {
if (instance == null) {
instance = new VolleySingleton(context);
}
return instance;
}
public RequestQueue getRequestQueue() {
if (requestQueue == null) {
requestQueue = Volley.newRequestQueue(ctx.getApplicationContext(), new HurlStack(null, newSslSocketFactory()));
}
return requestQueue;
}
public <T> void addToRequestQueue(Request<T> req) {
int socketTimeout = 90000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
req.setRetryPolicy(policy);
getRequestQueue().add(req);
}
private SSLSocketFactory newSslSocketFactory() {
try {
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream in = ctx.getApplicationContext().getResources().openRawResource(R.raw.certificate);
try {
trusted.load(in, ctx.getString(R.string.keystore).toCharArray());
} finally {
in.close();
}
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(trusted);
SSLContext context1 = SSLContext.getInstance("TLS");
context1.init(null, tmf.getTrustManagers(), null);
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
Log.i("Volley","Verifing host:"+hostname);
return true;
}
});
SSLSocketFactory sf = context1.getSocketFactory();
return sf;
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
The application worked fine with request to http domain, the problem came when I installed ssl on the domain. I'm not getting error response from the stringrequest of volley
What I'm doing wrong? I think the problem is in the keystore, which certificate I've to keystore? I tried with root and intermediate also separated but got nothing