Skip to content

Commit

Permalink
undo client config change
Browse files Browse the repository at this point in the history
  • Loading branch information
yishuT committed Sep 18, 2021
1 parent ef9b5ca commit 6702671
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 10 additions & 3 deletions client/pkg/transport/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (info *TLSInfo) loadTLSConfig() *tls.Config {
if info.Logger != nil {
info.Logger.Info("tls config reload from files")
}
cfg, err := info.newTlsConfig()
cfg, err := info.serverConfig()
if err == nil {
info.tlsConfig.Store(cfg)
} else {
Expand All @@ -364,7 +364,7 @@ func (info *TLSInfo) tlsConfigRefreshLoop() {
}
}

func (info *TLSInfo) newTlsConfig() (*tls.Config, error) {
func (info *TLSInfo) baseConfig() (*tls.Config, error) {
if info.KeyFile == "" || info.CertFile == "" {
return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.KeyFile, info.CertFile)
}
Expand Down Expand Up @@ -450,7 +450,14 @@ func (info *TLSInfo) newTlsConfig() (*tls.Config, error) {
return errors.New("client certificate authentication failed")
}
}
return cfg, nil
}

func (info *TLSInfo) serverConfig() (*tls.Config, error) {
cfg, err := info.baseConfig()
if err != nil {
return nil, err
}
cfg.ClientAuth = tls.NoClientCert
if info.TrustedCAFile != "" || info.ClientCertAuth {
cfg.ClientAuth = tls.RequireAndVerifyClientCert
Expand Down Expand Up @@ -559,7 +566,7 @@ func (info *TLSInfo) ClientConfig() (*tls.Config, error) {
var err error

if !info.Empty() {
cfg, err = info.newTlsConfig()
cfg, err = info.baseConfig()
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions client/pkg/transport/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func TestNewTransportTLSInfo(t *testing.T) {

func TestTLSInfoNonexist(t *testing.T) {
tlsInfo := TLSInfo{CertFile: "@badname", KeyFile: "@badname"}
_, err := tlsInfo.newTlsConfig()
_, err := tlsInfo.serverConfig()
werr := &os.PathError{
Op: "open",
Path: "@badname",
Expand Down Expand Up @@ -441,10 +441,10 @@ func TestTLSInfoMissingFields(t *testing.T) {
}

for i, info := range tests {
_, err = info.newTlsConfig()
_, err = info.serverConfig()

if err == nil {
t.Errorf("#%d: expected non nil error from newTlsConfig()", i)
t.Errorf("#%d: expected non nil error from serverConfig()", i)
}

if _, err = info.ClientConfig(); err == nil {
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestTLSInfoParseFuncError(t *testing.T) {
for i, tt := range tests {
tt.info.parseFunc = fakeCertificateParserFunc(tls.Certificate{}, errors.New("fake"))

if _, err = tt.info.newTlsConfig(); err == nil {
if _, err = tt.info.serverConfig(); err == nil {
t.Errorf("#%d: expected non-nil error from ServerConfig()", i)
}

Expand Down Expand Up @@ -514,7 +514,7 @@ func TestTLSInfoConfigFuncs(t *testing.T) {
for i, tt := range tests {
tt.info.parseFunc = fakeCertificateParserFunc(tls.Certificate{}, nil)

sCfg, err := tt.info.newTlsConfig()
sCfg, err := tt.info.serverConfig()
if err != nil {
t.Errorf("#%d: expected nil error from ServerConfig(), got non-nil: %v", i, err)
}
Expand Down

0 comments on commit 6702671

Please sign in to comment.