Bustcy Castle Keystore (BKS): java.io.IOException: invalid keystore version

I need to connect to a REST based web service.

( https://someurl.com/api/lookup/jobfunction/lang/EN )

In IE or Chrome browser, when I try to access this URL, I get a certificate that I have to trust and accept it to continue. After that I have to enter a username and password, and then get a JSON response.

The same thing I have to do this programmatically for an Android application.

  • Tried with custom EasySSLSocketFactory and EasyX509TrustManager, did not work. I got the following error: java.security.cert.CertPathValidatorException: The chain anchor for the certification path was not found.

  • The BKS keystore is used, please note that mykeystore.bks is an empty file before I executed the commands below.

    keytool -importcert -v -trustcacerts -file "test.crt" -alias IntermediateCA -keystore "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234 keytool -list -keystore "mykeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "bcprov-jdk15on-148.jar" -storetype BKS -storepass abcd1234 

MyHTTPClient.java is as follows:

 public class MyHttpClient extends DefaultHttpClient { final Context context; public MyHttpClient(Context context) { this.context = context; } @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // Register for port 443 our SSLSocketFactory with our keystore // to the ConnectionManager registry.register(new Scheme("https", newSslSocketFactory(), 443)); return new SingleClientConnManager(getParams(), registry); } private SSLSocketFactory newSslSocketFactory() { try { // Get an instance of the Bouncy Castle KeyStore format KeyStore trusted = KeyStore.getInstance("BKS"); // Get the raw resource, which contains the keystore with // your trusted certificates (root and any intermediate certs) InputStream in = context.getResources().openRawResource(R.raw.mykeystore); try { // Initialize the keystore with the provided trusted certificates // Also provide the password of the keystore trusted.load(in, "abcd1234".toCharArray()); } finally { in.close(); } // Pass the keystore to the SSLSocketFactory. The factory is responsible // for the verification of the server certificate. SSLSocketFactory sf = new SSLSocketFactory(trusted); // Hostname verification from certificate // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); return sf; } catch (Exception e) { throw new AssertionError(e); } } 

When I call webservice, I get the following error: Called: java.lang.AssertionError: java.io.IOException: wrong keystore version

Please tell me what I need to do to connect to an HTTPS-based web service that has user credentials and a password. ......

+8
android certificate web-services
source share
2 answers

Version 148 of BC Bank does not work with Android. Use version 146 or 147.

+1
source share

I got help from someone else. The solution consists of the following steps:

  • 1, Download KeyStore Explorer tool
  • 2.After installation, open your bks certificate, then find Tools-> Change Type
  • 3, select BKS-V1, then save and use it.
+1
source share

All Articles