mysql - 如何使用 JDBC 通过 X509 连接到 MySQL?

标签 mysql ssl jdbc

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

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

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

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

我完全按照 MySQL 站点上关于将证书导入 Java 信任库/ keystore 文件的说明进行操作。

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

如果我仅使用具有 REQUIRES SSL 的用户的信任库文件,那么一切都很好。与具有 REQUIRES X509 的用户一起使用 keystore 文件是没有的。

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

最佳答案

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

在花了一个星期的时间完成此操作后,我终于设法使用客户端证书(用户定义需要 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=,... ), 或 System.setProperty(var,val),...

它确实有效!!!

关于mysql - 如何使用 JDBC 通过 X509 连接到 MySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11509751/

相关文章:

java - JDBC 中的 ClassNotFoundException

php - CakePHP 2.1 初学者教程?

php - 迭代表中的列表值

php - 尝试使用 gmail 发送电子邮件时出现 Cakephp 3 错误

ssl - TLS、 header 和代理 : how to answer the client?

android - 使用存储在 android sqlite 数据库中的数据作为 weka 的输入

mysql - Mediawiki MySQL 的 CPU 负载有时很高

java - 我应该使用哪种 SOLR 实现方法; 3 个问题?

ssl - 新的 Google 域无法连接到 Heroku

java - 如何避免 TomEE 的 JDBC 连接池的数据库连接停滞?