-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: crypto/x509: make CertPool.contains public #39179
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
Comments
@stephen-fox what's your use-case? |
@icholy, I am working on a library that is utilized by a TLS server checking tool. One of the data points I would like to examine is whether a certificate provided by a TLS server is already in the CertPool containing the trusted CAs. |
/cc @FiloSottile |
You can do a map lookup of RawSubject against CertPool.Subjects(). Does that solve your use case? |
Thank you for the suggestion. I initially thought the same thing. However, that only provides the subject field of each certificate in the In addition to the map lookup by subject, the |
For your purposes (checking if the server sent a root) the Subject should be enough: the only case I can think of in which a server would want to send a certificate with a Subject matching a trusted root is if it's a compatibility cross-cert, and you can simply check for that by verifying it's not self-signed. Exposing contains would force us to retain full representations of the roots in memory, while we have pending CLs that lazy load them for performance, relying on the limited API, and we might not even have the full certificate for the system pool on some platforms (like Windows). |
Interesting. You will have to forgive my naïve understanding of the
If I am understanding you correctly, the CertPool may not contain a full representation of a certificate depending how the CertPool was initialized? My concern with using the A few questions too - what do you mean by "CLs"? Also, when you say "relying on a limited API", are you referring to the CA trust store APIs offered by operating systems? I have been following your trials and tribulations with macOS, so that is my first guess :) Thank you for bearing with me. |
Looks to me like this fundamental gap that's been opened up in the API has caused people to have to fork x509 all over the place 🙄 And now it looks like I might have to also 😭 FTR, my use case is simply to be able to count or iterate the certificates in a pool that has been created and passed to my function, so I can log a debug line. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. The
x509.CertPool
related source code inrelease-branch.go1.14
does not appear to have changed, and is not public.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Searched the go source code for alternative paths to
CertPool.contains()
. I have not found an alternative yet.What did you expect to see?
A public equivalent to
CertPool.contains()
, or another code path that accesses the method by taking aCertPool
as input (e.g.,x509.IsCertIn(*Certificate, *CertPool) bool
).What did you see instead?
There does not appear to be any public code to determine if a
CertPool
contains a given certificate.Notes
I would like to make
x509.CertPool.contains()
public. Before submitting any changes, I figured I would ask :) I do not see any (obvious) reasons why it would be kept private in the source code, or ingit blame
.Thank you for reading.
The text was updated successfully, but these errors were encountered: