I want to check the certificate chain, I get the X509Certificate2 collection and must check if all certificates are building the same chain.
Usually, in order to check the certificate chain, I have to take a digital signature from a leaf certificate and check if it is signed with a root certificate - but in .NET. I cannot find a way to extract the signature from the X509Certificate2 object.
So I thought about using the X509Chain.Build() method as follows:
void ValidateChain(X509Certificate2Collection collection, X509Certificate2 leaf) { X509Chain x509Chain = new X509Chain(); x509Chain.ChainPolicy.ExtraStore.AddRange(collection); bool isValid = x509Chain.Build(leaf); }
But I have some questions about the construction method:
- As I understand it, the chain was also built from my computer storage, and I want it to be built only from
ExtraStore , how can I determine this behavior? - I saw that after the chain was built, it does not contain a Root Certificate; my question is why , and how can I verify that the chain has Root CA, as this is not part of the chain.
I will be so grateful if anyone could explain to me how the Build() method works.
source share