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.
This commit is contained in:
Sylvie Crowe 2023-12-12 14:17:53 -08:00 committed by GitHub
parent e6186cd694
commit e79dcaf910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {