Skip to content

Commit

Permalink
fix: ask for password
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed May 11, 2022
1 parent a1011a9 commit 3a279a4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/melt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ func backup(path string, pass []byte) (string, error) {
}

key, err := parsePrivateKey(bts, pass)
if err != nil {
if errors.Is(err, &ssh.PassphraseMissingError{}) {
pass, err := askKeyPassphrase(path)
if err != nil {
return "", err
}
return backup(path, pass)
if err != nil && isPasswordError(err) {
pass, err := askKeyPassphrase(path)
if err != nil {
return "", err
}
return backup(path, pass)
}
if err != nil {
return "", fmt.Errorf("could not parse key: %w", err)
}

Expand All @@ -248,6 +248,11 @@ func backup(path string, pass []byte) (string, error) {
}
}

func isPasswordError(err error) bool {
var kerr *ssh.PassphraseMissingError
return errors.As(err, &kerr)
}

func marshallPrivateKey(key ed25519.PrivateKey, pass []byte) (*pem.Block, error) {
if len(pass) == 0 {
// nolint: wrapcheck
Expand Down

0 comments on commit 3a279a4

Please sign in to comment.