Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package connection |
| 8 | |
| 9 | import "crypto/tls" |
| 10 | |
| 11 | // Clone returns a shallow clone of c. It is safe to clone a Config that is being |
| 12 | // used concurrently by a TLS client or server. |
| 13 | func (c *TLSConfig) Clone() *TLSConfig { |
| 14 | cfg := cloneconfig(c.Config) |
| 15 | return &TLSConfig{cfg, c.clientCertPass} |
| 16 | } |
| 17 | |
| 18 | func cloneconfig(c *tls.Config) *tls.Config { |
| 19 | return &tls.Config{ |
| 20 | Rand: c.Rand, |
| 21 | Time: c.Time, |
| 22 | Certificates: c.Certificates, |
| 23 | NameToCertificate: c.NameToCertificate, |
| 24 | GetCertificate: c.GetCertificate, |
| 25 | RootCAs: c.RootCAs, |
| 26 | NextProtos: c.NextProtos, |
| 27 | ServerName: c.ServerName, |
| 28 | ClientAuth: c.ClientAuth, |
| 29 | ClientCAs: c.ClientCAs, |
| 30 | InsecureSkipVerify: c.InsecureSkipVerify, |
| 31 | CipherSuites: c.CipherSuites, |
| 32 | PreferServerCipherSuites: c.PreferServerCipherSuites, |
| 33 | SessionTicketsDisabled: c.SessionTicketsDisabled, |
| 34 | SessionTicketKey: c.SessionTicketKey, |
| 35 | ClientSessionCache: c.ClientSessionCache, |
| 36 | MinVersion: c.MinVersion, |
| 37 | MaxVersion: c.MaxVersion, |
| 38 | CurvePreferences: c.CurvePreferences, |
| 39 | DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, |
| 40 | Renegotiation: c.Renegotiation, |
| 41 | } |
| 42 | } |