From e79dcaf910eae9e1c1fec1c3b71402ea7575eb52 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:17:53 -0800 Subject: [PATCH] fix ability to log into ssh with key and password (#130) * fix ability to log into ssh with key and password A previous refactor to the ssh password system broke the ability to use key+password to log in. This change handles key+password as a special case allowing it to be handled separately. * clean up unnecessary print My last change left in a debug print that wasn't necessary in the code. This has been removed. --- wavesrv/pkg/remote/remote.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wavesrv/pkg/remote/remote.go b/wavesrv/pkg/remote/remote.go index 09bf66ae..bcbf039a 100644 --- a/wavesrv/pkg/remote/remote.go +++ b/wavesrv/pkg/remote/remote.go @@ -932,6 +932,22 @@ func (msh *MShellProc) isWaitingForPassword_nolock() bool { return pwIdx != -1 } +func (msh *MShellProc) isWaitingForPassphrase_nolock() bool { + barr := msh.PtyBuffer.Bytes() + if len(barr) == 0 { + return false + } + nlIdx := bytes.LastIndex(barr, []byte{'\n'}) + var lastLine string + if nlIdx == -1 { + lastLine = string(barr) + } else { + lastLine = string(barr[nlIdx+1:]) + } + pwIdx := strings.Index(lastLine, "Enter passphrase for key") + return pwIdx != -1 +} + func (msh *MShellProc) RunPtyReadLoop(cmdPty *os.File) { buf := make([]byte, PtyReadBufSize) var isWaiting bool @@ -964,7 +980,11 @@ func (msh *MShellProc) WaitAndSendPassword(pw string) { var isWaiting bool var isConnecting bool msh.WithLock(func() { - isWaiting = msh.isWaitingForPassword_nolock() + if msh.Remote.SSHOpts.GetAuthType() == sstore.RemoteAuthTypeKeyPassword { + isWaiting = msh.isWaitingForPassphrase_nolock() + } else { + isWaiting = msh.isWaitingForPassword_nolock() + } isConnecting = msh.Status == StatusConnecting }) if !isConnecting {