Skip to content

Commit b946a46

Browse files
hrakalexellis
authored andcommitted
Fix check for encrypted private keys using PassphraseMissingError
Signed-off-by: Hans Rakers <[email protected]>
1 parent 02cd632 commit b946a46

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

cmd/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func loadPublickey(path string) (ssh.AuthMethod, func() error, error) {
314314

315315
signer, err := ssh.ParsePrivateKey(key)
316316
if err != nil {
317-
if err.Error() != "ssh: cannot decode encrypted private keys" {
317+
if _, ok := err.(*ssh.PassphraseMissingError); !ok {
318318
return nil, noopCloseFunc, fmt.Errorf("unable to parse private key: %s", err.Error())
319319
}
320320

cmd/install_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package cmd
22

33
import (
4+
"errors"
45
"io/ioutil"
56
"os"
67
"regexp"
78
"strings"
89
"testing"
910

1011
"github.com/alexellis/k3sup/pkg/helm"
12+
"golang.org/x/crypto/ssh"
1113
)
1214

1315
// To regenerate:
@@ -45,7 +47,7 @@ kfFJfrUjElq6Bx9oPPxc2vD40gqnYL57A+Y+X+A0kL4fO7pfh2VxOw==
4547
`
4648

4749
func Test_loadPublickeyEncrypted(t *testing.T) {
48-
want := "parse private key with passphrase failed: x509: decryption password incorrect"
50+
want := &ssh.PassphraseMissingError{}
4951

5052
tmpfile, err := ioutil.TempFile("", "key")
5153
if err != nil {
@@ -60,7 +62,7 @@ func Test_loadPublickeyEncrypted(t *testing.T) {
6062

6163
tmpfile.Close()
6264
_, _, err = loadPublickey(fileName)
63-
if err.Error() != want {
65+
if errors.Is(err, want) {
6466
t.Fatalf("want: %q, but got: %q", want, err.Error())
6567
}
6668
}

0 commit comments

Comments
 (0)