Skip to content

Commit 2596f85

Browse files
committed
refactor(tls): drop cipherMap, use Go's cipher suite lists directly
Replace the hand-maintained cipherMap allowlist with direct lookups against tls.CipherSuites() and tls.InsecureCipherSuites(): - Secure ciphers are accepted silently - Insecure ciphers are accepted but logged via klog.Warningf - Unrecognized names are still rejected (existing behavior) This removes the maintenance burden of keeping cipherMap in sync with Go's cipher suite lists, and automatically picks up new secure ciphers added in future Go releases. Previously excluded insecure ciphers (RC4-based, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA) are now accepted with a warning instead of being silently rejected. Signed-off-by: zhujian <jiazhu@redhat.com>
1 parent 2445a0c commit 2596f85

3 files changed

Lines changed: 37 additions & 42 deletions

File tree

pkg/tls/cipher.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

pkg/tls/config.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"crypto/tls"
55
"fmt"
66
"strings"
7+
8+
"k8s.io/klog/v2"
79
)
810

911
const (
@@ -45,12 +47,17 @@ func parseTLSVersion(version string) (uint16, error) {
4547
}
4648

4749
// parseCipherSuites converts IANA cipher suite names to Go crypto/tls constants.
48-
// Returns a list of cipher suite IDs and a list of unsupported cipher names.
50+
// Secure ciphers (tls.CipherSuites) are accepted silently. Insecure ciphers
51+
// (tls.InsecureCipherSuites) are accepted but logged as a warning.
52+
// Returns a list of cipher suite IDs and a list of unrecognized cipher names.
4953
func parseCipherSuites(cipherString string) ([]uint16, []string) {
5054
if strings.TrimSpace(cipherString) == "" {
5155
return nil, nil
5256
}
5357

58+
secureSuites := tls.CipherSuites()
59+
insecureSuites := tls.InsecureCipherSuites()
60+
5461
cipherNames := strings.Split(cipherString, ",")
5562
cipherSuites := make([]uint16, 0, len(cipherNames))
5663
unsupported := make([]string, 0)
@@ -61,16 +68,31 @@ func parseCipherSuites(cipherString string) ([]uint16, []string) {
6168
continue
6269
}
6370

64-
if suite, ok := cipherMap[name]; ok {
65-
cipherSuites = append(cipherSuites, suite)
66-
} else {
67-
unsupported = append(unsupported, name)
71+
if id, ok := findCipherID(name, secureSuites); ok {
72+
cipherSuites = append(cipherSuites, id)
73+
continue
74+
}
75+
if id, ok := findCipherID(name, insecureSuites); ok {
76+
klog.Warningf("Cipher suite %s is insecure and should not be used in production", name)
77+
cipherSuites = append(cipherSuites, id)
78+
continue
6879
}
80+
unsupported = append(unsupported, name)
6981
}
7082

7183
return cipherSuites, unsupported
7284
}
7385

86+
// findCipherID looks up a cipher suite by IANA name in the given list.
87+
func findCipherID(name string, suites []*tls.CipherSuite) (uint16, bool) {
88+
for _, s := range suites {
89+
if s.Name == name {
90+
return s.ID, true
91+
}
92+
}
93+
return 0, false
94+
}
95+
7496
// GetDefaultTLSConfig returns a TLS config with safe defaults (TLS 1.2)
7597
func GetDefaultTLSConfig() *TLSConfig {
7698
return &TLSConfig{

pkg/tls/tls_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,16 @@ func TestParseCipherSuites(t *testing.T) {
918918
cipherString: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
919919
expectedCount: 2,
920920
},
921+
{
922+
name: "insecure cipher accepted with warning",
923+
cipherString: "TLS_RSA_WITH_AES_128_GCM_SHA256",
924+
expectedCount: 1,
925+
},
926+
{
927+
name: "mix of secure and insecure ciphers",
928+
cipherString: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_128_GCM_SHA256",
929+
expectedCount: 2,
930+
},
921931
}
922932

923933
for _, tc := range cases {

0 commit comments

Comments
 (0)