Skip to content

Commit

Permalink
add SSL MinVersion
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Oct 30, 2024
1 parent e257097 commit fc1a77d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions client/pd_service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,17 @@ func TestServiceClientScheme(t *testing.T) {
re.Equal("http://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("http://127.0.0.1:2379", nil), modifyURLScheme("127.0.0.1:2379", nil), nil, false)
re.Equal("http://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("127.0.0.1:2379", &tls.Config{}), modifyURLScheme("127.0.0.1:2379", &tls.Config{}), nil, false)
cli = newPDServiceClient(modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), nil, false)
re.Equal("https://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("https://127.0.0.1:2379", &tls.Config{}), modifyURLScheme("127.0.0.1:2379", &tls.Config{}), nil, false)
cli = newPDServiceClient(modifyURLScheme("https://127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), nil, false)
re.Equal("https://127.0.0.1:2379", cli.GetURL())
cli = newPDServiceClient(modifyURLScheme("http://127.0.0.1:2379", &tls.Config{}), modifyURLScheme("127.0.0.1:2379", &tls.Config{}), nil, false)
cli = newPDServiceClient(modifyURLScheme("http://127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), modifyURLScheme("127.0.0.1:2379", &tls.Config{MinVersion: tls.VersionTLS12}), nil, false)
re.Equal("https://127.0.0.1:2379", cli.GetURL())
}

func TestSchemeFunction(t *testing.T) {
re := require.New(t)
tlsCfg := &tls.Config{}
tlsCfg := &tls.Config{MinVersion: tls.VersionTLS12}

endpoints1 := []string{
"http://tc-pd:2379",
Expand Down
3 changes: 2 additions & 1 deletion client/tlsutil/tlsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (info tlsInfo) clientConfig() (*tls.Config, error) {
return nil, err
}
} else {
cfg = &tls.Config{ServerName: info.serverName}
cfg = &tls.Config{ServerName: info.serverName, MinVersion: tls.VersionTLS12}
}
cfg.InsecureSkipVerify = info.insecureSkipVerify

Expand Down Expand Up @@ -190,6 +190,7 @@ func (s TLSConfig) ToTLSConfig() (*tls.Config, error) {
Certificates: certificates,
RootCAs: certPool,
NextProtos: []string{"h2", "http/1.1"}, // specify `h2` to let Go use HTTP/2.
MinVersion: tls.VersionTLS12,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/utils/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (s TLSConfig) ToTLSConfig() (*tls.Config, error) {
Certificates: certificates,
RootCAs: certPool,
NextProtos: []string{"h2", "http/1.1"}, // specify `h2` to let Go use HTTP/2.
MinVersion: tls.VersionTLS12,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/netutil/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestIsEnableHttps(t *testing.T) {
httpClient = &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{},
TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12},
},
}
re.False(IsEnableHTTPS(httpClient))
Expand Down

0 comments on commit fc1a77d

Please sign in to comment.