Fixed a bug in ssh login with encrypted private key

Check the type of the returned error instead of the error message to
determine if the private key file is encrypted by a passphrase.
This commit is contained in:
Gilbert Chen
2020-04-17 15:55:30 -04:00
parent 4c3557eb80
commit 835af11334

View File

@@ -349,7 +349,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
} else {
keySigner, err = ssh.ParsePrivateKey(content)
if err != nil {
if strings.Contains(err.Error(), "cannot decode encrypted private keys") {
if _, ok := err.(*ssh.PassphraseMissingError); ok {
LOG_TRACE("SSH_PUBLICKEY", "The private key file is encrypted")
passphrase = GetPassword(preference, "ssh_passphrase", "Enter the passphrase to decrypt the private key file:", false, resetPassword)
if len(passphrase) == 0 {