mirror of
https://github.com/golang/go.git
synced 2025-05-30 19:52:53 +00:00
net/http: remove test-only private key from production binaries
The net/http/internal package contains a PEM-encoded private key used in tests. This key is initialized at init time, which prevents it from being stripped by the linker in non-test binaries. Move the certificate and key to a new net/http/internal/testcert package to ensure it is only included in binaries that reference it. Fixes #46677. Change-Id: Ie98bda529169314cc791063e7ce4d99ef99113c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/326771 Trust: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
8d11b1d117
commit
770f1de8c5
@ -440,7 +440,8 @@ var depsRules = `
|
|||||||
# HTTP, King of Dependencies.
|
# HTTP, King of Dependencies.
|
||||||
|
|
||||||
FMT
|
FMT
|
||||||
< golang.org/x/net/http2/hpack, net/http/internal, net/http/internal/ascii;
|
< golang.org/x/net/http2/hpack
|
||||||
|
< net/http/internal, net/http/internal/ascii, net/http/internal/testcert;
|
||||||
|
|
||||||
FMT, NET, container/list, encoding/binary, log
|
FMT, NET, container/list, encoding/binary, log
|
||||||
< golang.org/x/text/transform
|
< golang.org/x/text/transform
|
||||||
@ -459,6 +460,7 @@ var depsRules = `
|
|||||||
golang.org/x/net/http2/hpack,
|
golang.org/x/net/http2/hpack,
|
||||||
net/http/internal,
|
net/http/internal,
|
||||||
net/http/internal/ascii,
|
net/http/internal/ascii,
|
||||||
|
net/http/internal/testcert,
|
||||||
net/http/httptrace,
|
net/http/httptrace,
|
||||||
mime/multipart,
|
mime/multipart,
|
||||||
log
|
log
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/internal"
|
"net/http/internal/testcert"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -144,7 +144,7 @@ func (s *Server) StartTLS() {
|
|||||||
if s.client == nil {
|
if s.client == nil {
|
||||||
s.client = &http.Client{Transport: &http.Transport{}}
|
s.client = &http.Client{Transport: &http.Transport{}}
|
||||||
}
|
}
|
||||||
cert, err := tls.X509KeyPair(internal.LocalhostCert, internal.LocalhostKey)
|
cert, err := tls.X509KeyPair(testcert.LocalhostCert, testcert.LocalhostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("httptest: NewTLSServer: %v", err))
|
panic(fmt.Sprintf("httptest: NewTLSServer: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package internal
|
// Package testcert contains a test-only localhost certificate.
|
||||||
|
package testcert
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ h1fIw3cSS2OolhloGw/XM6RWPWtPAlGykKLciQrBru5NAPvCMsb/I1DAceTiotQM
|
|||||||
fblo6RBxUQ==
|
fblo6RBxUQ==
|
||||||
-----END CERTIFICATE-----`)
|
-----END CERTIFICATE-----`)
|
||||||
|
|
||||||
// LocalhostKey is the private key for localhostCert.
|
// LocalhostKey is the private key for LocalhostCert.
|
||||||
var LocalhostKey = []byte(testingKey(`-----BEGIN RSA TESTING KEY-----
|
var LocalhostKey = []byte(testingKey(`-----BEGIN RSA TESTING KEY-----
|
||||||
MIICXgIBAAKBgQDuLnQAI3mDgey3VBzWnB2L39JUU4txjeVE6myuDqkM/uGlfjb9
|
MIICXgIBAAKBgQDuLnQAI3mDgey3VBzWnB2L39JUU4txjeVE6myuDqkM/uGlfjb9
|
||||||
SjY1bIw4iA5sBBZzHi3z0h1YV8QPuxEbi4nW91IJm2gsvvZhIrCHS3l6afab4pZB
|
SjY1bIw4iA5sBBZzHi3z0h1YV8QPuxEbi4nW91IJm2gsvvZhIrCHS3l6afab4pZB
|
@ -25,6 +25,7 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/http/internal"
|
"net/http/internal"
|
||||||
|
"net/http/internal/testcert"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -1475,7 +1476,7 @@ func TestServeTLS(t *testing.T) {
|
|||||||
defer afterTest(t)
|
defer afterTest(t)
|
||||||
defer SetTestHookServerServe(nil)
|
defer SetTestHookServerServe(nil)
|
||||||
|
|
||||||
cert, err := tls.X509KeyPair(internal.LocalhostCert, internal.LocalhostKey)
|
cert, err := tls.X509KeyPair(testcert.LocalhostCert, testcert.LocalhostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1599,7 +1600,7 @@ func TestAutomaticHTTP2_Serve_WithTLSConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAutomaticHTTP2_ListenAndServe(t *testing.T) {
|
func TestAutomaticHTTP2_ListenAndServe(t *testing.T) {
|
||||||
cert, err := tls.X509KeyPair(internal.LocalhostCert, internal.LocalhostKey)
|
cert, err := tls.X509KeyPair(testcert.LocalhostCert, testcert.LocalhostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -1609,7 +1610,7 @@ func TestAutomaticHTTP2_ListenAndServe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAutomaticHTTP2_ListenAndServe_GetCertificate(t *testing.T) {
|
func TestAutomaticHTTP2_ListenAndServe_GetCertificate(t *testing.T) {
|
||||||
cert, err := tls.X509KeyPair(internal.LocalhostCert, internal.LocalhostKey)
|
cert, err := tls.X509KeyPair(testcert.LocalhostCert, testcert.LocalhostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http/internal"
|
"net/http/internal/testcert"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -191,7 +191,7 @@ func (f roundTripFunc) RoundTrip(r *Request) (*Response, error) {
|
|||||||
|
|
||||||
// Issue 25009
|
// Issue 25009
|
||||||
func TestTransportBodyAltRewind(t *testing.T) {
|
func TestTransportBodyAltRewind(t *testing.T) {
|
||||||
cert, err := tls.X509KeyPair(internal.LocalhostCert, internal.LocalhostKey)
|
cert, err := tls.X509KeyPair(testcert.LocalhostCert, testcert.LocalhostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httptrace"
|
"net/http/httptrace"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/http/internal"
|
"net/http/internal/testcert"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -4299,7 +4299,7 @@ func TestTransportReuseConnEmptyResponseBody(t *testing.T) {
|
|||||||
|
|
||||||
// Issue 13839
|
// Issue 13839
|
||||||
func TestNoCrashReturningTransportAltConn(t *testing.T) {
|
func TestNoCrashReturningTransportAltConn(t *testing.T) {
|
||||||
cert, err := tls.X509KeyPair(internal.LocalhostCert, internal.LocalhostKey)
|
cert, err := tls.X509KeyPair(testcert.LocalhostCert, testcert.LocalhostKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user