Skip to content

Commit fb142ee

Browse files
committed
cmd/go: for go get -insecure, skip TLS certificate checking
The flag is already named -insecure. Make it more so. If we're willing to accept HTTP, it's not much worse to accept HTTPS man-in-the-middle attacks too. This allows servers with self-signed certificates to work. Fixes #13197. Change-Id: Ia5491410bc886da0a26ef3bce4bf7d732f5e19e4 Reviewed-on: https://go-review.googlesource.com/18324 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent c063e34 commit fb142ee

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/cmd/go/http.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package main
1313

1414
import (
15+
"crypto/tls"
1516
"fmt"
1617
"io"
1718
"io/ioutil"
@@ -24,8 +25,17 @@ import (
2425
// httpClient is the default HTTP client, but a variable so it can be
2526
// changed by tests, without modifying http.DefaultClient.
2627
var httpClient = http.DefaultClient
27-
var impatientHTTPClient = &http.Client{
28+
29+
// impatientInsecureHTTPClient is used in -insecure mode,
30+
// when we're connecting to https servers that might not be there
31+
// or might be using self-signed certificates.
32+
var impatientInsecureHTTPClient = &http.Client{
2833
Timeout: time.Duration(5 * time.Second),
34+
Transport: &http.Transport{
35+
TLSClientConfig: &tls.Config{
36+
InsecureSkipVerify: true,
37+
},
38+
},
2939
}
3040

3141
type httpError struct {
@@ -71,7 +81,7 @@ func httpsOrHTTP(importPath string, security securityMode) (urlStr string, body
7181
log.Printf("Fetching %s", urlStr)
7282
}
7383
if security == insecure && scheme == "https" { // fail earlier
74-
res, err = impatientHTTPClient.Get(urlStr)
84+
res, err = impatientInsecureHTTPClient.Get(urlStr)
7585
} else {
7686
res, err = httpClient.Get(urlStr)
7787
}

0 commit comments

Comments
 (0)