我有一個MongoDb
實例正在運行(單實例),啓用了SSL
。我能夠與RoboMongo
連接到它那裏SSL
選項卡上我提供以下信息:使用SSL從JAVA應用程序連接到MongoDb
CA File : /path to my certificate/testCA.pem
PEM certificate/key: /path to my key/testKey.pem
哪些成功連接。現在我試圖從java應用程序連接到相同的mondodb。我進口testCA.pem到使用以下命令的cacerts:
keytool -import -keystore cacerts -file testCA.pem -storepass changeit
,我可以看到添加到存儲的新條目。試圖添加其他密鑰到它,它說無效的證書。在Java應用程序我設置系統屬性如下:
System.setProperty ("javax.net.ssl.trustStore","C:\\Program Files\\Java\\jre1.8.0_91\\lib\\security\\cacerts");
System.setProperty ("javax.net.ssl.trustStorePassword","changeit");
,我發現了以下錯誤:
org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=test.mongo.com:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.io.EOFException}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=test.mongo.com:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.io.EOFException}}]
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:75)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2075)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1918)
缺少什麼我在這裏先謝謝了!
我有完全一樣的問題,但它仍然不是爲我工作,我在Linux上運行的窗口,以便從「testKey.pem」創建xyz.pkcs12和密鑰存儲複製它交給窗口和進口的相同,沒有任何東西否則我應該這樣做? – Amit
@Amit你可以發佈你的stacktrace嗎? – Gurkha
javax.net.ssl.SSLHandshakeException:java.security.cert.CertificateException:本 \t在sun.security.ssl.Alerts.getSSLException(未知來源) \t在sun.security.ssl.SSLSocketImpl.fatal沒有使用者替代名稱(未知來源) \t在sun.security.ssl.Handshaker.fatalSE(未知來源) \t在sun.security.ssl.Handshaker.fatalSE(未知來源) \t在sun.security.ssl.ClientHandshaker.serverCertificate(未知來源) \t at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) \t at sun.security.ssl.Handshaker.processLoop(Unknown Source) – Amit