summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Scala <github@arcenik.net>2019-01-14 16:38:45 +0100
committerMarc CornellĂ  <marc.cornella@live.com>2019-01-14 16:38:45 +0100
commit2a603856598eafc3c8a0bde80f8a885d2a81dfee (patch)
tree3e1683bad604da8f105fd5663cd4cf3dd5645143
parentfabee55948776e2e4c210e9dcd75e7bc38c02bec (diff)
downloadzsh-2a603856598eafc3c8a0bde80f8a885d2a81dfee.tar.gz
zsh-2a603856598eafc3c8a0bde80f8a885d2a81dfee.tar.bz2
zsh-2a603856598eafc3c8a0bde80f8a885d2a81dfee.zip
ssh-agent: use key signatures to check loaded ids (#7504)
Use fingerprint of ssh key instead of file name to control if the key is already loaded. Also check for .ssh folder presence (#5128)
-rw-r--r--plugins/ssh-agent/ssh-agent.plugin.zsh24
1 files changed, 18 insertions, 6 deletions
diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh
index a688855d0..2a860f3aa 100644
--- a/plugins/ssh-agent/ssh-agent.plugin.zsh
+++ b/plugins/ssh-agent/ssh-agent.plugin.zsh
@@ -12,16 +12,28 @@ function _start_agent() {
}
function _add_identities() {
- local id line
- local -a identities ids
+ local id line sig
+ local -a identities loaded signatures
zstyle -a :omz:plugins:ssh-agent identities identities
- # get list of loaded identities
- for line in ${(f)"$(ssh-add -l)"}; do ids+=${${(z)line}[3]}; done
+ # check for .ssh folder presence
+ if [[ ! -d $HOME/.ssh ]]; then
+ return
+ fi
+
+ # get list of loaded identities' signatures
+ for line in ${(f)"$(ssh-add -l)"}; do loaded+=${${(z)line}[2]}; done
+
+ # get signatures of private keys
+ for id in $identities; do
+ signatures+="$(ssh-keygen -lf "$HOME/.ssh/$id" | awk '{print $2}') $id"
+ done
# add identities if not already loaded
- for id in ${^identities}; do
- [[ ${ids[(I)$HOME/.ssh/$id]} -le 0 ]] && ssh-add $HOME/.ssh/$id
+ for sig in $signatures; do
+ id="$(cut -f2 <<< $sig)"
+ sig="$(cut -f1 <<< $sig)"
+ [[ ${loaded[(I)$sig]} -le 0 ]] && ssh-add $HOME/.ssh/$id
done
}