如何在 OCSP 请求中使用代理

how to use proxy in OCSP request

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

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