【发布时间】:2023-04-08 12:52:02
【问题描述】:
在我的示例中有三个证书,假设它们形成一个链,但我还不知道它们中的哪一个签署了哪个:
X509Certificate c1 = ....
X509Certificate c2 = ....
X509Certificate c2 = ....
我想知道哪个证书负责签署另一个证书。
计划是获取“AuthorityKeyIdentifier”并将其与“SubjectKeyIdentifier”匹配。
import org.bouncycastle.asn1. DEROctetString;
private static String decodeKey(byte[] e) {
DEROctetString octet = new DEROctetString(e);
return octet.toString();
}
String subjectKeyId = decodeKey(c.getExtensionValue("2.5.29.14"));
String authorityKeyId = decodeKey(c.getExtensionValue("2.5.29.35"));
我得到以下证书(按链的顺序):主题/授权密钥 ID 对
SubjectKeyIdentifier和AuthorityKeyIdentifier解码后的取值:
证书1:(链的末端)
#0416041482b7384a93aa9b10ef80bbd954e2f10ffb809cde
#04183016801482b7384a93aa9b10ef80bbd954e2f10ffb809cde
证书 2:由证书 1 签名
#04160414ab8059c365836d1d7d13bd19c3ec1a8f0d476aa3
#04183016801482b7384a93aa9b10ef80bbd954e2f10ffb809cde
证书 3:由证书 2 签名
(no SubjectKeyIdentifier - null bytes)
#041830168014ab8059c365836d1d7d13bd19c3ec1a8f0d476aa3
格式化和对齐以便于阅读(与顶部相同)
------------------------------------------------------------------------------
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
------------------------------------------------------------------------------
Certificate 1
#04 16 04 14 82 b7 38 4a 93 aa 9b 10 ef 80 bb d9 54 e2 f1 0f fb 80 9c de
#04 18 30 16 80 14 82 b7 38 4a 93 aa 9b 10 ef 80 bb d9 54 e2 f1 0f fb 80 9c de
Certificate 2
#04 16 04 14 ab 80 59 c3 65 83 6d 1d 7d 13 bd 19 c3 ec 1a 8f 0d 47 6a a3
#04 18 30 16 80 14 82 b7 38 4a 93 aa 9b 10 ef 80 bb d9 54 e2 f1 0f fb 80 9c de
Certificate 3
=== == == == == == == == == == == NO DATA == == == == == == == == == == == ==
#04 18 30 16 80 14 ab 80 59 c3 65 83 6d 1d 7d 13 bd 19 c3 ec 1a 8f 0d 47 6a a3
我期待 c3 的 AuthorityKeyIdentifier 等同于 c2 的 SubjectKeyIdentifier。这里似乎不是这样。
编辑:结果的某些部分似乎匹配,我对“SubjectKeyIdentifier”有一些想法 - 它总是以“#04”开头,后跟内容的长度(以十六进制表示)。我现在对如何解码“SubjectKeyIdentifier”有了一定的了解,但“AuthorityKeyIdentifier”对我来说仍然是一个很大的谜。
相关SO post
我的解码有什么问题吗? 为什么 AuthorityKeyIdentifier 与签署它的证书的 SubjectKeyIdentifier 不匹配?
【问题讨论】:
-
你能把证书本身发给我们分析吗?
标签: java certificate x509 decoding subject