Skip to content

Commit

Permalink
security: set minimum version to TLS11 (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Apr 11, 2023
1 parent 9e46036 commit bd8d8aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/util/security/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (ci *CertInfo) buildServerConfig(lg *zap.Logger) (*tls.Config, error) {
}

tcfg := &tls.Config{
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
GetCertificate: ci.getCert,
GetClientCertificate: ci.getClientCert,
VerifyPeerCertificate: ci.verifyPeerCertificate,
Expand Down Expand Up @@ -243,15 +243,15 @@ func (ci *CertInfo) buildClientConfig(lg *zap.Logger) (*tls.Config, error) {
// still enable TLS without verify server certs
return &tls.Config{
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
}, nil
}
lg.Info("no CA to verify server connections, disable TLS")
return nil, nil
}

tcfg := &tls.Config{
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
GetCertificate: ci.getCert,
GetClientCertificate: ci.getClientCert,
InsecureSkipVerify: true,
Expand Down
9 changes: 9 additions & 0 deletions lib/util/security/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestCertServer(t *testing.T) {
require.NotNil(t, c)
require.Nil(t, ci.ca.Load())
require.NotNil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand All @@ -86,6 +87,7 @@ func TestCertServer(t *testing.T) {
require.NotNil(t, c)
require.Nil(t, ci.ca.Load())
require.NotNil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand All @@ -101,6 +103,7 @@ func TestCertServer(t *testing.T) {
require.Equal(t, tls.RequireAnyClientCert, c.ClientAuth)
require.NotNil(t, ci.ca.Load())
require.NotNil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand All @@ -117,6 +120,7 @@ func TestCertServer(t *testing.T) {
require.Equal(t, tls.RequestClientCert, c.ClientAuth)
require.NotNil(t, ci.ca.Load())
require.NotNil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand All @@ -131,6 +135,7 @@ func TestCertServer(t *testing.T) {
require.Equal(t, tls.RequireAnyClientCert, c.ClientAuth)
require.NotNil(t, ci.ca.Load())
require.NotNil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand Down Expand Up @@ -162,6 +167,7 @@ func TestCertServer(t *testing.T) {
require.NotNil(t, c)
require.Nil(t, ci.ca.Load())
require.Nil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand All @@ -174,6 +180,7 @@ func TestCertServer(t *testing.T) {
require.NotNil(t, c)
require.Nil(t, ci.ca.Load())
require.Nil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand All @@ -185,6 +192,7 @@ func TestCertServer(t *testing.T) {
require.NotNil(t, c)
require.NotNil(t, ci.ca.Load())
require.Nil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand All @@ -198,6 +206,7 @@ func TestCertServer(t *testing.T) {
require.NotNil(t, c)
require.NotNil(t, ci.ca.Load())
require.NotNil(t, ci.cert.Load())
require.Equal(t, tls.VersionTLS11, int(c.MinVersion))
},
err: "",
},
Expand Down
10 changes: 5 additions & 5 deletions lib/util/security/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ func CreateTLSConfigForTest() (serverTLSConf *tls.Config, clientTLSConf *tls.Con
}

serverTLSConf = &tls.Config{
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
Certificates: []tls.Certificate{serverCert},
}

certpool := x509.NewCertPool()
certpool.AppendCertsFromPEM(caPEM)
clientTLSConf = &tls.Config{
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
InsecureSkipVerify: true,
RootCAs: certpool,
}
Expand All @@ -218,7 +218,7 @@ func BuildServerTLSConfig(logger *zap.Logger, cfg config.TLSConfig) (*tls.Config
}

tcfg := &tls.Config{
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
}
cert, err := tls.LoadX509KeyPair(cfg.Cert, cfg.Key)
if err != nil {
Expand Down Expand Up @@ -250,15 +250,15 @@ func BuildClientTLSConfig(logger *zap.Logger, cfg config.TLSConfig) (*tls.Config
// still enable TLS without verify server certs
return &tls.Config{
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
}, nil
}
logger.Info("no CA to verify server connections, disable TLS")
return nil, nil
}

tcfg := &tls.Config{
MinVersion: tls.VersionTLS12,
MinVersion: tls.VersionTLS11,
}
tcfg.RootCAs = x509.NewCertPool()
certBytes, err := os.ReadFile(cfg.CA)
Expand Down

0 comments on commit bd8d8aa

Please sign in to comment.