We have a node application running in a Linux server. we use ca.pem certificate to communicate with the MongoDB.
I want to write a java application to communicate with the same MongoDB server from my local machine.
I copied(copy content and create a new ca.pem file in local machine) the ca.pem file in to local machine and execute the below command generate the keystore.
keytool -importcert -trustcacerts -file C:certsmongoca.pem -keystore C:certsmongomongocertca.cer
Inside the code I used the below properties to access the keys.
System.setProperty("javax.net.ssl.trustStore", "C:\certs\mongo\ca.pem");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStore","C:\certs\mongo\mongocert\ca.cer");
System.setProperty("javax.net.ssl.keyStorePassword","changeit");
I am getting the below error when I try to run the code
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at javax.net.ssl.DefaultSSLSocketFactory.throwException(Unknown Source)
at javax.net.ssl.DefaultSSLSocketFactory.createSocket(Unknown Source)
at com.mongodb.connection.SocketStream.open(SocketStream.java:57)
... 3 more
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.security.Provider$Service.newInstance(Unknown Source)
at sun.security.jca.GetInstance.getInstance(Unknown Source)
at sun.security.jca.GetInstance.getInstance(Unknown Source)
at javax.net.ssl.SSLContext.getInstance(Unknown Source)
at javax.net.ssl.SSLContext.getDefault(Unknown Source)
at javax.net.ssl.SSLSocketFactory.getDefault(Unknown Source)
at com.mongodb.MongoClientOptions.<clinit>(MongoClientOptions.java:54)
at com.test.Test.main(Test.java:64)
Caused by: java.security.KeyStoreException: problem accessing trust store
at sun.security.ssl.TrustManagerFactoryImpl.engineInit(Unknown Source)
at javax.net.ssl.TrustManagerFactory.init(Unknown Source)
at sun.security.ssl.SSLContextImpl$DefaultManagersHolder.getTrustManagers(Unknown Source)
at sun.security.ssl.SSLContextImpl$DefaultManagersHolder.<clinit>(Unknown Source)
at sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 8 more
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(Unknown Source)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(Unknown Source)
at sun.security.provider.KeyStoreDelegator.engineLoad(Unknown Source)
at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(Unknown Source)
at java.security.KeyStore.load(Unknown Source)
at sun.security.ssl.TrustStoreManager$TrustAnchorManager.loadKeyStore(Unknown Source)
at sun.security.ssl.TrustStoreManager$TrustAnchorManager.getTrustedCerts(Unknown Source)
at sun.security.ssl.TrustStoreManager.getTrustedCerts(Unknown Source)
... 17 more
Jan 28, 2021 4:41:47 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=daas-de-b2-k0011:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)}, caused by {java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)}, caused by {java.security.KeyStoreException: problem accessing trust store}, caused by {java.io.IOException: Invalid keystore format}}]}. Waiting for 30000 ms before timing out
Could you please give me some direction to resolve this issue...
question from:
https://stackoverflow.com/questions/65936050/invalid-keystore-format-error-in-accessing-the-mongodb 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…