@@ -36,40 +36,35 @@ type Options struct {
3636 MinVersion uint16
3737}
3838
39- // Extra (server-side) accepted CBC cipher suites - will phase out in the future
40- var acceptedCBCCiphers = []uint16 {
41- tls .TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA ,
42- tls .TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA ,
43- tls .TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ,
44- tls .TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA ,
45- }
46-
4739// DefaultServerAcceptedCiphers should be uses by code which already has a crypto/tls
4840// options struct but wants to use a commonly accepted set of TLS cipher suites, with
4941// known weak algorithms removed.
50- var DefaultServerAcceptedCiphers = append (clientCipherSuites , acceptedCBCCiphers ... )
42+ var DefaultServerAcceptedCiphers = defaultCipherSuites
43+
44+ // defaultCipherSuites is shared by both client and server as the default set.
45+ var defaultCipherSuites = []uint16 {
46+ tls .TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ,
47+ tls .TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
48+ tls .TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ,
49+ tls .TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
50+ }
5151
5252// ServerDefault returns a secure-enough TLS configuration for the server TLS configuration.
5353func ServerDefault (ops ... func (* tls.Config )) * tls.Config {
54- tlsConfig := & tls.Config {
55- // Avoid fallback by default to SSL protocols < TLS1.2
56- MinVersion : tls .VersionTLS12 ,
57- CipherSuites : DefaultServerAcceptedCiphers ,
58- }
59-
60- for _ , op := range ops {
61- op (tlsConfig )
62- }
63-
64- return tlsConfig
54+ return defaultConfig (ops ... )
6555}
6656
6757// ClientDefault returns a secure-enough TLS configuration for the client TLS configuration.
6858func ClientDefault (ops ... func (* tls.Config )) * tls.Config {
59+ return defaultConfig (ops ... )
60+ }
61+
62+ // defaultConfig is the default config used by both client and server TLS configuration.
63+ func defaultConfig (ops ... func (* tls.Config )) * tls.Config {
6964 tlsConfig := & tls.Config {
70- // Prefer TLS1.2 as the client minimum
65+ // Avoid fallback by default to SSL protocols < TLS1.2
7166 MinVersion : tls .VersionTLS12 ,
72- CipherSuites : clientCipherSuites ,
67+ CipherSuites : defaultCipherSuites ,
7368 }
7469
7570 for _ , op := range ops {
@@ -83,13 +78,13 @@ func ClientDefault(ops ...func(*tls.Config)) *tls.Config {
8378func certPool (caFile string , exclusivePool bool ) (* x509.CertPool , error ) {
8479 // If we should verify the server, we need to load a trusted ca
8580 var (
86- certPool * x509.CertPool
87- err error
81+ pool * x509.CertPool
82+ err error
8883 )
8984 if exclusivePool {
90- certPool = x509 .NewCertPool ()
85+ pool = x509 .NewCertPool ()
9186 } else {
92- certPool , err = SystemCertPool ()
87+ pool , err = SystemCertPool ()
9388 if err != nil {
9489 return nil , fmt .Errorf ("failed to read system certificates: %v" , err )
9590 }
@@ -98,10 +93,10 @@ func certPool(caFile string, exclusivePool bool) (*x509.CertPool, error) {
9893 if err != nil {
9994 return nil , fmt .Errorf ("could not read CA certificate %q: %v" , caFile , err )
10095 }
101- if ! certPool .AppendCertsFromPEM (pemData ) {
96+ if ! pool .AppendCertsFromPEM (pemData ) {
10297 return nil , fmt .Errorf ("failed to append certificates from PEM file: %q" , caFile )
10398 }
104- return certPool , nil
99+ return pool , nil
105100}
106101
107102// allTLSVersions lists all the TLS versions and is used by the code that validates
@@ -199,7 +194,7 @@ func getCert(options Options) ([]tls.Certificate, error) {
199194
200195// Client returns a TLS configuration meant to be used by a client.
201196func Client (options Options ) (* tls.Config , error ) {
202- tlsConfig := ClientDefault ()
197+ tlsConfig := defaultConfig ()
203198 tlsConfig .InsecureSkipVerify = options .InsecureSkipVerify
204199 if ! options .InsecureSkipVerify && options .CAFile != "" {
205200 CAs , err := certPool (options .CAFile , options .ExclusiveRootPools )
@@ -224,7 +219,7 @@ func Client(options Options) (*tls.Config, error) {
224219
225220// Server returns a TLS configuration meant to be used by a server.
226221func Server (options Options ) (* tls.Config , error ) {
227- tlsConfig := ServerDefault ()
222+ tlsConfig := defaultConfig ()
228223 tlsConfig .ClientAuth = options .ClientAuth
229224 tlsCert , err := tls .LoadX509KeyPair (options .CertFile , options .KeyFile )
230225 if err != nil {
0 commit comments