Try to search your question here, if you can't find : Ask Any Question Now ?

Null pointer exception in strongswan keystore

HomeCategory: stackoverflowNull pointer exception in strongswan keystore
sourav asked 1 week ago

I am trying to build strong swan app in Android. I am able to compile and build it but at runtime when I try to load LocalCertificateStore it returns null and as a result when adding certificate to keystore with store.setCertificateEntry(null, certificate); I get a null pointer exception.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileOutputStream android.content.Context.openFileOutput(java.lang.String, int)' on a null object reference

When I try to get certificates with TrustedCertificateManager.getInstance().getAllCACertificates()
it returns 0 certificates. But when I load AndroidCAStore (which is also loaded by TrustedCertificateManager) seperately it returns all the certificates.

The problem is keystore returns null. Earlier it would return

LocalCertificateStore Implementation not found.

But after adding Security.addProvider(new LocalCertificateKeyStoreProvider());
that error was gone.

KeyStore store = KeyStore.getInstance("LocalCertificateStore");
store.load(null,null);
Hashtable<String, X509Certificate> hsh=TrustedCertificateManager.getInstance().getAllCACertificates();
Log.d("Loaded CA size",""+hsh.size()); //returns 0
store.setCertificateEntry(null, certificate);
TrustedCertificateManager.getInstance().reset();
1 Answers
Best Answer
Arben answered 1 week ago
Your Answer

2 + 10 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com