@@ -25,23 +25,18 @@ import (
25
25
26
26
// ciphers maps strings into tls package cipher constants in
27
27
// https://golang.org/pkg/crypto/tls/#pkg-constants
28
+ // to be replaced by tls.CipherSuites() when the project migrates to go1.14.
28
29
var ciphers = map [string ]uint16 {
29
- "TLS_RSA_WITH_RC4_128_SHA" : tls .TLS_RSA_WITH_RC4_128_SHA ,
30
30
"TLS_RSA_WITH_3DES_EDE_CBC_SHA" : tls .TLS_RSA_WITH_3DES_EDE_CBC_SHA ,
31
31
"TLS_RSA_WITH_AES_128_CBC_SHA" : tls .TLS_RSA_WITH_AES_128_CBC_SHA ,
32
32
"TLS_RSA_WITH_AES_256_CBC_SHA" : tls .TLS_RSA_WITH_AES_256_CBC_SHA ,
33
- "TLS_RSA_WITH_AES_128_CBC_SHA256" : tls .TLS_RSA_WITH_AES_128_CBC_SHA256 ,
34
33
"TLS_RSA_WITH_AES_128_GCM_SHA256" : tls .TLS_RSA_WITH_AES_128_GCM_SHA256 ,
35
34
"TLS_RSA_WITH_AES_256_GCM_SHA384" : tls .TLS_RSA_WITH_AES_256_GCM_SHA384 ,
36
- "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" : tls .TLS_ECDHE_ECDSA_WITH_RC4_128_SHA ,
37
35
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" : tls .TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA ,
38
36
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" : tls .TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA ,
39
- "TLS_ECDHE_RSA_WITH_RC4_128_SHA" : tls .TLS_ECDHE_RSA_WITH_RC4_128_SHA ,
40
37
"TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" : tls .TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA ,
41
38
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" : tls .TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA ,
42
39
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" : tls .TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ,
43
- "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" : tls .TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 ,
44
- "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" : tls .TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ,
45
40
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" : tls .TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
46
41
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" : tls .TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ,
47
42
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" : tls .TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
@@ -53,21 +48,76 @@ var ciphers = map[string]uint16{
53
48
"TLS_AES_256_GCM_SHA384" : tls .TLS_AES_256_GCM_SHA384 ,
54
49
}
55
50
56
- func TLSCipherPossibleValues () []string {
51
+ // to be replaced by tls.InsecureCipherSuites() when the project migrates to go1.14.
52
+ var insecureCiphers = map [string ]uint16 {
53
+ "TLS_RSA_WITH_RC4_128_SHA" : tls .TLS_RSA_WITH_RC4_128_SHA ,
54
+ "TLS_RSA_WITH_AES_128_CBC_SHA256" : tls .TLS_RSA_WITH_AES_128_CBC_SHA256 ,
55
+ "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" : tls .TLS_ECDHE_ECDSA_WITH_RC4_128_SHA ,
56
+ "TLS_ECDHE_RSA_WITH_RC4_128_SHA" : tls .TLS_ECDHE_RSA_WITH_RC4_128_SHA ,
57
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" : tls .TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 ,
58
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" : tls .TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 ,
59
+ }
60
+
61
+ // InsecureTLSCiphers returns the cipher suites implemented by crypto/tls which have
62
+ // security issues.
63
+ func InsecureTLSCiphers () map [string ]uint16 {
64
+ cipherKeys := make (map [string ]uint16 , len (insecureCiphers ))
65
+ for k , v := range insecureCiphers {
66
+ cipherKeys [k ] = v
67
+ }
68
+ return cipherKeys
69
+ }
70
+
71
+ // InsecureTLSCipherNames returns a list of cipher suite names implemented by crypto/tls
72
+ // which have security issues.
73
+ func InsecureTLSCipherNames () []string {
74
+ cipherKeys := sets .NewString ()
75
+ for key := range insecureCiphers {
76
+ cipherKeys .Insert (key )
77
+ }
78
+ return cipherKeys .List ()
79
+ }
80
+
81
+ // PreferredTLSCipherNames returns a list of cipher suite names implemented by crypto/tls.
82
+ func PreferredTLSCipherNames () []string {
57
83
cipherKeys := sets .NewString ()
58
84
for key := range ciphers {
59
85
cipherKeys .Insert (key )
60
86
}
61
87
return cipherKeys .List ()
62
88
}
63
89
90
+ func allCiphers () map [string ]uint16 {
91
+ acceptedCiphers := make (map [string ]uint16 , len (ciphers )+ len (insecureCiphers ))
92
+ for k , v := range ciphers {
93
+ acceptedCiphers [k ] = v
94
+ }
95
+ for k , v := range insecureCiphers {
96
+ acceptedCiphers [k ] = v
97
+ }
98
+ return acceptedCiphers
99
+ }
100
+
101
+ // TLSCipherPossibleValues returns all acceptable cipher suite names.
102
+ // This is a combination of both InsecureTLSCipherNames() and PreferredTLSCipherNames().
103
+ func TLSCipherPossibleValues () []string {
104
+ cipherKeys := sets .NewString ()
105
+ acceptedCiphers := allCiphers ()
106
+ for key := range acceptedCiphers {
107
+ cipherKeys .Insert (key )
108
+ }
109
+ return cipherKeys .List ()
110
+ }
111
+
112
+ // TLSCipherSuites returns a list of cipher suite IDs from the cipher suite names passed.
64
113
func TLSCipherSuites (cipherNames []string ) ([]uint16 , error ) {
65
114
if len (cipherNames ) == 0 {
66
115
return nil , nil
67
116
}
68
117
ciphersIntSlice := make ([]uint16 , 0 )
118
+ possibleCiphers := allCiphers ()
69
119
for _ , cipher := range cipherNames {
70
- intValue , ok := ciphers [cipher ]
120
+ intValue , ok := possibleCiphers [cipher ]
71
121
if ! ok {
72
122
return nil , fmt .Errorf ("Cipher suite %s not supported or doesn't exist" , cipher )
73
123
}
@@ -83,6 +133,7 @@ var versions = map[string]uint16{
83
133
"VersionTLS13" : tls .VersionTLS13 ,
84
134
}
85
135
136
+ // TLSPossibleVersions returns all acceptable values for TLS Version.
86
137
func TLSPossibleVersions () []string {
87
138
versionsKeys := sets .NewString ()
88
139
for key := range versions {
@@ -91,6 +142,7 @@ func TLSPossibleVersions() []string {
91
142
return versionsKeys .List ()
92
143
}
93
144
145
+ // TLSVersion returns the TLS Version ID for the version name passed.
94
146
func TLSVersion (versionName string ) (uint16 , error ) {
95
147
if len (versionName ) == 0 {
96
148
return DefaultTLSVersion (), nil
@@ -101,6 +153,7 @@ func TLSVersion(versionName string) (uint16, error) {
101
153
return 0 , fmt .Errorf ("unknown tls version %q" , versionName )
102
154
}
103
155
156
+ // DefaultTLSVersion defines the default TLS Version.
104
157
func DefaultTLSVersion () uint16 {
105
158
// Can't use SSLv3 because of POODLE and BEAST
106
159
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
0 commit comments