From 5f822f2660b24cf600b79c17b393e0e643c887ea Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 13 Jan 2020 11:05:16 +0000 Subject: [PATCH] sftp: fix "failed to parse private key file: ssh: not an encrypted key" error This error started happening after updating golang/x/crypto which was done as a side effect of: 3801b8109 vendor: update termbox-go to fix ncdu command on FreeBSD This turned out to be a deliberate policy of making ssh.ParsePrivateKeyWithPassphrase fail if the passphrase was empty. See: https://go-review.googlesource.com/c/crypto/+/207599 This fix calls ssh.ParsePrivateKey if the passphrase is empty and ssh.ParsePrivateKeyWithPassphrase otherwise which fixes the problem. --- backend/sftp/sftp.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index c528ee4ff..9d0a1bcbd 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -439,7 +439,12 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) { return nil, err } } - signer, err := ssh.ParsePrivateKeyWithPassphrase(key, []byte(clearpass)) + var signer ssh.Signer + if clearpass == "" { + signer, err = ssh.ParsePrivateKey(key) + } else { + signer, err = ssh.ParsePrivateKeyWithPassphrase(key, []byte(clearpass)) + } if err != nil { return nil, errors.Wrap(err, "failed to parse private key file") }