我需要忽略PKIX路径构建异常
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderExc
ption: unable to find valid certification path to requested target
通过编写自己的实现了X509TrustManager
接口的类,我知道如何做到这一点,其中我总是从isServerTrusted
返回true
。
但是,我不想信任所有服务器和所有客户端。
- 对于客户端,我希望所有默认验证都像当前一样完成。
- 对于服务器,我只想忽略一个特定证书的服务器证书验证,但是仍然希望按照当前方式进行验证(例如使用cacerts存储)。
我怎样才能实现这样的目标 - 即将部分验证传递给我替换之前的X509TrustFactory对象。
也就是说,这就是我想要做的事情。
public boolean isServerTrusted(X509Certificate[] chain)
{
if(chain[0].getIssuerDN().getName().equals("MyTrustedServer") && chain[0].getSubjectDN().getName().equals("MyTrustedServer"))
return true;
// else I want to do whatever verification is normally done
}
此外,我不想干扰现有的isClientTrusted
验证。
我应该如何做到这一点?
equals
比较什么,但您肯定可以比较两个X509Certificate
实例上的getEncoded()
结果(当然是字节数组比较,而不是引用)。 - BrunogetAcceptedIssuers()
并将它们与链中的第一个证书进行了比较。 - Chakrit W