【问题标题】:Validate a certification path验证认证路径
【发布时间】:2013-06-26 11:24:23
【问题描述】:

我用 Java 实现了一个 SAML SP。
为了验证 SAML 响应的证书,
我从 SAML 响应中提取 X509Certificate 元素,并根据我提前将 IDP 证书上传到的 Java 密钥库文件对其进行验证。
我使用以下代码来验证证书:

 X509Certificate certFromResponse = //extract from SAML response 
 KeyStore keyStore = getKS();
 PKIXParameters params = new PKIXParameters(keyStore);
 params.setRevocationEnabled(false);
 CertPath certPath = 
 certificateFactory.generateCertPath(Arrays.asList(certFromResponse));
 CertPathValidator certPathValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType());
 CertPathValidatorResult result = certPathValidator.validate(certPath, params);

这适用于根 CA 的证书。
当证书有证书路径时,验证失败。
一种可能的处理方法是手动将路径中的所有证书上传到 JKS 文件中
使用不同的别名,然后将它们提取到这样的列表中:

List<Certificate> certs = new ArrayList<Certificate>();
certs.add(certFromResponse);
if (keyStore.getCertificate("ALIAS_CA_1") != null) {
    certs.add(keyStore.getCertificate("ALIAS_CA_1"));
}
if (keyStore.getCertificate("ALIAS_CA_2") != null) {
    certs.add(keyStore.getCertificate("ALIAS_CA_2");
}
...
CertPath certPath = certificateFactory.generateCertPath(certs);

有没有更直接的方法呢?
是否可以从证书本身中提取证书路径?

谢谢!

【问题讨论】:

    标签: java saml-2.0 opensaml


    【解决方案1】:

    PKIXParameters好像是自动提取认证路径的,不用手动提取。
    我们所要做的就是将所有证书上传到密钥库。

    【讨论】:

      猜你喜欢
      • 2018-03-24
      • 2010-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多