cmd/age: automatically load default SSH key paths

This commit is contained in:
Filippo Valsorda
2021-01-16 16:07:46 +01:00
parent 6da7d26b4d
commit 225044b061

View File

@@ -12,6 +12,7 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
_log "log"
"os"
"runtime/debug"
@@ -292,8 +293,26 @@ func decrypt(keys []string, in io.Reader, out io.Writer) {
&LazyScryptIdentity{passphrasePrompt},
}
// TODO: check the default SSH location if no arguments are provided
// (~/.ssh/id_rsa, ~/.ssh/id_ed25519).
// If they exist and are well-formed, load the default SSH keys. If they are
// passphrase protected, the passphrase will only be requested if the
// identity matches a recipient stanza.
for _, path := range []string{
os.ExpandEnv("$HOME/.ssh/id_rsa"),
os.ExpandEnv("$HOME/.ssh/id_ed25519"),
} {
content, err := ioutil.ReadFile(path)
if err != nil {
continue
}
ids, err := parseSSHIdentity(path, content)
if err != nil {
// If the key is explicitly requested, this error will be caught
// below, otherwise ignore it silently.
continue
}
identities = append(identities, ids...)
}
for _, name := range keys {
ids, err := parseIdentitiesFile(name)
if err != nil {