diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2021-02-28 13:59:50 +0000 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2021-02-28 13:59:50 +0000 |
| commit | e8e4ba05251d0bc4fa1b1d82c73892c64c4f7b86 (patch) | |
| tree | ecda3bcd92d30a6c35023b5588166820f3a1b940 /zsh | |
| parent | 3cffabfc142fcf8b9a72bf2bd559fa3f2dee696a (diff) | |
zsh: Use fingerprints in op-ssh-add
Diffstat (limited to 'zsh')
| -rw-r--r-- | zsh/functions/op-ssh-add | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/zsh/functions/op-ssh-add b/zsh/functions/op-ssh-add index 012424f..ad55d6c 100644 --- a/zsh/functions/op-ssh-add +++ b/zsh/functions/op-ssh-add @@ -1,14 +1,26 @@ # -*- mode: sh -*- +# op-ssh-add will add SSH keys to the agent, but will fetch the +# passphrase in 1Password rather than prompt you for it. +# +# To be found, keys must have the following three things: +# +# 1. Have the password field set to the passphrase of the key, +# 2. Have an `SSH' tag set, and +# 3. Have a `fingerprint' field set to the fingerprint of the key. +# +# You must also have the 1Password CLI tool (op) and jq installed. + if [[ ${@[1]} =~ '-[DdKLlTXx]' ]]; then $(which -p ssh-add) $@ return $? fi -local prv pub +local fp prv pub for prv (${@[-1]} ~/.ssh/id_{ecdsa,ed25519}{,_sk}); do if [[ -f ${prv}.pub ]]; then pub=${prv}.pub + fp=$(cut -d' ' -f2 <<< $(ssh-keygen -f ${pub} -l)) break fi done @@ -24,10 +36,11 @@ if [[ -z ${session} ]]; then fi zmodload zsh/zpty zpty ssh $(which -p ssh-add) $@ -zpty -w ssh $(op get item \ - $(cut -d' ' -f3 ${pub}) \ - --fields password \ - --session ${session}) +zpty -w ssh $(op list items --session ${session} --tags SSH \ + | op get item \ + --fields fingerprint,password \ + --session ${session} - \ + | jq -jr "select(.fingerprint == \"${fp}\") | .password") zpty -r ssh zpty -d ssh op signout --session ${session} |
