Skip to content

Commit db58021

Browse files
crypto/tls: don't copy Mutex or Once values
This fixes some 40 warnings from go vet. Fixes #16134. Change-Id: Ib9fcba275fe692f027a2a07b581c8cf503b11087 Reviewed-on: https://go-review.googlesource.com/24287 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent b43fe46 commit db58021

File tree

6 files changed

+174
-90
lines changed

6 files changed

+174
-90
lines changed

src/crypto/tls/common.go

+27
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,33 @@ func ticketKeyFromBytes(b [32]byte) (key ticketKey) {
422422
return key
423423
}
424424

425+
// clone returns a copy of c. Only the exported fields are copied.
426+
func (c *Config) clone() *Config {
427+
return &Config{
428+
Rand: c.Rand,
429+
Time: c.Time,
430+
Certificates: c.Certificates,
431+
NameToCertificate: c.NameToCertificate,
432+
GetCertificate: c.GetCertificate,
433+
RootCAs: c.RootCAs,
434+
NextProtos: c.NextProtos,
435+
ServerName: c.ServerName,
436+
ClientAuth: c.ClientAuth,
437+
ClientCAs: c.ClientCAs,
438+
InsecureSkipVerify: c.InsecureSkipVerify,
439+
CipherSuites: c.CipherSuites,
440+
PreferServerCipherSuites: c.PreferServerCipherSuites,
441+
SessionTicketsDisabled: c.SessionTicketsDisabled,
442+
SessionTicketKey: c.SessionTicketKey,
443+
ClientSessionCache: c.ClientSessionCache,
444+
MinVersion: c.MinVersion,
445+
MaxVersion: c.MaxVersion,
446+
CurvePreferences: c.CurvePreferences,
447+
DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled,
448+
Renegotiation: c.Renegotiation,
449+
}
450+
}
451+
425452
func (c *Config) serverInit() {
426453
if c.SessionTicketsDisabled {
427454
return

src/crypto/tls/conn_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ func TestCertificateSelection(t *testing.T) {
124124
func runDynamicRecordSizingTest(t *testing.T, config *Config) {
125125
clientConn, serverConn := net.Pipe()
126126

127-
serverConfig := *config
127+
serverConfig := config.clone()
128128
serverConfig.DynamicRecordSizingDisabled = false
129-
tlsConn := Server(serverConn, &serverConfig)
129+
tlsConn := Server(serverConn, serverConfig)
130130

131131
recordSizesChan := make(chan []int, 1)
132132
go func() {
@@ -225,19 +225,19 @@ func runDynamicRecordSizingTest(t *testing.T, config *Config) {
225225
}
226226

227227
func TestDynamicRecordSizingWithStreamCipher(t *testing.T) {
228-
config := *testConfig
228+
config := testConfig.clone()
229229
config.CipherSuites = []uint16{TLS_RSA_WITH_RC4_128_SHA}
230-
runDynamicRecordSizingTest(t, &config)
230+
runDynamicRecordSizingTest(t, config)
231231
}
232232

233233
func TestDynamicRecordSizingWithCBC(t *testing.T) {
234-
config := *testConfig
234+
config := testConfig.clone()
235235
config.CipherSuites = []uint16{TLS_RSA_WITH_AES_256_CBC_SHA}
236-
runDynamicRecordSizingTest(t, &config)
236+
runDynamicRecordSizingTest(t, config)
237237
}
238238

239239
func TestDynamicRecordSizingWithAEAD(t *testing.T) {
240-
config := *testConfig
240+
config := testConfig.clone()
241241
config.CipherSuites = []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256}
242-
runDynamicRecordSizingTest(t, &config)
242+
runDynamicRecordSizingTest(t, config)
243243
}

src/crypto/tls/handshake_client_test.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,14 @@ func TestHandshakeClientAES256GCMSHA384(t *testing.T) {
509509
}
510510

511511
func TestHandshakeClientCertRSA(t *testing.T) {
512-
config := *testConfig
512+
config := testConfig.clone()
513513
cert, _ := X509KeyPair([]byte(clientCertificatePEM), []byte(clientKeyPEM))
514514
config.Certificates = []Certificate{cert}
515515

516516
test := &clientTest{
517517
name: "ClientCert-RSA-RSA",
518518
command: []string{"openssl", "s_server", "-cipher", "RC4-SHA", "-verify", "1"},
519-
config: &config,
519+
config: config,
520520
}
521521

522522
runClientTestTLS10(t, test)
@@ -525,7 +525,7 @@ func TestHandshakeClientCertRSA(t *testing.T) {
525525
test = &clientTest{
526526
name: "ClientCert-RSA-ECDSA",
527527
command: []string{"openssl", "s_server", "-cipher", "ECDHE-ECDSA-AES128-SHA", "-verify", "1"},
528-
config: &config,
528+
config: config,
529529
cert: testECDSACertificate,
530530
key: testECDSAPrivateKey,
531531
}
@@ -536,7 +536,7 @@ func TestHandshakeClientCertRSA(t *testing.T) {
536536
test = &clientTest{
537537
name: "ClientCert-RSA-AES256-GCM-SHA384",
538538
command: []string{"openssl", "s_server", "-cipher", "ECDHE-RSA-AES256-GCM-SHA384", "-verify", "1"},
539-
config: &config,
539+
config: config,
540540
cert: testRSACertificate,
541541
key: testRSAPrivateKey,
542542
}
@@ -545,14 +545,14 @@ func TestHandshakeClientCertRSA(t *testing.T) {
545545
}
546546

547547
func TestHandshakeClientCertECDSA(t *testing.T) {
548-
config := *testConfig
548+
config := testConfig.clone()
549549
cert, _ := X509KeyPair([]byte(clientECDSACertificatePEM), []byte(clientECDSAKeyPEM))
550550
config.Certificates = []Certificate{cert}
551551

552552
test := &clientTest{
553553
name: "ClientCert-ECDSA-RSA",
554554
command: []string{"openssl", "s_server", "-cipher", "RC4-SHA", "-verify", "1"},
555-
config: &config,
555+
config: config,
556556
}
557557

558558
runClientTestTLS10(t, test)
@@ -561,7 +561,7 @@ func TestHandshakeClientCertECDSA(t *testing.T) {
561561
test = &clientTest{
562562
name: "ClientCert-ECDSA-ECDSA",
563563
command: []string{"openssl", "s_server", "-cipher", "ECDHE-ECDSA-AES128-SHA", "-verify", "1"},
564-
config: &config,
564+
config: config,
565565
cert: testECDSACertificate,
566566
key: testECDSAPrivateKey,
567567
}
@@ -691,15 +691,15 @@ func TestLRUClientSessionCache(t *testing.T) {
691691
}
692692

693693
func TestHandshakeClientALPNMatch(t *testing.T) {
694-
config := *testConfig
694+
config := testConfig.clone()
695695
config.NextProtos = []string{"proto2", "proto1"}
696696

697697
test := &clientTest{
698698
name: "ALPN",
699699
// Note that this needs OpenSSL 1.0.2 because that is the first
700700
// version that supports the -alpn flag.
701701
command: []string{"openssl", "s_server", "-alpn", "proto1,proto2"},
702-
config: &config,
702+
config: config,
703703
validate: func(state ConnectionState) error {
704704
// The server's preferences should override the client.
705705
if state.NegotiatedProtocol != "proto1" {
@@ -712,15 +712,15 @@ func TestHandshakeClientALPNMatch(t *testing.T) {
712712
}
713713

714714
func TestHandshakeClientALPNNoMatch(t *testing.T) {
715-
config := *testConfig
715+
config := testConfig.clone()
716716
config.NextProtos = []string{"proto3"}
717717

718718
test := &clientTest{
719719
name: "ALPN-NoMatch",
720720
// Note that this needs OpenSSL 1.0.2 because that is the first
721721
// version that supports the -alpn flag.
722722
command: []string{"openssl", "s_server", "-alpn", "proto1,proto2"},
723-
config: &config,
723+
config: config,
724724
validate: func(state ConnectionState) error {
725725
// There's no overlap so OpenSSL will not select a protocol.
726726
if state.NegotiatedProtocol != "" {
@@ -736,7 +736,7 @@ func TestHandshakeClientALPNNoMatch(t *testing.T) {
736736
const sctsBase64 = "ABIBaQFnAHUApLkJkLQYWBSHuxOizGdwCjw1mAT5G9+443fNDsgN3BAAAAFHl5nuFgAABAMARjBEAiAcS4JdlW5nW9sElUv2zvQyPoZ6ejKrGGB03gjaBZFMLwIgc1Qbbn+hsH0RvObzhS+XZhr3iuQQJY8S9G85D9KeGPAAdgBo9pj4H2SCvjqM7rkoHUz8cVFdZ5PURNEKZ6y7T0/7xAAAAUeX4bVwAAAEAwBHMEUCIDIhFDgG2HIuADBkGuLobU5a4dlCHoJLliWJ1SYT05z6AiEAjxIoZFFPRNWMGGIjskOTMwXzQ1Wh2e7NxXE1kd1J0QsAdgDuS723dc5guuFCaR+r4Z5mow9+X7By2IMAxHuJeqj9ywAAAUhcZIqHAAAEAwBHMEUCICmJ1rBT09LpkbzxtUC+Hi7nXLR0J+2PmwLp+sJMuqK+AiEAr0NkUnEVKVhAkccIFpYDqHOlZaBsuEhWWrYpg2RtKp0="
737737

738738
func TestHandshakClientSCTs(t *testing.T) {
739-
config := *testConfig
739+
config := testConfig.clone()
740740

741741
scts, err := base64.StdEncoding.DecodeString(sctsBase64)
742742
if err != nil {
@@ -748,7 +748,7 @@ func TestHandshakClientSCTs(t *testing.T) {
748748
// Note that this needs OpenSSL 1.0.2 because that is the first
749749
// version that supports the -serverinfo flag.
750750
command: []string{"openssl", "s_server"},
751-
config: &config,
751+
config: config,
752752
extensions: [][]byte{scts},
753753
validate: func(state ConnectionState) error {
754754
expectedSCTs := [][]byte{
@@ -771,11 +771,11 @@ func TestHandshakClientSCTs(t *testing.T) {
771771
}
772772

773773
func TestRenegotiationRejected(t *testing.T) {
774-
config := *testConfig
774+
config := testConfig.clone()
775775
test := &clientTest{
776776
name: "RenegotiationRejected",
777777
command: []string{"openssl", "s_server", "-state"},
778-
config: &config,
778+
config: config,
779779
numRenegotiations: 1,
780780
renegotiationExpectedToFail: 1,
781781
checkRenegotiationError: func(renegotiationNum int, err error) error {
@@ -793,41 +793,41 @@ func TestRenegotiationRejected(t *testing.T) {
793793
}
794794

795795
func TestRenegotiateOnce(t *testing.T) {
796-
config := *testConfig
796+
config := testConfig.clone()
797797
config.Renegotiation = RenegotiateOnceAsClient
798798

799799
test := &clientTest{
800800
name: "RenegotiateOnce",
801801
command: []string{"openssl", "s_server", "-state"},
802-
config: &config,
802+
config: config,
803803
numRenegotiations: 1,
804804
}
805805

806806
runClientTestTLS12(t, test)
807807
}
808808

809809
func TestRenegotiateTwice(t *testing.T) {
810-
config := *testConfig
810+
config := testConfig.clone()
811811
config.Renegotiation = RenegotiateFreelyAsClient
812812

813813
test := &clientTest{
814814
name: "RenegotiateTwice",
815815
command: []string{"openssl", "s_server", "-state"},
816-
config: &config,
816+
config: config,
817817
numRenegotiations: 2,
818818
}
819819

820820
runClientTestTLS12(t, test)
821821
}
822822

823823
func TestRenegotiateTwiceRejected(t *testing.T) {
824-
config := *testConfig
824+
config := testConfig.clone()
825825
config.Renegotiation = RenegotiateOnceAsClient
826826

827827
test := &clientTest{
828828
name: "RenegotiateTwiceRejected",
829829
command: []string{"openssl", "s_server", "-state"},
830-
config: &config,
830+
config: config,
831831
numRenegotiations: 2,
832832
renegotiationExpectedToFail: 2,
833833
checkRenegotiationError: func(renegotiationNum int, err error) error {

0 commit comments

Comments
 (0)