![dependabot[bot]](/assets/img/avatar_default.png) 84b5992e55
			
		
	
	84b5992e55
	
	
	
		
			
			* ci: bump golangci/golangci-lint-action from 6 to 7 Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6 to 7. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/v6...v7) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix lint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix v2 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix v3 Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
		
			
				
	
	
		
			69 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package ldap
 | |
| 
 | |
| import (
 | |
| 	"crypto/tls"
 | |
| 	"net"
 | |
| 
 | |
| 	"github.com/pires/go-proxyproto"
 | |
| 	"goauthentik.io/internal/config"
 | |
| 	"goauthentik.io/internal/utils"
 | |
| )
 | |
| 
 | |
| func (ls *LDAPServer) getCertificates(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
 | |
| 	if len(ls.providers) == 1 {
 | |
| 		if ls.providers[0].cert != nil {
 | |
| 			ls.log.WithField("server-name", info.ServerName).Debug("We only have a single provider, using their cert")
 | |
| 			return ls.providers[0].cert, nil
 | |
| 		}
 | |
| 	}
 | |
| 	allIdenticalCerts := true
 | |
| 	for _, provider := range ls.providers {
 | |
| 		if provider.tlsServerName == &info.ServerName {
 | |
| 			if provider.cert == nil {
 | |
| 				ls.log.WithField("server-name", info.ServerName).Debug("Handler does not have a certificate")
 | |
| 				return ls.defaultCert, nil
 | |
| 			}
 | |
| 			return provider.cert, nil
 | |
| 		}
 | |
| 		if provider.certUUID != ls.providers[0].certUUID || provider.cert == nil {
 | |
| 			allIdenticalCerts = false
 | |
| 		}
 | |
| 	}
 | |
| 	if allIdenticalCerts {
 | |
| 		ls.log.WithField("server-name", info.ServerName).Debug("all providers have the same keypair, using keypair")
 | |
| 		return ls.providers[0].cert, nil
 | |
| 	}
 | |
| 	ls.log.WithField("server-name", info.ServerName).Debug("Fallback to default cert")
 | |
| 	return ls.defaultCert, nil
 | |
| }
 | |
| 
 | |
| func (ls *LDAPServer) StartLDAPTLSServer() error {
 | |
| 	listen := config.Get().Listen.LDAPS
 | |
| 	tlsConfig := utils.GetTLSConfig()
 | |
| 	tlsConfig.GetCertificate = ls.getCertificates
 | |
| 
 | |
| 	ln, err := net.Listen("tcp", listen)
 | |
| 	if err != nil {
 | |
| 		ls.log.WithField("listen", listen).WithError(err).Warning("Failed to listen")
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	proxyListener := &proxyproto.Listener{Listener: ln, ConnPolicy: utils.GetProxyConnectionPolicy()}
 | |
| 	defer func() {
 | |
| 		err := proxyListener.Close()
 | |
| 		if err != nil {
 | |
| 			ls.log.WithError(err).Warning("failed to close proxy listener")
 | |
| 		}
 | |
| 	}()
 | |
| 
 | |
| 	tln := tls.NewListener(proxyListener, tlsConfig)
 | |
| 
 | |
| 	ls.log.WithField("listen", listen).Info("Starting LDAP SSL server")
 | |
| 	err = ls.s.Serve(tln)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 	ls.log.WithField("listen", listen).Info("Stopping LDAP SSL Server")
 | |
| 	return nil
 | |
| }
 |