Skip to content

Commit

Permalink
ssh: return ServerAuthError after too many auth failures
Browse files Browse the repository at this point in the history
if a client is disconnected due to too many authentication attempts
we should return a ServerAuthError instead of a generic error.

Some users check the error returned by NewServerConn to determine
whether or not a client attempted to authenticate.

Fixes golang/go#69191

Change-Id: If68fcecdefd6c810fe9df8256b1216e320d8a916
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/566398
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Nicola Murino <nicola.murino@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
  • Loading branch information
drakkan authored and gopherbot committed Sep 16, 2024
1 parent 9e92970 commit 42ee18b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions ssh/client_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,17 +641,28 @@ func TestClientAuthMaxAuthTries(t *testing.T) {
defer c1.Close()
defer c2.Close()

go newServer(c1, serverConfig)
_, _, _, err = NewClientConn(c2, "", clientConfig)
if tries > 2 {
if err == nil {
errCh := make(chan error, 1)

go func() {
_, err := newServer(c1, serverConfig)
errCh <- err
}()
_, _, _, cliErr := NewClientConn(c2, "", clientConfig)
srvErr := <-errCh

if tries > serverConfig.MaxAuthTries {
if cliErr == nil {
t.Fatalf("client: got no error, want %s", expectedErr)
} else if err.Error() != expectedErr.Error() {
} else if cliErr.Error() != expectedErr.Error() {
t.Fatalf("client: got %s, want %s", err, expectedErr)
}
var authErr *ServerAuthError
if !errors.As(srvErr, &authErr) {
t.Errorf("expected ServerAuthError, got: %v", srvErr)
}
} else {
if err != nil {
t.Fatalf("client: got %s, want no error", err)
if cliErr != nil {
t.Fatalf("client: got %s, want no error", cliErr)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ssh/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ userAuthLoop:
if err := s.transport.writePacket(Marshal(discMsg)); err != nil {
return nil, err
}

return nil, discMsg
authErrs = append(authErrs, discMsg)
return nil, &ServerAuthError{Errors: authErrs}
}

var userAuthReq userAuthRequestMsg
Expand Down

0 comments on commit 42ee18b

Please sign in to comment.