From acc6c4c59ba38fdcd8b258fc9931ac2697308b11 Mon Sep 17 00:00:00 2001 From: Janos Pasztor Date: Mon, 8 Mar 2021 22:25:18 +0100 Subject: [PATCH] Fixed linting issues --- go.sum | 2 ++ server_impl.go | 51 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/go.sum b/go.sum index 4f1ac5f..7e54f93 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/containerssh/log v0.9.10/go.mod h1:NBMzkhOLZ4z45ShSBKQ/Ij6Hqqg15DgOKy6HlSITx0s= github.com/containerssh/log v0.9.11 h1:CLpl9mhxBg4giLZjcZB+FjddYypm2f2x1bCY3iissdA= github.com/containerssh/log v0.9.11/go.mod h1:uVuUPoZsJYi2KoV9+lgPeB/gWuXeUTD3AoVxc4y+tKY= +github.com/containerssh/log v0.9.13 h1:jBSrFaxZNGwkjHU6y/efYI8lyG8KIFR5aOIeOnNzquE= +github.com/containerssh/log v0.9.13/go.mod h1:uVuUPoZsJYi2KoV9+lgPeB/gWuXeUTD3AoVxc4y+tKY= github.com/containerssh/service v0.9.2 h1:+EZ7s7sxSme+IosYBR24oNhVlPTz3GJTXBZ0HaSD9rU= github.com/containerssh/service v0.9.2/go.mod h1:nbA2I+GL0vU7ls0JEQKI+QOJfbUjlIDmmUSQqx/G7ro= github.com/containerssh/structutils v0.9.0 h1:pz4xl5ZrPnpdSx7B/ru8Fj3oU3vOtx1jprIuSkm5s7o= diff --git a/server_impl.go b/server_impl.go index eddf901..9e1f9dd 100644 --- a/server_impl.go +++ b/server_impl.go @@ -296,11 +296,22 @@ func (s *server) createAuthenticators( func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error), func(conn ssh.ConnMetadata, challenge ssh.KeyboardInteractiveChallenge) (*ssh.Permissions, error), ) { - passwordHandler := s.createPasswordAuthenticator(handlerNetworkConnection, logger) - pubKeyHandler := s.createPubKeyAuthenticator(handlerNetworkConnection, logger) + passwordCallback := s.createPasswordCallback(handlerNetworkConnection, logger) + pubkeyCallback := s.createPubKeyCallback(handlerNetworkConnection, logger) + keyboardInteractiveCallback := s.createKeyboardInteractiveCallback(handlerNetworkConnection, logger) + return passwordCallback, pubkeyCallback, keyboardInteractiveCallback +} + +func (s *server) createKeyboardInteractiveCallback( + handlerNetworkConnection *networkConnectionWrapper, + logger log.Logger, +) func(conn ssh.ConnMetadata, challenge ssh.KeyboardInteractiveChallenge) (*ssh.Permissions, error) { keyboardInteractiveHandler := s.createKeyboardInteractiveHandler(handlerNetworkConnection, logger) - passwordCallback := func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) { - permissions, err := passwordHandler(conn, password) + keyboardInteractiveCallback := func( + conn ssh.ConnMetadata, + challenge ssh.KeyboardInteractiveChallenge, + ) (*ssh.Permissions, error) { + permissions, err := keyboardInteractiveHandler(conn, challenge) if err != nil { return permissions, err } @@ -319,6 +330,14 @@ func (s *server) createAuthenticators( handlerNetworkConnection.sshConnectionHandler = sshConnectionHandler return permissions, err } + return keyboardInteractiveCallback +} + +func (s *server) createPubKeyCallback( + handlerNetworkConnection *networkConnectionWrapper, + logger log.Logger, +) func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) { + pubKeyHandler := s.createPubKeyAuthenticator(handlerNetworkConnection, logger) pubkeyCallback := func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) { permissions, err := pubKeyHandler(conn, key) if err != nil { @@ -339,25 +358,35 @@ func (s *server) createAuthenticators( handlerNetworkConnection.sshConnectionHandler = sshConnectionHandler return permissions, err } - keyboardInteractiveCallback := func( - conn ssh.ConnMetadata, - challenge ssh.KeyboardInteractiveChallenge, - ) (*ssh.Permissions, error) { - permissions, err := keyboardInteractiveHandler(conn, challenge) + return pubkeyCallback +} + +func (s *server) createPasswordCallback( + handlerNetworkConnection *networkConnectionWrapper, + logger log.Logger, +) func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) { + passwordHandler := s.createPasswordAuthenticator(handlerNetworkConnection, logger) + passwordCallback := func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) { + permissions, err := passwordHandler(conn, password) if err != nil { return permissions, err } // HACK: check HACKS.md "OnHandshakeSuccess handler" sshConnectionHandler, err := handlerNetworkConnection.OnHandshakeSuccess(conn.User()) if err != nil { - err = log.WrapUser(err, EBackendRejected, "Authentication currently unavailable, please try again later.", "The backend has rejected the user after successful authentication.") + err = log.WrapUser( + err, + EBackendRejected, + "Authentication currently unavailable, please try again later.", + "The backend has rejected the user after successful authentication.", + ) s.logger.Error(err) return permissions, err } handlerNetworkConnection.sshConnectionHandler = sshConnectionHandler return permissions, err } - return passwordCallback, pubkeyCallback, keyboardInteractiveCallback + return passwordCallback } // HACK: check HACKS.md "OnHandshakeSuccess handler"