From d3227931e2f473cebf819813ca61aef0e095ae68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Fri, 3 Dec 2021 09:01:50 +0100 Subject: [PATCH] write pubkeys to random tmpfile first solution was one tempfile for all connections there have been probably problems, when more connections have been startet at the same time. on write pubkeys, while the other tried to read the file. --- bin/startagent | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/startagent b/bin/startagent index 06d1914..91a8cbe 100755 --- a/bin/startagent +++ b/bin/startagent @@ -79,19 +79,21 @@ check_token(){ # defined here also, to work also in environments, where functions.sh couldn't be sourced [ -z "${P11M:+x}" ] && { P11M=$PKCS11_MODULE; export P11M; } - local tmppubkey="${XDG_RUNTIME_DIR}/token.pub" # If DISPLAY is set, ssh-add calls ssh-askpass, and if its in remote-terminal, it wont work # So remember and unset DISPLAY, and set it at the end again, if it was set before [ $DISPLAY ] && local DISPLAY_ORIG=$DISPLAY - [ $DISPLAY ] && logdebug "unset DISPLAY: $DISPLAY" + [ $DISPLAY ] && logtrace "unset DISPLAY: $DISPLAY" [ $DISPLAY ] && unset DISPLAY # Write public keys of all in agent stored keys to a temporary file + local tmppubkey="$(mktemp -p ${XDG_RUNTIME_DIR} pubkey.XXXXXX.pub)" + logtrace "tmppubkey: $tmppubkey" loginfo "$(ssh-add -L > $tmppubkey)" # Check if public-keys in tmppubkey are working. They are not working, if you removed and add back hardware-token. - loginfo "$(ssh-add -T ${tmppubkey} || { ssh-add -e $P11M; set -x; ssh-add -s $P11M; } )" - loginfo "$(ssh-add -l)" - [ $DISPLAY_ORIG ] && logdebug "reset DISPLAY=$DISPLAY_ORIG" + loginfo "$(ssh-add -T ${tmppubkey}|| { ssh-add -e $P11M; ssh-add -s $P11M; } )" + logdebug "$(rm "${tmppubkey}")" + loginfo "$(ssh-add -l )" + [ $DISPLAY_ORIG ] && logtrace "reset DISPLAY=$DISPLAY_ORIG" [ $DISPLAY_ORIG ] && export DISPLAY=$DISPLAY_ORIG }