Skip to content

Commit

Permalink
Use constants for tls versions
Browse files Browse the repository at this point in the history
  • Loading branch information
p53 committed Oct 28, 2024
1 parent 35bfe7e commit 7d5ee9a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions pkg/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ const (
DefaultOpaTimeout = 10 * time.Second

ForwardingGrantTypePassword = "password"

TLS13 = "tlsv1.3"
TLS12 = "tlsv1.2"
)

var SignatureAlgs = [3]jose.SignatureAlgorithm{jose.RS256, jose.HS256, jose.HS512}
6 changes: 3 additions & 3 deletions pkg/google/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func NewDefaultConfig() *Config {
SkipAccessTokenIssuerCheck: true,
SkipAccessTokenClientIDCheck: true,
Tags: make(map[string]string),
TLSMinVersion: "tlsv1.3",
TLSMinVersion: constant.TLS13,
UpstreamExpectContinueTimeout: constant.DefaultUpstreamExpectContinueTimeout,
UpstreamKeepaliveTimeout: constant.DefaultUpstreamKeepaliveTimeout,
UpstreamKeepalives: true,
Expand Down Expand Up @@ -485,8 +485,8 @@ func (r *Config) isTLSMinValid() error {
switch strings.ToLower(r.TLSMinVersion) {
case "":
return apperrors.ErrMinimalTLSVersionEmpty
case "tlsv1.2":
case "tlsv1.3":
case constant.TLS12:
case constant.TLS13:
default:
return apperrors.ErrInvalidMinimalTLSVersion
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/keycloak/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func NewDefaultConfig() *Config {
SkipAccessTokenIssuerCheck: true,
SkipAccessTokenClientIDCheck: true,
Tags: make(map[string]string),
TLSMinVersion: "tlsv1.3",
TLSMinVersion: constant.TLS13,
UpstreamExpectContinueTimeout: constant.DefaultUpstreamExpectContinueTimeout,
UpstreamKeepaliveTimeout: constant.DefaultUpstreamKeepaliveTimeout,
UpstreamKeepalives: true,
Expand Down Expand Up @@ -491,8 +491,8 @@ func (r *Config) isTLSMinValid() error {
switch strings.ToLower(r.TLSMinVersion) {
case "":
return apperrors.ErrMinimalTLSVersionEmpty
case "tlsv1.2":
case "tlsv1.3":
case constant.TLS12:
case constant.TLS13:
default:
return apperrors.ErrInvalidMinimalTLSVersion
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/keycloak/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestIsConfig(t *testing.T) {
Upstream: "http://120.0.0.1",
MaxIdleConns: 100,
MaxIdleConnsPerHost: 50,
TLSMinVersion: "tlsv1.2",
TLSMinVersion: constant.TLS12,
},
Ok: true,
},
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestIsConfig(t *testing.T) {
Upstream: "http://120.0.0.1",
MaxIdleConns: 100,
MaxIdleConnsPerHost: 50,
TLSMinVersion: "tlsv1.3",
TLSMinVersion: constant.TLS13,
},
Ok: true,
},
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestIsConfig(t *testing.T) {
SecureCookie: true,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 50,
TLSMinVersion: "tlsv1.3",
TLSMinVersion: constant.TLS13,
},
Ok: true,
},
Expand Down Expand Up @@ -1222,14 +1222,14 @@ func TestIsTLSMinValid(t *testing.T) {
{
Name: "ValidTLS1.2",
Config: &Config{
TLSMinVersion: "tlsv1.2",
TLSMinVersion: constant.TLS12,
},
Valid: true,
},
{
Name: "ValidTLS1.3",
Config: &Config{
TLSMinVersion: "tlsv1.3",
TLSMinVersion: constant.TLS13,
},
Valid: true,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/keycloak/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,9 @@ func makeListenerConfig(config *config.Config) listenerConfig {
switch strings.ToLower(config.TLSMinVersion) {
case "":
minTLSVersion = 0 // zero means default value
case "tlsv1.2":
case constant.TLS12:
minTLSVersion = tls.VersionTLS12
case "tlsv1.3":
case constant.TLS13:
minTLSVersion = tls.VersionTLS13
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/testsuite/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ func TestTLS(t *testing.T) {
conf.TLSPrivateKey = os.TempDir() + FakePrivFilePrefix + strconv.Itoa(rand.Intn(10000))
conf.TLSCaCertificate = os.TempDir() + FakeCaFilePrefix + strconv.Itoa(rand.Intn(10000))
conf.Listen = testProxyAddr
conf.TLSMinVersion = "tlsv1.3"
conf.TLSMinVersion = constant.TLS13
conf.NoRedirects = true
},
ExecutionSettings: []fakeRequest{
Expand All @@ -1891,7 +1891,7 @@ func TestTLS(t *testing.T) {
conf.TLSPrivateKey = os.TempDir() + FakePrivFilePrefix + strconv.Itoa(rand.Intn(10000))
conf.TLSCaCertificate = os.TempDir() + FakeCaFilePrefix + strconv.Itoa(rand.Intn(10000))
conf.Listen = testProxyAddr
conf.TLSMinVersion = "tlsv1.2"
conf.TLSMinVersion = constant.TLS12
conf.NoRedirects = true
},
ExecutionSettings: []fakeRequest{
Expand All @@ -1912,7 +1912,7 @@ func TestTLS(t *testing.T) {
conf.TLSPrivateKey = os.TempDir() + FakePrivFilePrefix + strconv.Itoa(rand.Intn(10000))
conf.TLSCaCertificate = os.TempDir() + FakeCaFilePrefix + strconv.Itoa(rand.Intn(10000))
conf.Listen = testProxyAddr
conf.TLSMinVersion = "tlsv1.3"
conf.TLSMinVersion = constant.TLS13
},
ExecutionSettings: []fakeRequest{
{
Expand Down

0 comments on commit 7d5ee9a

Please sign in to comment.