Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Improve error message
  • Loading branch information
Emyrk committed Nov 3, 2023
commit fc034993ffe5eff5297f835b4e140e157d496a39
7 changes: 4 additions & 3 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,13 +1503,14 @@ func configureServerTLS(ctx context.Context, logger slog.Logger, tlsMinVersion,

//nolint:revive
func configureCipherSuites(ctx context.Context, logger slog.Logger, ciphers []string, allowInsecureCiphers bool, minTLS, maxTLS uint16) ([]uint16, error) {
fmt.Println(ciphers)
if minTLS > maxTLS {
return nil, xerrors.Errorf("minimum tls version cannot be greater than maximum tls version")
return nil, xerrors.Errorf("minimum tls version (%s) cannot be greater than maximum tls version (%s)", versionName(minTLS), versionName(maxTLS))
}
if minTLS >= tls.VersionTLS13 {
// The cipher suites config option is ignored for tls 1.3 and higher.
// So this user flag is a no-op if the min version is 1.3.
return nil, xerrors.Errorf("tls ciphers cannot be specified when using minimum tls version 1.3 or higher")
return nil, xerrors.Errorf("'--tls-ciphers' cannot be specified when using minimum tls version 1.3 or higher, %d ciphers found as input.", len(ciphers))
}
// Configure the cipher suites which parses the strings and converts them
// to golang cipher suites.
Expand Down Expand Up @@ -1615,7 +1616,7 @@ func parseTLSCipherSuites(ciphers []string) ([]tls.CipherSuite, error) {
}

if len(unsupported) > 0 {
return nil, xerrors.Errorf("unsupported tls ciphers specified: %s", strings.Join(unsupported, ", "))
return nil, xerrors.Errorf("unsupported tls ciphers specified, see https://github.com/golang/go/blob/master/src/crypto/tls/cipher_suites.go#L53-L75: %s", strings.Join(unsupported, ", "))
}

return supported, nil
Expand Down
4 changes: 2 additions & 2 deletions cli/server_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Test_configureCipherSuites(t *testing.T) {
minTLS: tls.VersionTLS13,
maxTLS: tls.VersionTLS13,
inputCiphers: cipherNames(tls.CipherSuites()),
wantErr: "tls ciphers cannot be specified when using minimum tls version 1.3",
wantErr: "'--tls-ciphers' cannot be specified when using minimum tls version 1.3",
},
{
name: "TLSUnsupported",
Expand All @@ -142,7 +142,7 @@ func Test_configureCipherSuites(t *testing.T) {
name: "Min>Max",
minTLS: tls.VersionTLS13,
maxTLS: tls.VersionTLS12,
wantErr: "minimum tls version cannot be greater than maximum tls version",
wantErr: "minimum tls version (TLS 1.3) cannot be greater than maximum tls version (TLS 1.2)",
},
}
for _, tt := range tests {
Expand Down