我需要使用 OCSP 使用 http 代理验证 X509 证书。这是我的代码:
List<X509Certificate> certificates = Collections.singletonList(certificate);
CertPath cp = factory.generateCertPath(certificates);
Set<TrustAnchor> trust = new HashSet<>();
trust.add(new TrustAnchor(issuerCertificate, null));
PKIXParameters params = new PKIXParameters(trust);
params.setRevocationEnabled(true);
CertPathValidator cpv =
CertPathValidator.getInstance(CertPathValidator.getDefaultType());
PKIXCertPathValidatorResult validationResult =
(PKIXCertPathValidatorResult) cpv.validate(cp, params);
我知道,我可以使用 System.setProperty("http.proxy", "...") 设置代理,但我只需要为我的请求设置它,而不是为整个系统设置它。