@@ -26,6 +26,7 @@ type opts struct {
26
26
certs []tls.Certificate
27
27
serverName string
28
28
tlsCfg * tls.Config
29
+ tlsCiphers []uint16
29
30
//TODO: Add KMIP Authentication / Credentials
30
31
//TODO: Overwrite default/preferred/supported key formats for register
31
32
}
@@ -36,7 +37,6 @@ func (o *opts) tlsConfig() (*tls.Config, error) {
36
37
cfg = & tls.Config {
37
38
MinVersion : tls .VersionTLS12 , // As required by KMIP 1.4 spec
38
39
39
- // // TODO: Make cipher suites configurable and do not add by default legacy ones
40
40
// CipherSuites: []uint16{
41
41
// // Mandatory support as per KMIP 1.4 spec
42
42
// // tls.TLS_RSA_WITH_AES_256_CBC_SHA256, // Not supported in Go
@@ -71,6 +71,13 @@ func (o *opts) tlsConfig() (*tls.Config, error) {
71
71
if cfg .ServerName == "" {
72
72
cfg .ServerName = o .serverName
73
73
}
74
+
75
+ for _ , cipher := range o .tlsCiphers {
76
+ if ! slices .Contains (cfg .CipherSuites , cipher ) {
77
+ cfg .CipherSuites = append (cfg .CipherSuites , cipher )
78
+ }
79
+ }
80
+
74
81
return cfg , nil
75
82
}
76
83
@@ -167,6 +174,37 @@ func WithTlsConfig(cfg *tls.Config) Option {
167
174
}
168
175
}
169
176
177
+ func WithTlsCipherSuiteNames (ciphers ... string ) Option {
178
+ return func (o * opts ) error {
179
+ search:
180
+ for _ , cipherName := range ciphers {
181
+ for _ , s := range tls .CipherSuites () {
182
+ if s .Name != cipherName {
183
+ continue
184
+ }
185
+ o .tlsCiphers = append (o .tlsCiphers , s .ID )
186
+ continue search
187
+ }
188
+ for _ , s := range tls .InsecureCipherSuites () {
189
+ if s .Name != cipherName {
190
+ continue
191
+ }
192
+ o .tlsCiphers = append (o .tlsCiphers , s .ID )
193
+ continue search
194
+ }
195
+ return fmt .Errorf ("invalid TLS cipher name %q" , cipherName )
196
+ }
197
+ return nil
198
+ }
199
+ }
200
+
201
+ func WithTlsCipherSuites (ciphers ... uint16 ) Option {
202
+ return func (o * opts ) error {
203
+ o .tlsCiphers = append (o .tlsCiphers , ciphers ... )
204
+ return nil
205
+ }
206
+ }
207
+
170
208
type Client struct {
171
209
lock * sync.Mutex
172
210
conn * conn
0 commit comments