我正在使用SpringBoot,配置数据源的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
我的Spring Boot应用在生产环境中出现了错误(但是在本地使用自签名证书时不会发生此错误):
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 应用服务器的签名证书)。
我已将 Postgresql 服务器的签名证书(别名:PGSQLServerHostNameHere)作为“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