【问题标题】:Obtaining the certificate chain获取证书链
【发布时间】:2013-08-23 21:29:09
【问题描述】:

我正在使用 Java 中的 X509 证书。 在获得根证书之前,是否可以在签名层次结构中找到所有其他证书?

我有一个证书文件(扩展名为.cer),我想提取父签名证书。我想继续查找该证书的父级,直到我获得最终的根证书,它是自签名的。

我检查了java.security.cert 中的 X509Certificate 证书 API 和相关 API,但找不到任何有用的东西。

【问题讨论】:

标签: java cryptography certificate x509certificate digital-certificate


【解决方案1】:

这并不难 - 假设您以某种方式/带外获得了一个或多个钥匙串中的所有中间证书和根证书。

看看

http://codeautomate.org/blog/2012/02/certificate-validation-using-java/

用于执行此操作的代码片段。关键位在 validateKeyChain() 中,基本上包括

   cert = cert-to-validate
   while(not self signed) {
       extract issuer from cert
       scan keychain(s) to find cert with a subject equal to the issuer
       if none found - error
       check if the signature is correct.
       cert = issuers_cert
   }
   if not at the top/root - error

至于 如何 您获得中间/根证书 - 这是一个不同的问题。请注意,此代码有点幼稚 - 并不太了解交叉签名。虽然 java pkix 调用 - BouncyCastle 有一个例子。

您通常可以将根证书构建成密钥链;但中间证书通常需要“收集”或更动态地发现。这通常需要在 TLS 或类似期间查询 SSL 堆栈。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2015-03-21
    相关资源
    最近更新 更多