背景: 客戶端某系統a通過https方式請求另外一個系統b,a系統拋出異常
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://b.***.com/api/openPlatform/***": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
問題探究:
? ? ?通過瀏覽器訪問https://b.***.com 頁面時候,提示證書是安全的,再進一步查看證書詳情,發現證書是Let's Encrypt機構頒發的,按正常來講,如果證書是絕對安全的(公認受信任的機構頒發的),是不會報上面異常的,所以懷疑是不是,即使瀏覽器信任上述證書,但是jdk還是不信任的,所以它還是到本地去看,有沒有在本地找到受信任的證書,我們第一個解決方案就是 找到這個證書對應的crt,導入到a系統的jdk中,重啟后發現不再報錯,雖然問題解決,但也未解決內心疑惑,進一步查找資料發現,部分jdk版本和Let's Encrypt證書是不兼容的,我們系統在用的版本恰好是在不兼容范圍內的jdk,于是升級了下jdk,升級到8u251,問題解決,以后再也不必因為免費證書3個月到期后客戶端頻繁的跟著導入證書了。
參考資料:https://letsencrypt.org/docs/certificate-compatibility/