CertPathValidator异常Java试图使用SSL连接到服务器数据库
我有一个Java应用程序(带有hibernate),我正试图在一个带有Google Cloud SQL+计算引擎的项目中使用它,但没有成功 Google Cloud SQL要求我通过SSL连接到数据库,使用CertPathValidator异常Java试图使用SSL连接到服务器数据库,java,mysql,hibernate,ssl,google-cloud-sql,Java,Mysql,Hibernate,Ssl,Google Cloud Sql,我有一个Java应用程序(带有hibernate),我正试图在一个带有Google Cloud SQL+计算引擎的项目中使用它,但没有成功 Google Cloud SQL要求我通过SSL连接到数据库,使用server-ca.pem、client-cert.pem和client-key.pem 在此之前,我使用属性连接到数据库: hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver hibernate.connection.url=
server-ca.pem
、client-cert.pem
和client-key.pem
在此之前,我使用属性连接到数据库:
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost/dbname?autoReconnect=true&useSSL=false
hibernate.connection.username=root
hibernate.connection.password=pass
hibernate.dialect=org.hibernate.dialect.MySQLDialect
如何将其更改为使用SSL
谢谢大家!
[编辑]
尝试了Pooja Aggarwal的回答,但没有成功
使用-Djavax.net.debug=all
我得到一个异常:
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
[编辑2]
我为生成证书而运行的命令:
openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem \
-name "mysqldb" -passout pass:MYPASS -out client-keystore.p12
keytool -importkeystore -srckeystore client-keystore.p12 -srcstoretype pkcs12 \
-srcstorepass MYPASS -destkeystore keystore -deststoretype JKS -deststorepass MYPASS
然后执行:
java -Djavax.net.ssl.keyStore=/home/user/cert/keystore -Djavax.net.ssl.keyStorePassword=MYPASS -jar MyApp.jar
附言:
我可以通过以下方式连接:
mysql -uroot -p -h 192.00.00.00 \
--ssl-ca=server-ca.pem --ssl-cert=client-cert.pem \
--ssl-key=client-key.pem
按照本链接中提到的步骤操作。 您需要将useSSL标记为true,并在JDK中导入证书,其步骤在上面的链接中提到。然后需要设置系统属性
System.setProperty("javax.net.ssl.keyStore","path_to_keystore_file");
System.setProperty("javax.net.ssl.keyStorePassword","mypassword");
使用此链接中提到的步骤导入证书:遵循此链接中提到的步骤。 您需要将useSSL标记为true,并在JDK中导入证书,其步骤在上面的链接中提到。然后需要设置系统属性
System.setProperty("javax.net.ssl.keyStore","path_to_keystore_file");
System.setProperty("javax.net.ssl.keyStorePassword","mypassword");
使用此链接中提到的步骤导入证书:您面临的问题是什么?此异常:由以下原因引起:java.security.cert.CertificateException:java.security.cert.CertPathValidatorException:Path未与任何信任主播链接您是否在jdk中导入了证书?我已编辑了答案。请按照stackoverflow链接jediz回答中提到的步骤进行操作。相同的异常?您面临的问题是什么?此异常:由以下原因引起:java.security.cert.CertificateException:java.security.cert.CertPathValidatorException:Path未与任何信任主播链接您是否在jdk中导入了证书?我已编辑了我的答案。请按照jediz回答中提到的步骤进行操作。相同的例外情况?