Comunicação entre o Android e o servidor usando SSL com o Bouncy Castle
Entendo que isso é algo que não é tão difícil, mas, infelizmente, estou preso aqui e lutando desde ontem, segui issoAutenticação mútua no Android tutorial, para colocar um keystore em recursos e tentar conectar-se ao meu servidor via SSL, mas obtendo a seguinte exceção
java.lang.RuntimeException: org.spongycastle.jcajce.provider.asymmetric.x509.CertificateFactory $ ExCertificateException
Eu coloquei meusslapptruststore.pfx
arquivo emres/raw/sslapptruststore.pfx
e usando este pedaço de código
try {
KeyStore clientCert = KeyStore.getInstance("PKCS12");
clientCert.load(getResources().openRawResource(R.raw.sslapptruststore), "123456".toCharArray());// this line causes exception
HttpClient httpClient = null;
HttpParams httpParams = new BasicHttpParams();
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(clientCert, null, null);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", sslSocketFactory, 8443));
httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, registry), httpParams);
HttpPost httpPost = new HttpPost(
"https://192.168.1.113:8443/CertProvider");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("csr", csr.toString()));
// Url Encoding the POST parameters
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
// Making HTTP Request
// HttpResponse response = null;
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = "";
response = httpClient.execute(httpPost, responseHandler);
} catch (Exception e) {
Log.e("", e.getMessage());
}
Eu também procurei, mas outras pessoas estão usando.bks
.
Qualquer ajuda é apreciada.