有在我的例子三个证,假设它们形成一个链条,但我还不知道他们签署了:如何知道哪些X509证书签名的另一个证书(JAVA)
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不正确匹配?
您可以发布证书本身供我们分析吗? – frasertweedale