繁体   English   中英

如何使用JDBC使用X509连接MySQL?

[英]How to connect to MySQL with X509 using JDBC?

我已经建立了一个MySQL(社区服务器,5.1)数据库服务器。

我已经设置了SSL,创建了证书等。

我创建了一个具有REQUIRES X509属性的用户。

我可以使用命令行客户端“mysql”使用此用户进行连接,“status”命令显示SSL处于活动状态等。

我完全按照MySQL站点的说明将证书导入Java truststore / keystore文件。

我只是无法使用这些连接到数据库。

如果我使用具有REQUIRES SSL的用户只使用truststore文件,那么一切都很好。 使用带有REQUIRES X509的用户的密钥库文件就没有了。

在网络上似乎有很多证据表明人们正在努力解决这个问题并没有多少答案。 有没有人真的有这个工作?

在我的评论页面底部列出了这里的破解: http//dev.mysql.com/doc/refman/5.0/en/connector-j-reference-using-ssl.html

在花了一个星期的时间后,我终于设法使用客户端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

然后通过连接URL,通过JVM启动参数参数(-D =,...)在Java应用程序中指定受信任的certifcates文件(信任库)和客户端证书/密钥文件(密钥库),或者System.setProperty(VAR,VAL),...

它确实有效!!!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM