Skip to content

Commit 6ed9d0a

Browse files
committed
feat(client): optionally customize TLS1.2 cipher suites
Signed-off-by: Pierre-Henri Symoneaux <[email protected]>
1 parent c9c555b commit 6ed9d0a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

kmipclient/client.go

+39-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type opts struct {
2626
certs []tls.Certificate
2727
serverName string
2828
tlsCfg *tls.Config
29+
tlsCiphers []uint16
2930
//TODO: Add KMIP Authentication / Credentials
3031
//TODO: Overwrite default/preferred/supported key formats for register
3132
}
@@ -36,7 +37,6 @@ func (o *opts) tlsConfig() (*tls.Config, error) {
3637
cfg = &tls.Config{
3738
MinVersion: tls.VersionTLS12, // As required by KMIP 1.4 spec
3839

39-
// // TODO: Make cipher suites configurable and do not add by default legacy ones
4040
// CipherSuites: []uint16{
4141
// // Mandatory support as per KMIP 1.4 spec
4242
// // tls.TLS_RSA_WITH_AES_256_CBC_SHA256, // Not supported in Go
@@ -71,6 +71,13 @@ func (o *opts) tlsConfig() (*tls.Config, error) {
7171
if cfg.ServerName == "" {
7272
cfg.ServerName = o.serverName
7373
}
74+
75+
for _, cipher := range o.tlsCiphers {
76+
if !slices.Contains(cfg.CipherSuites, cipher) {
77+
cfg.CipherSuites = append(cfg.CipherSuites, cipher)
78+
}
79+
}
80+
7481
return cfg, nil
7582
}
7683

@@ -167,6 +174,37 @@ func WithTlsConfig(cfg *tls.Config) Option {
167174
}
168175
}
169176

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+
170208
type Client struct {
171209
lock *sync.Mutex
172210
conn *conn

0 commit comments

Comments
 (0)