2012-07-16 139 views
4

我建立了一個MySQL(社區服務器,5.1)數據庫服務器。如何使用JDBC與X509連接MySQL?

我已經設置了SSL,創建的證書等

我已經創建了具有REQUIRES X509屬性的用戶。

我可以使用使用命令行客戶端「MySQL的」和「狀態」這個用戶連接命令顯示SSL是活躍等

我完全按照有關導入從MySQL網站中的說明證書導入Java信任庫/密鑰庫文件。

我只是不能使用這些連接到數據庫。

如果我只使用具有REQUIRES SSL的用戶的信任庫文件,那麼一切都很好。與用戶使用密鑰庫文件與需要X509只是沒有它。

似乎有很多證據表明人們正在爲此而掙扎,並沒有多少答案。有沒有人真的有這個工作?

+0

例外?堆棧跟蹤?信息? – EJP 2012-07-16 23:52:11

+0

那麼,打開調試使用「System.setProperty(」javax.net.debug「,」所有「);」產生一定的輸出,但沒有明顯的錯誤進行調查: – 2012-07-17 07:03:53

+0

java.sql.SQLException:訪問拒絕用戶'ssluser'@'localhost'(使用密碼:是) \t at com.mysql.jdbc.SQLError.createSQLException SQLError.java:946) \t在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) \t在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885) \t在com.mysql .jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421) \t在com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:3988) \t在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1293 ) \t at com.mysql.jdbc.Conn ection.createNewIO(Connection.java:2748) – 2012-07-17 07:05:49

回答

12

裂紋,在頁面的底部,在此列出,在我的評論: http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-using-ssl.html

LITERALLY支出WEEK您不要這樣做,我終於設法使用客戶端certifiacte連接後(需要X509用戶確定指標) !!!!

rem NOTE: these commands are run using the Java 6 (1.6) JDK as it requires the "-importkeystore" command 
rem which is not available before this JDK version. 

rem Import the self signed Certifacte Authority certificate into a keystore. 
keytool -import -alias mysqlCACert -file ca-cert.pem -keystore truststore -storepass truststore 
rem Shows only the signed certificate. 
keytool -v -list -keystore truststore -storepass truststore 

rem Create a PKCS12 file from an existing signed client certifcate and its private key. 
rem set password to "keystore". 
openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem -out client.p12 -name clientalias -CAfile ca-cert.pem -caname root 
rem Import the combined certificate and private key into the keystore. 
keytool -importkeystore -deststorepass keystore -destkeystore keystore -srckeystore client.p12 -srcstoretype PKCS12 -srcstorepass keystore -alias clientalias 

然後指定受信任的榮譽證書文件(信任),並在Java應用程序要麼通過連接URL的客戶端證書/密鑰文件(密鑰庫),通過JVM啓動參數的參數(-D = ,...)或System.setProperty(var,val),...

它實際上工作!

+0

你應該得到這個黑魔法的獎勵! – NateS 2015-05-09 16:18:52

+0

謝謝!花了我一段時間找到這篇文章,但你爲我節省了很多頭痛。非常感謝,像魅力一樣工作。 – mba12 2015-06-25 21:25:01