Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X509VerificationFlags.AllowUnknownCertificateAuthority behavior #26449

Closed
davidorbelian opened this issue Jun 11, 2018 · 2 comments
Closed

X509VerificationFlags.AllowUnknownCertificateAuthority behavior #26449

davidorbelian opened this issue Jun 11, 2018 · 2 comments
Labels
area-System.Security question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@davidorbelian
Copy link

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.

@bartonjs
Copy link
Member

If AllowUnknownCertificateAuthority is the only flag set then chain.Build() will return true if

  • The chain correctly terminated in a self-signed certificate (via ExtraStore, or searched persisted stores)
  • None of the certificates are invalid per the requested revocation policy
  • All of the certificates are valid under the (optional) ApplicationPolicy or CertificatePolicy values
  • All of the certificates' NotBefore values are at-or-before VerificationTime and all of the certificates' NotAfter values are (at-or-)after VerificationTime.

If that flag is not specified then an additional constraint is added:

  • The self-signed certificate must be registered as trusted on the system (e.g. in the LM\Root store).

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)

@davidorbelian
Copy link
Author

@bartonjs Now it became clear, thanks! I think you can close the issue?

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Security question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

3 participants