/~martin/ blog/ misc/ egate usbmgr

Getting an egate crypto token to work with usbmgr

Since both udev and hotplug suck (the former more than the later) I decided to go with usbmgr.

It doesn't yet know of the device so you have to tell it:

sudo cat << EOF >> /etc/usbmgr/usbmgr.conf
# egate
vendor 0x0973 product 0x01 module none
EOF

We tell usbmgr to run the script openct[1] when it detects the device:

sudo mkdir -p /etc/usbmgr/vendor/0973/0001
sudo echo openct > /etc/usbmgr/vendor/0973/0001/script

[1] the openct script to initialize the token and lock xscreensaver for all users when unplugged:

#!/bin/sh

#test "$ACTION" = "add" || exit 0

if [ $ACTION = "add" ]; then
        if [ -e /var/run/openct/status ]
        then
                # race condition in the kernel, $DEVICE might not exist now
                sleep 1
                # let's hope 1 second is good enough
                /usr/sbin/openct-control init
                /usr/sbin/openct-control attach $DEVICE usb:$PRODUCT
        fi
fi

if [ $ACTION = "remove" ]; then
        # lock screen and remove ssh-agent keys
        user=`who | grep " :0" | awk '{print $1}'`
        export XAUTHORITY=/home/$user/.Xauthority
        export DISPLAY=:0
        su $user -c "xscreensaver-command -lock"
        su $user -c "/usr/bin/ssh-add -D"
        # turn the display off
        xset dpms force off
fi