Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
Fixed linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Pasztor committed Mar 8, 2021
1 parent c8cb474 commit acc6c4c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
51 changes: 40 additions & 11 deletions server_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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"
Expand Down

0 comments on commit acc6c4c

Please sign in to comment.