我应该使用哪个 Java API 来实现支持 OCSP 的证书验证?

Which Java API should I use for implementing certificate verification with OCSP support?

存在两个 java api 引用:

第一个有关于X509TrustManager接口的描述。我很困惑。我应该使用那个来实现 x509 证书验证还是必须通过第二个 link?这是实现我的目标的标准方法

second link 提供了有关 CertPath class 如何实施您自己的证书路径验证的文档。所以你必须自己处理整个 PKI 证书链 (例如,直到根的签名和证书的验证)。此外,它还为您提供了 PKIX 证书验证默认算法的信息。

first link 展示了如何使用 TrustManager,其中使用了 PKIX 算法。除了使用 PKIX 的证书路径验证之外,还包含 TrustManager 更多机制来建立 SSL/TLS 通信。

TrustManager/PKIX 算法还提供了一种撤销机制(CLROCSP)。要激活 OCSP,请深入了解 first link section PKIX TrustManager Support

If the init(KeyStore ks) method is used, default PKIXParameters are used with the exception that revocation checking is disabled. It can be enabled by setting the system property com.sun.net.ssl.checkRevocation to true.

并且您必须将安全性 属性 ocsp.enable 设置为 true。所以基本上,你无事可做

System.setProperty("com.sun.net.ssl.checkRevocation", "true");
Security.setProperty("ocsp.enable", "true");

如果你不想重新实现或交换TrustManagerPKIX算法已经提供的验证链机制,那么你绝对应该使用first link .如果您需要有关 PKIX 算法的更多信息,实现您自己的算法或执行 认证验证而不建立 TLS/SSL 通信,那么您应该检查 second link.