mirror of
https://github.com/FiloSottile/age.git
synced 2026-04-18 02:01:04 +00:00
cmd/age: automatically load default SSH key paths
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user