1*069ac184SEd Maste# $OpenBSD: agent-pkcs11.sh,v 1.13 2023/10/30 23:00:25 djm Exp $ 2ce3adf43SDag-Erling Smørgrav# Placed in the Public Domain. 3ce3adf43SDag-Erling Smørgrav 4ce3adf43SDag-Erling Smørgravtid="pkcs11 agent test" 5ce3adf43SDag-Erling Smørgrav 6*069ac184SEd Mastep11_setup || skip "No PKCS#11 library found" 719261079SEd Maste 8ce3adf43SDag-Erling Smørgravtrace "start agent" 919261079SEd Masteeval `${SSHAGENT} ${EXTRA_AGENT_ARGS} -s` > /dev/null 10ce3adf43SDag-Erling Smørgravr=$? 11ce3adf43SDag-Erling Smørgravif [ $r -ne 0 ]; then 12ce3adf43SDag-Erling Smørgrav fail "could not start ssh-agent: exit code $r" 13ce3adf43SDag-Erling Smørgravelse 14ce3adf43SDag-Erling Smørgrav trace "add pkcs11 key to agent" 15*069ac184SEd Maste p11_ssh_add -s ${TEST_SSH_PKCS11} > /dev/null 2>&1 16ce3adf43SDag-Erling Smørgrav r=$? 17ce3adf43SDag-Erling Smørgrav if [ $r -ne 0 ]; then 18ce3adf43SDag-Erling Smørgrav fail "ssh-add -s failed: exit code $r" 19ce3adf43SDag-Erling Smørgrav fi 20ce3adf43SDag-Erling Smørgrav 21ce3adf43SDag-Erling Smørgrav trace "pkcs11 list via agent" 22ce3adf43SDag-Erling Smørgrav ${SSHADD} -l > /dev/null 2>&1 23ce3adf43SDag-Erling Smørgrav r=$? 24ce3adf43SDag-Erling Smørgrav if [ $r -ne 0 ]; then 25ce3adf43SDag-Erling Smørgrav fail "ssh-add -l failed: exit code $r" 26ce3adf43SDag-Erling Smørgrav fi 27ce3adf43SDag-Erling Smørgrav 2819261079SEd Maste for k in $RSA $EC; do 2919261079SEd Maste trace "testing $k" 3019261079SEd Maste pub=$(cat $k.pub) 31*069ac184SEd Maste ${SSHADD} -L | grep -q "$pub" || \ 32*069ac184SEd Maste fail "key $k missing in ssh-add -L" 3319261079SEd Maste ${SSHADD} -T $k.pub || fail "ssh-add -T with $k failed" 3419261079SEd Maste 3519261079SEd Maste # add to authorized keys 3619261079SEd Maste cat $k.pub > $OBJ/authorized_keys_$USER 3719261079SEd Maste trace "pkcs11 connect via agent ($k)" 384f52dfbbSDag-Erling Smørgrav ${SSH} -F $OBJ/ssh_proxy somehost exit 5 39ce3adf43SDag-Erling Smørgrav r=$? 40ce3adf43SDag-Erling Smørgrav if [ $r -ne 5 ]; then 41ce3adf43SDag-Erling Smørgrav fail "ssh connect failed (exit code $r)" 42ce3adf43SDag-Erling Smørgrav fi 4319261079SEd Maste done 44ce3adf43SDag-Erling Smørgrav 45ce3adf43SDag-Erling Smørgrav trace "remove pkcs11 keys" 46*069ac184SEd Maste p11_ssh_add -e ${TEST_SSH_PKCS11} > /dev/null 2>&1 47ce3adf43SDag-Erling Smørgrav r=$? 48ce3adf43SDag-Erling Smørgrav if [ $r -ne 0 ]; then 49ce3adf43SDag-Erling Smørgrav fail "ssh-add -e failed: exit code $r" 50ce3adf43SDag-Erling Smørgrav fi 51ce3adf43SDag-Erling Smørgrav 52ce3adf43SDag-Erling Smørgrav trace "kill agent" 53ce3adf43SDag-Erling Smørgrav ${SSHAGENT} -k > /dev/null 54ce3adf43SDag-Erling Smørgravfi 55