2

我需要使用 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", "...") 设置代理,但我只需要为我的请求设置它,而不是为整个系统设置它。

4

1 回答 1

0

我找到了基于 Apache 开源项目Apache 开源项目之一编写自己的 OCSP 验证代码的最简单方法, 并将其扩展为使用可配置的 HTTP 代理进行请求

于 2017-05-23T12:11:45.577 回答