Hi there.
I am not sure is this a bug or that behavior is expected. I was searching for some ways to validate a custom CA issued certificate and found this.
Setting ChainPolicy.VerificationFlags = X509VerificationFlags.AllowUnknownCertificateAuthority;
will allow the build method to return true even if you don't add certificates to the ExtraStore which completely defeats the purpose of checking.
I want to make sure this is an expected behavior and if so, ask how should I validate server certs against ca certs added to extra store?
Thank you.
If AllowUnknownCertificateAuthority is the only flag set then chain.Build() will return true if
If that flag is not specified then an additional constraint is added:
So, Build() returns true, you know that a time-valid non-revoked chain is present. The thing to do at that point is read chain.ChainElements[chain.ChainElements.Count - 1].Certificate and determine if it is a certificate that you trust. I recommend comparing chainRoot.RawData to a byte[] representing a certificate that you trust as a root in context (that is, byte-for-byte compare rather than using a thumbprint value).
(If other flags are set then other constraints are also relaxed)
@bartonjs Now it became clear, thanks! I think you can close the issue?
Most helpful comment
If
AllowUnknownCertificateAuthorityis the only flag set then chain.Build() will return true ifIf that flag is not specified then an additional constraint is added:
So, Build() returns true, you know that a time-valid non-revoked chain is present. The thing to do at that point is read
chain.ChainElements[chain.ChainElements.Count - 1].Certificateand determine if it is a certificate that you trust. I recommend comparingchainRoot.RawDatato abyte[]representing a certificate that you trust as a root in context (that is, byte-for-byte compare rather than using a thumbprint value).(If other flags are set then other constraints are also relaxed)