From 5f7b3540329628c8e3935216076df99f6a9501f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Mon, 6 Jul 2020 11:40:19 +0200 Subject: [PATCH] add scripts for bmi-usage, and etoken --- bin/ssh-init-pkcs11 | 23 +++++++++++++++++++++++ bin/startbmi | 6 ++++++ bin/token | 29 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100755 bin/ssh-init-pkcs11 create mode 100755 bin/startbmi create mode 100755 bin/token diff --git a/bin/ssh-init-pkcs11 b/bin/ssh-init-pkcs11 new file mode 100755 index 0000000..35f36a3 --- /dev/null +++ b/bin/ssh-init-pkcs11 @@ -0,0 +1,23 @@ +#!/bin/sh + +set -eu +set -x +[ -z "${PKCS11_MODULE+x}" ] && PKCS11_MODULE="$(dnf repoquery --installed -l p11-kit | grep \/p11-kit-proxy.so\$ | head -1)" + +echo SSH_AGENT_PID before: $SSH_AGENT_PID + +[ -z "$(pidof ssh-agent)" -o "${SSH_AGENT_PID}" != "$(pidof ssh-agent)" ] && eval "$(ssh-agent -s)" + + +echo SSH_AGENT_PID after: $SSH_AGENT_PID + +#if ssh-add -l | grep -q "${PKCS11_MODULE}"; then +# # Remove any stale loaded keys from token, ssh-agent does not automatically +# # reconnect with the token when you reinsert it. +# ssh-add -e "${PKCS11_MODULE}" +#fi + +ssh-add -e "${PKCS11_MODULE}" 2>/dev/null +echo $? +# Tell ssh-agent to use the keys on the token +ssh-add -s "${PKCS11_MODULE}" diff --git a/bin/startbmi b/bin/startbmi new file mode 100755 index 0000000..e0bbdf1 --- /dev/null +++ b/bin/startbmi @@ -0,0 +1,6 @@ +#!/bin/bash + +ssh -fN bmi-pfwd + +x2goclient --hide --close-disconnect --session "BMI Thunderbird" & + diff --git a/bin/token b/bin/token new file mode 100755 index 0000000..12b03d8 --- /dev/null +++ b/bin/token @@ -0,0 +1,29 @@ +#!/bin/sh +#set -eu +#set -x + +[ -z "${PKCS11_MODULE+x}" ] && { PKCS11_MODULE=/usr/lib64/p11-kit-proxy.so; export PKCS11_MODULE; } + + +ssh-add -l &>/dev/null +if [ "$?" == 2 ]; then + test -r ~/.ssh-agent && \ + eval "$(<~/.ssh-agent)" >/dev/null + + ssh-add -l &>/dev/null + if [ "$?" == 2 ]; then + (umask 066; ssh-agent > ~/.ssh-agent) + eval "$(<~/.ssh-agent)" >/dev/null + + fi +fi + +ssh-add -l &>/dev/null +if [ "$?" == 0 ]; then + # Remove and add again $PKCS11_MODULE + ssh-add -e $PKCS11_MODULE + ssh-add -s $PKCS11_MODULE +else + echo "not able to create ssh-agent" +fi +