Commit 2638001e authored by Paul Querna's avatar Paul Querna Committed by Filippo Valsorda

net/http: remove extraneous call to VerifyHostname

VerifyHostname is called by tls.Conn during Handshake and does not need to be called explicitly.

Change-Id: I22b7fa137e76bb4be3d0018813a571acfb882219
Reviewed-on: https://go-review.googlesource.com/98618
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarFilippo Valsorda <filippo@golang.org>
parent 8a151924
......@@ -1078,12 +1078,6 @@ func (pconn *persistConn) addTLS(name string, trace *httptrace.ClientTrace) erro
}
return err
}
if !cfg.InsecureSkipVerify {
if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
plainConn.Close()
return err
}
}
cs := tlsConn.ConnectionState()
if trace != nil && trace.TLSHandshakeDone != nil {
trace.TLSHandshakeDone(cs, nil)
......
......@@ -16,6 +16,7 @@ import (
"context"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"encoding/binary"
"errors"
"fmt"
......@@ -3716,6 +3717,64 @@ func testTransportEventTrace(t *testing.T, h2 bool, noHooks bool) {
}
}
func TestTransportEventTraceTLSVerify(t *testing.T) {
var mu sync.Mutex
var buf bytes.Buffer
logf := func(format string, args ...interface{}) {
mu.Lock()
defer mu.Unlock()
fmt.Fprintf(&buf, format, args...)
buf.WriteByte('\n')
}
ts := httptest.NewTLSServer(HandlerFunc(func(w ResponseWriter, r *Request) {
t.Error("Unexpected request")
}))
defer ts.Close()
certpool := x509.NewCertPool()
certpool.AddCert(ts.Certificate())
c := &Client{Transport: &Transport{
TLSClientConfig: &tls.Config{
ServerName: "dns-is-faked.golang",
RootCAs: certpool,
},
}}
trace := &httptrace.ClientTrace{
TLSHandshakeStart: func() { logf("TLSHandshakeStart") },
TLSHandshakeDone: func(s tls.ConnectionState, err error) {
logf("TLSHandshakeDone: ConnectionState = %v \n err = %v", s, err)
},
}
req, _ := NewRequest("GET", ts.URL, nil)
req = req.WithContext(httptrace.WithClientTrace(context.Background(), trace))
_, err := c.Do(req)
if err == nil {
t.Error("Expected request to fail TLS verification")
}
mu.Lock()
got := buf.String()
mu.Unlock()
wantOnce := func(sub string) {
if strings.Count(got, sub) != 1 {
t.Errorf("expected substring %q exactly once in output.", sub)
}
}
wantOnce("TLSHandshakeStart")
wantOnce("TLSHandshakeDone")
wantOnce("err = x509: certificate is valid for example.com")
if t.Failed() {
t.Errorf("Output:\n%s", got)
}
}
var (
isDNSHijackedOnce sync.Once
isDNSHijacked bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment