javax.net.ssl.SSLHandshakeException: PKIX path validation failed:
java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
表示客戶端信任存儲(trustStore)中缺少 AD 憑證鏈的根憑證,或憑證鏈不完整。
keytool -list -keystore d:/zhouwd.keystore 檢視是否包含 AD 根 CA 憑證。ldaps://10.0.10.164:636),憑證 CN/SAN 必須包含該 IP,否則需實作自訂 HostnameVerifier(不建議生產環境)。javax.net.ssl.trustStore 指向正確檔案,trustStorePassword 正確。telnet 10.0.10.164 636 測試連接埠可達。若無法解決憑證鏈問題,可暫時實作信任所有憑證的 TrustManager(僅限測試):
TrustManager[] trustAll = new TrustManager[] {
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAll, new SecureRandom());
// 將 sc.getSocketFactory() 設定給 LDAP 連線屬性
cacerts 或自訂 keystore)。-Djavax.net.debug=ssl,handshake 定位具體驗證失敗點。