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

net/http: tls.Config.ServerName ignored on line 501 of net/http/transport.go #5829

Closed
gopherbot opened this issue Jul 2, 2013 · 3 comments
Closed
Milestone

Comments

@gopherbot
Copy link

by mail@stefanofratini.it:

Hello

I've been struggling with an annoying problem with HTTPS communication between 2 golang
powered hosts (both go1.1 powered)

The server component uses a certificate signed by a CA that I've generated with openssl

The client component connects to the server via https using the public key of CA as the
rootCA for the connection

Everything works fine if the client connects to the server using a DNS name. Instead if
the client connects specifying an IP address in the URL and using the ServerName field
of the tls.Config struct:

tr := &http.Transport{
        TLSClientConfig: &tls.Config{RootCAs: certPool, ServerName: "host-name"},
    }

the hostname validation fails.

It seemed to me like the ServerName field was somewhere ignored and I think I was
correct.

I've identified the problem at the following lines (starting from 501) of
net/http/transport.go

if t.TLSClientConfig == nil || !t.TLSClientConfig.InsecureSkipVerify {
            if err = conn.(*tls.Conn).VerifyHostname(cm.tlsHost()); err != nil {
                return nil, err
            }
        }

The correct code should be instead

if t.TLSClientConfig == nil || !t.TLSClientConfig.InsecureSkipVerify {
            if err = conn.(*tls.Conn).VerifyHostname(cfg.ServerName); err != nil {
                return nil, err
            }
        }

I've recompiled GO and tested the new code successfully

I'm not sure what's the best way to contribute new code as I'm not a Mercurial expert...
Apologies if I'm entering this in the wrong place

**Which compiler are you using (5g, 6g, 8g, gccgo)?**
Not sure, default linux compiler

**Which operating system are you using?**
Lubuntu 12.04

**Which version are you using?  (run 'go version')**
Go1.1

Stefano
@rsc
Copy link
Contributor

rsc commented Jul 8, 2013

Comment 1:

Labels changed: added priority-later, removed priority-triage.

Owner changed to @bradfitz.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jul 8, 2013

Comment 2:

Labels changed: added go1.2.

@bradfitz
Copy link
Contributor

Comment 3:

This issue was closed by revision baa9ca0.

Status changed to Fixed.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants