[go] cmd/pprof: add options to skip tls verification

37 views
Skip to first unread message

Brad Fitzpatrick (Gerrit)

unread,
Nov 12, 2016, 1:30:18 PM11/12/16
to Patrick Lee, Brad Fitzpatrick, golang-...@googlegroups.com, Gobot Gobot, golang-co...@googlegroups.com

Brad Fitzpatrick merged cmd/pprof: add options to skip tls verification.

View Change

cmd/pprof: add options to skip tls verification

Don't verify tls host when profiling https+insecure://host/port/...,
as per discussion in https://go-review.googlesource.com/#/c/20885/.

Fixes: #11468

Change-Id: Ibfc236e5442a00339334602a4014e017c62d9e7a
Reviewed-on: https://go-review.googlesource.com/33157
Reviewed-by: Brad Fitzpatrick <brad...@golang.org>
Run-TryBot: Brad Fitzpatrick <brad...@golang.org>
TryBot-Result: Gobot Gobot <go...@golang.org>
---
M src/cmd/pprof/internal/fetch/fetch.go
1 file changed, 18 insertions(+), 2 deletions(-)

Approvals:
  Brad Fitzpatrick: Looks good to me, approved; Run TryBots
  Gobot Gobot: TryBots succeeded

diff --git a/src/cmd/pprof/internal/fetch/fetch.go b/src/cmd/pprof/internal/fetch/fetch.go
index 2e2de57..d3ccb65 100644
--- a/src/cmd/pprof/internal/fetch/fetch.go
+++ b/src/cmd/pprof/internal/fetch/fetch.go
@@ -7,6 +7,7 @@
 package fetch
 
 import (
+	"crypto/tls"
 	"fmt"
 	"io"
 	"io/ioutil"
@@ -72,11 +73,26 @@
 
 // httpGet is a wrapper around http.Get; it is defined as a variable
 // so it can be redefined during for testing.
-var httpGet = func(url string, timeout time.Duration) (*http.Response, error) {
+var httpGet = func(source string, timeout time.Duration) (*http.Response, error) {
+	url, err := url.Parse(source)
+	if err != nil {
+		return nil, err
+	}
+
+	var tlsConfig *tls.Config
+	if url.Scheme == "https+insecure" {
+		tlsConfig = &tls.Config{
+			InsecureSkipVerify: true,
+		}
+		url.Scheme = "https"
+		source = url.String()
+	}
+
 	client := &http.Client{
 		Transport: &http.Transport{
 			ResponseHeaderTimeout: timeout + 5*time.Second,
+			TLSClientConfig:       tlsConfig,
 		},
 	}
-	return client.Get(url)
+	return client.Get(source)
 }

To view, visit this change. To unsubscribe, visit settings.

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibfc236e5442a00339334602a4014e017c62d9e7a
Gerrit-PatchSet: 2
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Owner: Patrick Lee <pattys...@gmail.com>Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>Gerrit-Reviewer: Gobot Gobot <go...@golang.org>

Reply all
Reply to author
Forward
0 new messages