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

Tls rootca option #337

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

garmr-ulfr
Copy link

@garmr-ulfr garmr-ulfr commented Nov 22, 2024

This adds a way to include a custom Root CA to the TLS transport. (#315)

@fortuna fortuna self-requested a review December 5, 2024 16:07
@garmr-ulfr
Copy link
Author

Hey @fortuna! Do you have an time frame for when this will be merged in?

@@ -94,6 +94,8 @@ type ClientConfig struct {
NextProtos []string
// The cache for sessin resumption.
SessionCache tls.ClientSessionCache
// The root certificate authorities for client to use for certificate verification.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update the validation function, otherwise I think this will have no effect.

It would be helpful to have a test to exercise this. I wonder if LLM can help 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLM?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to generate the test that shows it working/not working, because it's a bit complicated to create the test. But we can probably piggy back on existing tests somewhere

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example test: https://pkg.go.dev/crypto/tls#example-Dial

We need to redesign the certificate validation. I don't want to repeat the same mistake many TLS libraries do that spread a bunch of options that tweak validation, making it hard to figure out what options are relevant for what and how they interact.

We should get rid of all validation options (CertificateName, RootCA), and replace with a VerifyConnection function instead. Unlike the standard function, I'd make it take a slice of PeerCertificates, not tls.ConnectionState, so we don't tie it to the standard TLS implementation.

Then we can provide a helper struct type with CertificateName and RootCAs that implements the verify function. It needs to set x509.VerifyOptions.Roots and DNSName. That function can be passed to our tls.ClientConfig.

If someone wants the "InsecureSkipVerify" behavior, they can simply set a function that returns nil.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooohh, OK. I will do that!

@@ -94,6 +94,8 @@ type ClientConfig struct {
NextProtos []string
// The cache for sessin resumption.
SessionCache tls.ClientSessionCache
// The root certificate authorities for client to use for certificate verification.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example test: https://pkg.go.dev/crypto/tls#example-Dial

We need to redesign the certificate validation. I don't want to repeat the same mistake many TLS libraries do that spread a bunch of options that tweak validation, making it hard to figure out what options are relevant for what and how they interact.

We should get rid of all validation options (CertificateName, RootCA), and replace with a VerifyConnection function instead. Unlike the standard function, I'd make it take a slice of PeerCertificates, not tls.ConnectionState, so we don't tie it to the standard TLS implementation.

Then we can provide a helper struct type with CertificateName and RootCAs that implements the verify function. It needs to set x509.VerifyOptions.Roots and DNSName. That function can be passed to our tls.ClientConfig.

If someone wants the "InsecureSkipVerify" behavior, they can simply set a function that returns nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants