1

This question already has an answer here:

Assume you have a certificate (X509 v3) chain sent to you for validation. The chain sent to you may or may not include the root CA certificate. Is there a reliable way to find out whether this is the case?

Quite obviously only the certificate at the top of the hierarchy may be the root CA certificate, but how would I check this? I came up with a check for equality between issuer and subject, and this seems to work fine for all cases I found so far, but I'm not sure whether is foolproof.

Edit: This is not about a manual check or about which tool to use, it's about a programmatic check. So using openSSl to perform checks (as suggested in a 'possible duplicate' claim) is not an option. The question is which certificate attributes or extensions I can use in which fashion to reliably identify a root CA certificate in a given chain.

To make the question even more to the point: I suggested to check whether subject==issuer right from the beginning. The question is whether this is a foolproof approach. So is it possible to rely on the fact that this is true if and only if it is a root certificate? What happens if I create a root certificate and a derived intermediate CA certificate and, in the latter, just choose the subject equal to the issuer? Will that result in a valid certificate? (The authority key identifier may well correctly point to the key identifier of the root CA).

(Note that I did not ask how to check whether I should trust the chain. I want to know how to reliably identify a root CA certificate in a chain).

marked as duplicate by Steffen Ullrich, Xander, Matthew, wireghoul, Rory Alsop Aug 15 '16 at 17:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

Simply check if Issuer and Subject fields for equality. If they are equal, the certificate is self-signed and represents root certificate. Otherwise, the certificate is intermediate certificate. Of course, public key in the root certificate must validate its own signature.

Edit to follow up OP edit:

The question is which certificate attributes or extensions I can use in which fashion to reliably identify a root CA certificate in a given chain.

you must check that isCA attribute of Basic Constraints certificate extension is set to True in all CA certificates. And this extension SHALL be marked critical.

What happens if I create a root certificate and a derived intermediate CA certificate and, in the latter, just choose the subject equal to the issuer?

there are two outcomes:

The authority key identifier may well correctly point to the key identifier of the root CA

you will create a loop in the chain which is detected by most certificate chaining engines. Otherwise, the certificate will not be a part of your chain with root and intermediate certificate.

  • thank you for your answer. It indicates that the check I already suggested may work, but I sitll have some doubts. See the edit to my question. Are you saying that Issuer = Subject and validiation of signature will suffice? – Thomas Aug 11 '16 at 18:02
0

You need to check two conditions:

  1. Issuer is the same as the Subject
  2. The certificate is trusted

The second condition is required because you might very well pass off certificates created by a random CA.

Not the answer you're looking for? Browse other questions tagged or ask your own question.