Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Mysql jdbc ssl连接拒绝验证证书_Java_Mysql_Amazon Web Services_Jdbc_Ssl Certificate - Fatal编程技术网

Java Mysql jdbc ssl连接拒绝验证证书

Java Mysql jdbc ssl连接拒绝验证证书,java,mysql,amazon-web-services,jdbc,ssl-certificate,Java,Mysql,Amazon Web Services,Jdbc,Ssl Certificate,我正在尝试使用java通过ssl连接到mysql数据库。我有一个名为rds-combined-ca-bundle.pem(从下载)的证书文件,用于托管mysql数据库的远程服务器 如果我运行以下程序(在Red Hat Enterprise Linux Server 5.7版(Tikanga)上): 然后它就起作用了: Reading table information for completion of table and column names You can turn off this f

我正在尝试使用java通过ssl连接到mysql数据库。我有一个名为rds-combined-ca-bundle.pem(从下载)的证书文件,用于托管mysql数据库的远程服务器

如果我运行以下程序(在Red Hat Enterprise Linux Server 5.7版(Tikanga)上):

然后它就起作用了:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1076
Server version: 5.6.27-log MySQL Community Server (GPL)
但是,当我尝试使用mysql驱动程序(mysql-connector-java-5.1.38-bin.jar)在java中执行此操作时,不起作用,我不确定原因。我按照指示的步骤进行操作

首先,我创建了我的信任库和密钥库:

keytool -import -alias fnblCert -file rds-combined-ca-bundle.pem -keystore fdcertstore
然后我制作了我的客户机密钥

keytool -genkey -keyalg rsa -alias fnblclient -keystore fdkeystore
我的java代码(至少是处理db连接的部分)可以这样处理它:

System.setProperty("javax.net.ssl.trustStore", "/srv/dw/apps/FileDownloader/config/fdcertstore");
System.setProperty("javax.net.ssl.trustStorePassword", "the_password");
System.setProperty("javax.net.ssl.keyStore", "/srv/dw/apps/FileDownloader/config/fdkeystore");
System.setProperty("javax.net.ssl.keyStorePassword", "the_password");
System.setProperty("javax.net.debug", "all");

String url = "jdbc:mysql://some.server.com/db_name?"
            + "user=a_user&password=the_password"
            + "&useSSL=true";

Connection conn = DriverManager.getConnection(url);
java版本:java版本“1.7.0_85” OpenJDK运行时环境(rhel-2.6.1.3.el5_11-x86_64 u85-b01) OpenJDK 64位服务器虚拟机(构建24.85-b03,混合模式)

因此,当上面的代码运行时,我会遇到一系列令人讨厌的异常(不打算粘贴所有堆栈跟踪):

异常消息本身并不能很好地解释。我最初认为它无法找到信任存储或验证它,但后来我看到了握手调试输出,并注意到它找到了客户机:

<snip>
found key for : fnblclient
<snip>
Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11

Key:  Sun RSA public key, 2048 bits
显然,这意味着它不喜欢我给它的证书。在这一点上,我已经没有想法了。我认为mysql命令的检查不如java严格。如果我指定&verifyServerCertificate=false属性,代码就可以工作,但我不必这样做,因为--sslca参数确实执行服务器证书身份验证(如mysql 5.5参考手册中所述),并且它可以工作

如果有人能至少为我指出正确的方向,我将不胜感激

附:服务器不是我的,所以我不能乱动设置,我只能访问用户


PPS:我也不能处理默认的cacert文件,因为系统管理员没有给我特权。

也许这个问题可以帮助我:谢谢。这个问题很相似,但不是同一个问题。从握手调试输出判断,我的信任存储文件没有问题,但我出于某种原因拒绝了服务器的证书,而mysql命令对此没有问题。因此我感到困惑。错误PKIX路径构建失败通常意味着信任存储中缺少来自证书链的一个或多个证书。@MarkrotVeel可能是这样,但我需要在其中放入哪些额外的证书?正如您所看到的,我在mysql命令中只使用了一个证书,它可以正常工作。然后我将相同的证书放在信任存储中,但它不起作用。我是否还遗漏了一个额外的步骤?可能不相关,但我不止一次地解决了这个错误,升级了JVM的JCE策略文件。你试过了吗?也许这个问题可以帮助你:谢谢。这个问题很相似,但不是同一个问题。从握手调试输出判断,我的信任存储文件没有问题,但我出于某种原因拒绝了服务器的证书,而mysql命令对此没有问题。因此我感到困惑。错误PKIX路径构建失败通常意味着信任存储中缺少来自证书链的一个或多个证书。@MarkrotVeel可能是这样,但我需要在其中放入哪些额外的证书?正如您所看到的,我在mysql命令中只使用了一个证书,它可以正常工作。然后我将相同的证书放在信任存储中,但它不起作用。我是否还遗漏了一个额外的步骤?可能没有关联,但我不止一次地解决了这个错误,升级了JVM的JCE策略文件。你试过了吗?
An exception has occured while connecting to the remote machine: Communications link failure
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
<snip>
found key for : fnblclient
<snip>
Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11

Key:  Sun RSA public key, 2048 bits
<snip>

trustStore is: /srv/dw/apps/FileDownloader/config/fdcertstore
trustStore type is : jks
trustStore provider is : 
init truststore
adding as trusted cert:
  Subject: CN=aws.amazon.com/rds/, OU=RDS, O=Amazon.com, L=Seattle, ST=Washington, C=US
  Issuer:  CN=aws.amazon.com/rds/, OU=RDS, O=Amazon.com, L=Seattle, ST=Washington, C=US
  Algorithm: RSA; Serial number: 0xe775b657e21a8128
  Valid from Tue Apr 06 01:44:31 EEST 2010 until Sun Apr 05 01:44:31 EEST 2015
%% Invalidated:  [Session-1, TLS_RSA_WITH_AES_256_CBC_SHA]
Thread-12, SEND TLSv1 ALERT:  fatal, description = certificate_unknown
Thread-12, WRITE: TLSv1 Alert, length = 2
[Raw write]: length = 7
0000: 15 03 01 00 02 02 2E                          
Thread-12, called closeSocket()
Thread-12, handling exception: javax.net.ssl.SSLHandshakeException:     sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target