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

时间:2017-04-28 21:58:15

标签: java postgresql ssl spring-boot

我正在使用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

1 个答案:

答案 0 :(得分:1)

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握手。