From 3de3e333331a2676b8977d27465233c136944b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 21 Oct 2022 17:09:07 +0200 Subject: [PATCH] print error, when more than one token is plugged in --- bin/startagent | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/bin/startagent b/bin/startagent index 2cd0a47..1e451dc 100755 --- a/bin/startagent +++ b/bin/startagent @@ -250,7 +250,7 @@ agent_load_identity_keys () { fingerprints=( $(ssh_runinagent $agentfile "ssh-add -l|awk '{print \$2}'") ) logdebug "fingerprints from loaded keys before action:" - for f in ${fingerprints[*]};do + for f in ${fingerprints[@]};do logdebug "$f" done if ! $tokenonly ; then @@ -303,25 +303,33 @@ agent_load_identity_keys () { #[ "$(readlink - f $key)" == "$P11M" ] || key="$P11M" [ "$(readlink -f $key)" != "$P11M" -a "${P11M:-x}" != "x" ] && key="$P11M" logdebug "P11M2: ${P11M:-not set} - key: $key" - echo "P11M: ${P11M:-not set} - key: $key" + logdebug "P11M: ${P11M:-not set} - key: $key" - tokenfingerprint="$(ssh-keygen -l -D $key|tr -s ' '|awk '{print $2}')" + tokenfingerprints=($(ssh-keygen -l -D $key|tr -s ' '|awk '{print $2}')) - if [[ ${fingerprints[*]} =~ "$tokenfingerprint" ]]; then - logdebug "token: $key ($tokenfingerprint) is loaded" - check_pubkeysonly - if $readd || $remove ; then - $readd && logdebug "re-add token $key" - $remove && logdebug "remove token $key" - echo agentfile1 $agentfile \$SSH_ADD_OPTIONS $key >&2 - logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -e "${key}" 2>&1)" - ssh_runinagent $agentfile echo $SSH_AUTH_SOCK >&2 - $remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s "${key}" 2>&1)" - fi + logtrace "fingerprints: ${fingerprints[*]}" + logtrace "tokenfingerprints count: ${#tokenfingerprints[@]}" + if [ ${#tokenfingerprints[@]} -gt 1 ]; then + logerr "Found ${#tokenfingerprints[@]} in p11-kit-proxy! Check if only one token is plugged into your computer" else - logdebug "token: $key is not loaded -> load it" - logdebug "$(ssh_runinagent $agentfile ssh-add -v ${SSH_ADD_OPTIONS} -e ${key} 2>&1)" - $remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s ${key} 2>&1)" + tokenfingerprint=${tokenfingerprints[0]} + logtrace "tokenfingerprint: ${tokenfingerprint}" + if [[ "${fingerprints[@]}" =~ "$tokenfingerprint" ]]; then + logdebug "token: $key ($tokenfingerprint) is loaded" + check_pubkeysonly + if $readd || $remove ; then + $readd && logdebug "re-add token $key" + $remove && logdebug "remove token $key" + echo agentfile1 $agentfile \$SSH_ADD_OPTIONS $key >&2 + logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -e "${key}" 2>&1)" + ssh_runinagent $agentfile echo $SSH_AUTH_SOCK >&2 + $remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s "${key}" 2>&1)" + fi + else + logdebug "token: $key is not loaded -> load it" + logdebug "$(ssh_runinagent $agentfile ssh-add -v ${SSH_ADD_OPTIONS} -e ${key} 2>&1)" + $remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s ${key} 2>&1)" + fi fi done fi