FTP: add support for client certificate authentication

This commit is contained in:
Nicola Murino
2020-12-29 09:20:09 +01:00
parent 141ca6777c
commit 40e759c983
10 changed files with 62 additions and 10 deletions

View File

@@ -152,10 +152,15 @@ func (s *Server) AuthUser(cc ftpserver.ClientContext, username, password string)
// GetTLSConfig returns a TLS Certificate to use
func (s *Server) GetTLSConfig() (*tls.Config, error) {
if certMgr != nil {
return &tls.Config{
tlsConfig := &tls.Config{
GetCertificate: certMgr.GetCertificateFunc(),
MinVersion: tls.VersionTLS12,
}, nil
}
if s.binding.ClientAuthType == 1 {
tlsConfig.ClientCAs = certMgr.GetRootCAs()
tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert
}
return tlsConfig, nil
}
return nil, errors.New("no TLS certificate configured")
}