Browse Source

http2/h2i: strip port from server name in client hello

The existing implementation passes hostname:port to the ServerName
field of the client's TLS config. This is passed to the server
incorrectly as the ServerName in the client hello. This change adds a
function to strip the port from the host when passing it to the TLS
config.

Change-Id: I03714ffc7f21d87c375f8f07392ef02bbe76da66
Reviewed-on: https://go-review.googlesource.com/34728
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
voutasaurus 9 years ago
parent
commit
e99677b929
1 changed files with 9 additions and 1 deletions
  1. 9 1
      http2/h2i/h2i.go

+ 9 - 1
http2/h2i/h2i.go

@@ -88,6 +88,14 @@ func withPort(host string) string {
 	return host
 	return host
 }
 }
 
 
+// withoutPort strips the port from addr if present.
+func withoutPort(addr string) string {
+	if h, _, err := net.SplitHostPort(addr); err == nil {
+		return h
+	}
+	return addr
+}
+
 // h2i is the app's state.
 // h2i is the app's state.
 type h2i struct {
 type h2i struct {
 	host   string
 	host   string
@@ -134,7 +142,7 @@ func main() {
 
 
 func (app *h2i) Main() error {
 func (app *h2i) Main() error {
 	cfg := &tls.Config{
 	cfg := &tls.Config{
-		ServerName:         app.host,
+		ServerName:         withoutPort(app.host),
 		NextProtos:         strings.Split(*flagNextProto, ","),
 		NextProtos:         strings.Split(*flagNextProto, ","),
 		InsecureSkipVerify: *flagInsecure,
 		InsecureSkipVerify: *flagInsecure,
 	}
 	}