仍然是密码学中的一个小白我每天都会遇到简单的事情。今天只是其中的一个。从终端实体获取根证书和中间证书
我想用弹性城堡库在java中验证smime消息,我想我几乎已经知道了,但此时的问题是构建PKIXparameters对象。 比方说,我有以下结构的终端实体X509证书:
root certificate
+->intermediate certificate
+->end-entity certificate
为了验证消息,我需要首先建立信任链,但我无法弄清楚如何提取的根和中级来自最终实体的证书。
我试图用终端实体根,但它没有工作:
InputStream isCert = GetFISCertificate();
List list = new ArrayList();
X509Certificate rootCert = (X509Certificate) certificateFactory.generateCertificate(isCert);
list.add(rootCert);
CollectionCertStoreParameters params = new CollectionCertStoreParameters(list);
CertStore store = CertStore.getInstance("Collection", params, BC);
//create cert path
List certChain = new ArrayList();
certChain.add(rootCert);
CertPath certPath = certificateFactory.generateCertPath(certChain);
Set trust = Collections.singleton(new TrustAnchor(rootCert, null));
//validation
CertPathValidator certPathValidator = CertPathValidator.getInstance("PKIX", BC);
PKIXParameters pKIXParameters = new PKIXParameters(trust);
pKIXParameters.addCertStore(store);
pKIXParameters.setDate(new Date());
try {
CertPathValidatorResult result = certPathValidator.validate(certPath, pKIXParameters);
System.out.println("certificate path validated");
} catch (CertPathValidatorException e) {
System.out.println("validation failed on certificate number " + e.getIndex() + ", details: " + e.getMessage());
}
得到这个异常:
validation failed on certificate number -1, details: Trust anchor for certification path not found.
而且顺便说一句,我就可以只使用终端实体证书来验证消息,就好像它是自签名证书一样?
延长管理局信息访问是很常见的OCSP信息。但我想我从来没有见过这个包含id-ad-caIssuers的扩展的证书。无论如何,很好的答案。 – Egl
@Egl我见过证书,包括id-ad-caIssuers和OCSP(google.com的证书和巴西的PKI最终实体都是很好的例子)。我也看过其中一个证书,不幸的是,似乎CA中没有标准。 –
非常感谢您的回答!你帮了我很多! – revolt