Skip to content

Commit 4df2f67

Browse files
committed
ssh: fail keyboard-interactive auth with unexpectedMessageError() when auth fails before receiving the UserAuthInfoRequest from server
1 parent d4e7c9c commit 4df2f67

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ssh/client_auth.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ func (cb KeyboardInteractiveChallenge) auth(session []byte, user string, c packe
555555
}
556556

557557
gotMsgExtInfo := false
558+
gotUserAuthInfoRequest := false
558559
for {
559560
packet, err := c.readPacket()
560561
if err != nil {
@@ -585,6 +586,9 @@ func (cb KeyboardInteractiveChallenge) auth(session []byte, user string, c packe
585586
if msg.PartialSuccess {
586587
return authPartialSuccess, msg.Methods, nil
587588
}
589+
if !gotUserAuthInfoRequest {
590+
return authFailure, msg.Methods, unexpectedMessageError(msgUserAuthInfoRequest, packet[0])
591+
}
588592
return authFailure, msg.Methods, nil
589593
case msgUserAuthSuccess:
590594
return authSuccess, nil, nil
@@ -596,6 +600,7 @@ func (cb KeyboardInteractiveChallenge) auth(session []byte, user string, c packe
596600
if err := Unmarshal(packet, &msg); err != nil {
597601
return authFailure, nil, err
598602
}
603+
gotUserAuthInfoRequest = true
599604

600605
// Manually unpack the prompt/echo pairs.
601606
rest := msg.Prompts

0 commit comments

Comments
 (0)