In my example, there are three certificates, suppose they form a chain, but I still do not know which of them are signed:
X509Certificate c1 = .... X509Certificate c2 = .... X509Certificate c2 = ....
I would like to know which certificate is responsible for signing another certificate.
The plan was to get an AuthorityKeyIdentifier "and match it with a" 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"));
I get the following for certificates (in the order of their chain): key identifier of subject / authority identifier
The values of the SubjectKeyIdentifier and AuthorityKeyIdentifier after decoding:
Certificate 1: (end of chain)
#0416041482b7384a93aa9b10ef80bbd954e2f10ffb809cde #04183016801482b7384a93aa9b10ef80bbd954e2f10ffb809cde
Certificate 2: Signed by Certificate 1
#04160414ab8059c365836d1d7d13bd19c3ec1a8f0d476aa3 #04183016801482b7384a93aa9b10ef80bbd954e2f10ffb809cde
Certificate 3: Signature for Certificate 2
(no SubjectKeyIdentifier - null bytes)
Formatted and aligned for easy reading (same as above)
------------------------------------------------------------------------------ 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
I expected c3 AuthorityKeyIdentifier to be equivalent to c2 SubjectKeyIdentifier. this does not seem to be the case.
EDIT: some parts of the result seem to be the same, I have an idea in “SubjectKeyIdentifier” - it always starts with “# 04”, followed by the length of the content (in hexadecimal format). Now I have a definite idea on how to decode the “SubjectKeyIdentifier”, but the “AuthorityKeyIdentifier” is still a big mystery to me.
relevant SO post
Did I do something wrong with the decryption? Why does the AuthorityKeyIdentifier property not match the correct SubjectKeyIdentifier of the certificate that signed it?