feat(healthcheck): run TLS handshake after TCP dial if address has 443 port
This commit is contained in:
@@ -2,9 +2,11 @@ package healthcheck
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -79,6 +81,22 @@ func (s *Server) healthCheck(ctx context.Context) (err error) {
|
|||||||
return fmt.Errorf("dialing: %w", err)
|
return fmt.Errorf("dialing: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(address, ":443") {
|
||||||
|
host, _, err := net.SplitHostPort(address)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("splitting host and port: %w", err)
|
||||||
|
}
|
||||||
|
tlsConfig := &tls.Config{
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
ServerName: host,
|
||||||
|
}
|
||||||
|
tlsConnection := tls.Client(connection, tlsConfig)
|
||||||
|
err = tlsConnection.HandshakeContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("running TLS handshake: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = connection.Close()
|
err = connection.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("closing connection: %w", err)
|
return fmt.Errorf("closing connection: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user