簡體   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