Skip to content

Commit

Permalink
tls: fix server side verification (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Feb 22, 2023
1 parent c68bfd3 commit a55e6b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/util/security/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (ci *CertInfo) verifyPeerCertificate(rawCerts [][]byte, _ [][]*x509.Certifi
}
if ci.server {
opts.KeyUsages = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}
} else {
// this is the default behavior of Verify()
// it is not necessary but explicit
opts.KeyUsages = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
}
// TODO: not implemented, maybe later
// opts.DNSName = ci.serverName
Expand Down Expand Up @@ -226,7 +230,7 @@ func (ci *CertInfo) buildServerConfig(lg *zap.Logger) (*tls.Config, error) {
ci.ca.Store(cas)

if ci.cfg.SkipCA {
tcfg.ClientAuth = tls.VerifyClientCertIfGiven
tcfg.ClientAuth = tls.RequestClientCert
} else {
tcfg.ClientAuth = tls.RequireAnyClientCert
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/security/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestCertServer(t *testing.T) {
},
checker: func(t *testing.T, c *tls.Config, ci *CertInfo) {
require.NotNil(t, c)
require.Equal(t, tls.VerifyClientCertIfGiven, c.ClientAuth)
require.Equal(t, tls.RequestClientCert, c.ClientAuth)
require.NotNil(t, ci.ca.Load())
require.NotNil(t, ci.cert.Load())
},
Expand Down

0 comments on commit a55e6b6

Please sign in to comment.