Skip to content

Commit

Permalink
*: fix TLS cases (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Nov 2, 2022
1 parent b8de341 commit 73255cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/manager/cert/cert_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"go.uber.org/zap"
)

var emptyCert = new(tls.Certificate)

// Security configurations don't support dynamically updating now.
type certInfo struct {
cfg config.TLSConfig
Expand Down Expand Up @@ -124,7 +126,12 @@ func (ci *certInfo) customizeTLSConfig(tlsConfig *tls.Config) *tls.Config {
}
} else {
tlsConfig.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
return ci.getCertificate(), nil
cert := ci.getCertificate()
if cert == nil {
// GetClientCertificate must return a non-nil Certificate.
return emptyCert, nil
}
return cert, nil
}
if !tlsConfig.InsecureSkipVerify {
tlsConfig.InsecureSkipVerify = true
Expand Down
4 changes: 2 additions & 2 deletions pkg/proxy/backend/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (auth *Authenticator) handshakeFirstTime(logger *zap.Logger, clientIO *pnet
resp.AuthPlugin = "auth_unknown_plugin"
resp.Capability = auth.capability

if backendCapability&pnet.ClientSSL != 0 {
if backendCapability&pnet.ClientSSL != 0 && backendTLSConfig != nil {
resp.Capability |= mysql.ClientSSL
pkt = pnet.MakeHandshakeResponse(resp)
// write SSL Packet
Expand Down Expand Up @@ -294,7 +294,7 @@ func (auth *Authenticator) writeAuthHandshake(backendIO *pnet.PacketIO, authData
}
data := pnet.MakeHandshakeResponse(resp)

if tls {
if tls && auth.backendTLSConfig != nil {
// write SSL req
if err := backendIO.WritePacket(data[:32], true); err != nil {
return err
Expand Down

0 comments on commit 73255cd

Please sign in to comment.