fix: fix auth ordering and identity files

The last few commits introduced a few bugs that are fixed here. The
first is that the auth ordering is parsed as a single string and not a
list. This is fixed by manually splitting the string into a list. The
second is that the copy of identity files was not long enough to copy
the contents of the original. This is now updated to use the length of
the original in its construction.
This commit is contained in:
Sylvia Crowe 2024-02-10 00:55:58 -08:00
parent 85156bd6c2
commit e62540bdbe

View File

@ -64,7 +64,7 @@ func createDummySigner() ([]ssh.Signer, error) {
// keys from being attempted. But if there's an error because of a dummy // keys from being attempted. But if there's an error because of a dummy
// file, the library can still try again with a new key. // file, the library can still try again with a new key.
func createPublicKeyCallback(sshKeywords *SshKeywords, passphrase string) func() ([]ssh.Signer, error) { func createPublicKeyCallback(sshKeywords *SshKeywords, passphrase string) func() ([]ssh.Signer, error) {
var identityFiles []string identityFiles := make([]string, len(sshKeywords.IdentityFile))
copy(identityFiles, sshKeywords.IdentityFile) copy(identityFiles, sshKeywords.IdentityFile)
identityFilesPtr := &identityFiles identityFilesPtr := &identityFiles
@ -479,9 +479,8 @@ func ConnectToClient(opts *sstore.SSHOpts) (*ssh.Client, error) {
keyboardInteractive := ssh.KeyboardInteractive(createCombinedKbdInteractiveChallenge(opts.SSHPassword)) keyboardInteractive := ssh.KeyboardInteractive(createCombinedKbdInteractiveChallenge(opts.SSHPassword))
passwordCallback := ssh.PasswordCallback(createCombinedPasswordCallbackPrompt(opts.SSHPassword)) passwordCallback := ssh.PasswordCallback(createCombinedPasswordCallbackPrompt(opts.SSHPassword))
// batch mode turns off interactive input // batch mode turns off interactive input. this means the number of
// this means the number of attemtps must // attemtps must drop to 1 with this setup
// drop to 1 with this setup
var attemptsAllowed int var attemptsAllowed int
if sshKeywords.BatchMode { if sshKeywords.BatchMode {
attemptsAllowed = 1 attemptsAllowed = 1
@ -636,8 +635,10 @@ func findSshConfigKeywords(hostPattern string) (*SshKeywords, error) {
} }
sshKeywords.KbdInteractiveAuthentication = (strings.ToLower(kbdInteractiveAuthenticationRaw) != "no") sshKeywords.KbdInteractiveAuthentication = (strings.ToLower(kbdInteractiveAuthenticationRaw) != "no")
// these are parsed as a single string and must be separated
// these are case sensitive in openssh so they are here too // these are case sensitive in openssh so they are here too
sshKeywords.PreferredAuthentications = ssh_config.GetAll(hostPattern, "PreferredAuthentications") preferredAuthenticationsRaw, err := ssh_config.GetStrict(hostPattern, "PreferredAuthentications")
sshKeywords.PreferredAuthentications = strings.Split(preferredAuthenticationsRaw, ",")
return sshKeywords, nil return sshKeywords, nil
} }