-
Notifications
You must be signed in to change notification settings - Fork 376
Implement TLS VerifyPeerCertificate callback to skip hostname verfication #238
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -711,8 +711,46 @@ func (c *connection) getTLSConfig() (*tls.Config, error) { | |
| } | ||
| } | ||
|
|
||
| if c.tlsOptions.ValidateHostname { | ||
| tlsConfig.ServerName = c.physicalAddr.Hostname() | ||
| tlsConfig.ServerName = c.physicalAddr.Hostname() | ||
|
|
||
| if tlsConfig.InsecureSkipVerify { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't |
||
| // Solution is credited to https://github.com/golang/go/issues/21971 | ||
| // Code is adapted from the original implementation of handshake_client.go at | ||
| // https://github.com/golang/go/blob/master/src/crypto/tls/handshake_client.go#L804 | ||
| // disable the default verification; use customized VerifyPeerCertificate | ||
| tlsConfig.VerifyPeerCertificate = func(rawCerts [][]byte, certChain [][]*x509.Certificate) error { | ||
| // If this is the first handshake on a connection, process and | ||
| // (optionally) verify the server's certificates. | ||
| certs := make([]*x509.Certificate, len(rawCerts)) | ||
| for i, asn1Data := range rawCerts { | ||
| cert, err := x509.ParseCertificate(asn1Data) | ||
| if err != nil { | ||
| return fmt.Errorf("tls: failed to parse server certificate error: %s", err.Error()) | ||
| } | ||
| certs[i] = cert | ||
| } | ||
|
|
||
| if tlsConfig.RootCAs == nil { | ||
| return nil | ||
| } | ||
|
Comment on lines
+733
to
+735
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would this deal with the common scenario where the client is using the system's bundle? I am unsure of whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just ran into this. As-is verification will return success when no roots are loaded. |
||
|
|
||
| // Verify certs if they exist but skip ServerName validation | ||
| opts := x509.VerifyOptions{ | ||
| Roots: tlsConfig.RootCAs, | ||
| CurrentTime: time.Now(), | ||
| DNSName: "", // skip hostname verification | ||
| Intermediates: x509.NewCertPool(), | ||
| } | ||
|
|
||
| for i, cert := range certs { | ||
| if i == 0 { | ||
| continue | ||
| } | ||
| opts.Intermediates.AddCert(cert) | ||
| } | ||
| _, err := certs[0].Verify(opts) | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| cert, err := c.auth.GetTLSCertificate() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't seem to do anything substantive. I'd expect it to exercise the resultant
tls.Configin some way, maybe by making an actual TLS connection.