Compare commits

...

4 commits

Author SHA1 Message Date
Jakobus Schürz
bbf612262c add commented new feature 2023-03-07 18:14:28 +01:00
Jakobus Schürz
fcc0563af6 fix some output 2023-03-07 18:14:28 +01:00
Jakobus Schürz
cdfdc9e4e0 fix merging-mistake 2023-03-07 18:14:28 +01:00
Jakobus Schürz
f1c113c89a fix tmux issues 2023-03-07 18:14:28 +01:00
2 changed files with 40 additions and 18 deletions

View file

@ -98,7 +98,7 @@ while :; do
exit 0 exit 0
;; ;;
-*) -*)
echo "Unknown urgument: »$1«" echo "Unknown urgument: »$1«" >&2
exit 1 exit 1
;; ;;
*) *)
@ -173,7 +173,6 @@ agent_start_or_restart () {
#logdebug "ssh-agent for identity »$ssh_identity«: $agentfile" #logdebug "ssh-agent for identity »$ssh_identity«: $agentfile"
$createonly && logtrace "current loaded keys after action: $createonly && logtrace "current loaded keys after action:
$(ssh_runinagent $agentfile ssh-add -l)" $(ssh_runinagent $agentfile ssh-add -l)"
echo $agentfile
ret=0 ret=0
else else
logwarning "ssh-identity »$ssh_identity« is not configured. Please create $identitydir and add keys" logwarning "ssh-identity »$ssh_identity« is not configured. Please create $identitydir and add keys"
@ -191,7 +190,6 @@ $(ssh_runinagent $agentfile ssh-add -l)"
logdebug "ssh-agent for identity »$ssh_identity«: $agentfile" logdebug "ssh-agent for identity »$ssh_identity«: $agentfile"
# logdebug "currently loaded keys after action: # logdebug "currently loaded keys after action:
#$(ssh_runinagent $agentfile ssh-add -l)" #$(ssh_runinagent $agentfile ssh-add -l)"
echo $agentfile
ret=0 ret=0
else else
logwarning "no identity given -> exit" logwarning "no identity given -> exit"
@ -286,7 +284,6 @@ agent_load_identity_keys () {
for key in $(ls ${SSH_IDENTITIES_DIR}/${ssh_identity}/*|grep "\.so$"); do for key in $(ls ${SSH_IDENTITIES_DIR}/${ssh_identity}/*|grep "\.so$"); do
echo "key: $key"
logdebug "PKCS11_MODULE: ${PKCS11_MODULE:-not set} - key: $key" logdebug "PKCS11_MODULE: ${PKCS11_MODULE:-not set} - key: $key"
#[ -e "${P11M-x}" ] || [ "$(readlink - f $key)" == "$P11M" ] || key="$P11M" #[ -e "${P11M-x}" ] || [ "$(readlink - f $key)" == "$P11M" ] || key="$P11M"
#[ "$(readlink - f $key)" == "$P11M" ] || key="$P11M" #[ "$(readlink - f $key)" == "$P11M" ] || key="$P11M"
@ -295,7 +292,7 @@ agent_load_identity_keys () {
export P11M=$PKCS11_MODULE export P11M=$PKCS11_MODULE
logdebug "PKCS11_MODULE: ${PKCS11_MODULE:-not set} - key: $key" logdebug "PKCS11_MODULE: ${PKCS11_MODULE:-not set} - key: $key"
grep -q "PKCS11_MODULE" "${agentfile}" >/dev/null 2>&1 && sed -i -e '/PKCS11_MODULE/d' "${agentfile}" grep -q "PKCS11_MODULE" "${agentfile}" >/dev/null 2>&1 && sed -i -e '/PKCS11_MODULE/d' "${agentfile}"
echo "PKCS11_MODULE=$(readlink -f $key)" | tee -a "${agentfile}" echo "PKCS11_MODULE=$(readlink -f $key)" | tee -a "${agentfile}" >&2
tokenfingerprints=($(ssh-keygen -l -D $key|tr -s ' '|awk '{print $2}')) tokenfingerprints=($(ssh-keygen -l -D $key|tr -s ' '|awk '{print $2}'))
@ -315,7 +312,6 @@ agent_load_identity_keys () {
$remove && logdebug "remove token $key" $remove && logdebug "remove token $key"
logtrace "agentfile1 $agentfile \$SSH_ADD_OPTIONS $key " logtrace "agentfile1 $agentfile \$SSH_ADD_OPTIONS $key "
logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -e "${key}" 2>&1)" 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)" $remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s "${key}" 2>&1)"
fi fi
else else

View file

@ -22,6 +22,32 @@ promptcommandmunge () {
} }
function _pkcs11module_hook() { function _pkcs11module_hook() {
# if [ -S ~/.ssh/ssh_from_remote_auth_sock ]
# then
# if ss -elx|grep -q $(readlink -f ~/.ssh/ssh_from_remote_auth_sok) # test if socket is active
# then
# # Use PKCS11_MODULE from remote connection, even when using local machine
# # This is for: When i'm logged in from remote and working on local workstation, so i can use the token locally too
# #echo "read p11m" >&2
# if [ -e ~/.ssh/p11m ]
# then
# . ~/.ssh/p11m
# else
# rm ~/.ssh/p11m
# unset P11M
# unset PKCS11_MODULE
# fi
# fi
# else
# #echo "NOT read p11m, delete it!" >&2
# [ -e ~/.ssh/p11m ] && { rm ~/.ssh/p11m; \
# unset P11M; \
# unset PKCS11_MODULE; \
# }
#
# fi
if [ -z "${PKCS11_MODULE:+x}" ] if [ -z "${PKCS11_MODULE:+x}" ]
then then
# setze PKCS11_MODULE # setze PKCS11_MODULE
@ -57,11 +83,11 @@ function _pkcs11module_hook() {
fi fi
} }
## this function updates in combination with PROMPT_COMMAND the shell-environment-variables in tmux-sessions,
# every time prompt is called. It does it only, when called from tmux (Environment TMUX is set)
function _tmux_hook() { function _tmux_hook() {
# [ -z "${TMUX+x}" ] || eval "$(tmux show-environment -s)"
## this function updates in combination with PROMPT_COMMAND the shell-environment-variables in tmux-sessions,
# every time prompt is called. It does it only, when called from tmux (Environment TMUX is set)
# [ -z "${TMUX+x}" ] || eval "$(tmux show-environment -s)"
if [ -n "${TMUX}" ]; then if [ -n "${TMUX}" ]; then
eval "$(tmux show-environment -s)" eval "$(tmux show-environment -s)"
@ -69,16 +95,16 @@ function _tmux_hook() {
} }
# To make the code more reliable on detecting the default umask
function _umask_hook { function _umask_hook {
# Record the default umask value on the 1st run # To make the code more reliable on detecting the default umask
[[ -z $DEFAULT_UMASK ]] && export DEFAULT_UMASK="$(builtin umask)" # Record the default umask value on the 1st run
[[ -z $DEFAULT_UMASK ]] && export DEFAULT_UMASK="$(builtin umask)"
if [[ -n $UMASK ]]; then if [[ -n $UMASK ]]; then
umask "$UMASK" umask "$UMASK"
else else
umask "$DEFAULT_UMASK" umask "$DEFAULT_UMASK"
fi fi
} }
function cpb() { function cpb() {