繁体   English   中英

Postgresql无法接受SSL连接:sslv3警报证书未知

[英]Postgresql could not accept SSL connection: sslv3 alert certificate unknown

我正在使用SpringBoot配置datasource.url = jdbc:postgresql://..... / mydb?ssl = true&sslFactory = .... nonValidating ...

在我的application.yml中

port: 8443
ssl:
 enabled: true
 key-alias: PGSQLServerHostNameHere
 key-store: keystore.jks
 key-store-password:....
 key-store-type: JKS
 trust-store: #this one is irrelevant, it's just a...
 ### ... trust store for other restTemplate stuff
 trust-store-password: ....
 key-password: ....
 ciphers: "TLSv1.2"
 protocol: TLS

但是,Postgresql也设置并运行SSL = on。 的ssl_ciphers = 'TLSv1.2工作'

但是在PGSQL日志中,我得到:

Postgresql could not accept SSL connection: sslv3 alert certificate unknown

我在prod上的春季启动应用程序中出现错误(本地的自签名证书不会发生此错误):

org.postgresql...PSQLException: SSL error: sun.security.validator.ValdiatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

SSL证书配置

我在root.crt中为postgresql服务器签名了证书(包括Java app服务器的签名证书,里面有正确的别名)。

我在JKS文件中将postgresql服务器的签名证书(别名:PGSQLServerHostNameHere)作为我的keystore.jks的“trustEntry”。

我的keystore.jks中有privateKeyEntry用于我自己的服务器。

我在keystore.jks中有根CA.

SpringBoot应用程序在我的本地机器上使用自签名JKS可以正常工作。

但Postgresql是一个问题...拒绝我从Java应用服务器的通信。

postgresql.conf中:

ssl = on
ssl_ciphers = 'TLSv1.2'

(everything else is default)

的pg_hba.conf

hostssl all all md5
 Postgresql could not accept SSL connection: sslv3 alert certificate unknown .... sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 

这意味着客户端无法接受来自服务器的证书,可能是因为颁发该证书的CA不在信任库中。 并且客户端将此服务器作为警报发送此服务器,以便服务器知道连接失败的原因。

但Postgresql是一个问题...拒绝我从Java应用服务器的通信。

不,您的Java应用程序拒绝与Postgresql的通信,因为它不信任证书。 您在Postgresql的错误消息中看到的正是您的Java应用程序发送的内容,因为它不会继续TLS握手。

我想唯一的方法是查看JSSE实现并将-Djavax.net.ssl类型命令添加到命令行或将其添加到System.setProperty()

此外,您可以将其添加到JDBC ssl_cert=... &ssl_key=...等的URL中。

不得不为postgresql找到合适的命令。 它没有详细记录。

application.yml “ssl”属性与javax.net.ssl无关

暂无
暂无

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

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