Skip to content

Commit 636d31c

Browse files
committed
tls.VersionName is go 1.21, copy the function
1 parent 54b64f9 commit 636d31c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

cli/server.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -1537,13 +1537,13 @@ func configureCipherSuites(ctx context.Context, logger slog.Logger, ciphers []st
15371537
if !hasSupportedVersion(minTLS, maxTLS, cipher.SupportedVersions) {
15381538
versions := make([]string, 0, len(cipher.SupportedVersions))
15391539
for _, sv := range cipher.SupportedVersions {
1540-
versions = append(versions, tls.VersionName(sv))
1540+
versions = append(versions, versionName(sv))
15411541
}
15421542
logger.Warn(ctx, "cipher not supported for tls versions enabled, cipher will not be used",
15431543
slog.F("cipher", cipher.Name),
15441544
slog.F("cipher_supported_versions", strings.Join(versions, ",")),
1545-
slog.F("server_min_version", tls.VersionName(minTLS)),
1546-
slog.F("server_max_version", tls.VersionName(maxTLS)),
1545+
slog.F("server_min_version", versionName(minTLS)),
1546+
slog.F("server_max_version", versionName(maxTLS)),
15471547
)
15481548
}
15491549

@@ -1567,7 +1567,7 @@ func configureCipherSuites(ctx context.Context, logger slog.Logger, ciphers []st
15671567
continue // v1.3 ignores configured cipher suites.
15681568
}
15691569
if !covered {
1570-
missedVersions = append(missedVersions, tls.VersionName(version))
1570+
missedVersions = append(missedVersions, versionName(version))
15711571
}
15721572
}
15731573
if len(missedVersions) > 0 {
@@ -1631,6 +1631,25 @@ func hasSupportedVersion(min, max uint16, versions []uint16) bool {
16311631
return false
16321632
}
16331633

1634+
// versionName is tls.VersionName in go 1.21.
1635+
// Until the switch, the function is copied locally.
1636+
func versionName(version uint16) string {
1637+
switch version {
1638+
case tls.VersionSSL30:
1639+
return "SSLv3"
1640+
case tls.VersionTLS10:
1641+
return "TLS 1.0"
1642+
case tls.VersionTLS11:
1643+
return "TLS 1.1"
1644+
case tls.VersionTLS12:
1645+
return "TLS 1.2"
1646+
case tls.VersionTLS13:
1647+
return "TLS 1.3"
1648+
default:
1649+
return fmt.Sprintf("0x%04X", version)
1650+
}
1651+
}
1652+
16341653
func configureOIDCPKI(orig *oauth2.Config, keyFile string, certFile string) (*oauthpki.Config, error) {
16351654
// Read the files
16361655
keyData, err := os.ReadFile(keyFile)

0 commit comments

Comments
 (0)