YubiKey lock screen: Difference between revisions

From D3xt3r01.tk
Jump to navigationJump to search
Line 13: Line 13:
Create a /etc/udev/rules.d/85-screen-lock-toggle.rules
Create a /etc/udev/rules.d/85-screen-lock-toggle.rules
<source lang="bash">
<source lang="bash">
KERNEL=="hidraw?" ACTION=="remove", ATTRS{serial}=="0001484196", ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0010", RUN+="/usr/local/bin/gnome-lock-disable"
SUBSYSTEM=="usb", ACTION=="remove", ENV{ID_VENDOR_ID}=="1050", ENV{ID_MODEL_ID}=="0010", ENV{ID_SERIAL_SHORT}=="0001484196", RUN+="/usr/local/bin/gnome-lock enable"
KERNEL=="hidraw?" ACTION=="add", ATTRS{serial}=="0001484196", ATTRS{idVendor}=="1050", ATTRS{idProduct}=="0010", RUN+="/usr/local/bin/gnome-lock-enable"
</source>
</source>


Line 25: Line 24:


<source lang="bash">
<source lang="bash">
~# cat /usr/local/bin/gnome-lock-enable
~# cat /usr/local/bin/gnome-lock
#!/bin/bash
#!/bin/bash
echo "$(date) $0" >> /tmp/yubi_lock_log
log="/tmp/yubi_lock_log"
user=`ps aux | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
echo "$(date) $(whoami) '$0' '$1'" >> ${log}
if [ -n $user ]; then
 
GNOME_SCREENSAVER_PROC=`ps xa | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
export `grep -z DBUS_SESSION_BUS_ADDRESS /proc/$GNOME_SCREENSAVER_PROC/environ`
su $user -c "gconftool-2 --set "/apps/gnome-screensaver/lock_enabled" --type bool 1"
fi
~# cat /usr/local/bin/gnome-lock-disable
#!/bin/bash
echo "$(date) $0" >> /tmp/yubi_lock_log
user=`ps aux | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
user=`ps aux | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
if [ -n $user ]; then
export DISPLAY=":0"
GNOME_SCREENSAVER_PROC=`ps xa | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
if [ -n $user -a "$1" == "enable" ]
export `grep -z DBUS_SESSION_BUS_ADDRESS /proc/$GNOME_SCREENSAVER_PROC/environ`
then
su $user -c "gconftool-2 --set "/apps/gnome-screensaver/lock_enabled" --type bool 0"
        sudo -u ${user} /usr/bin/gnome-screensaver-command -l >> ${log} 2>&1
fi
fi
</source>
</source>

Revision as of 21:23, 23 October 2012

What

I'm trying to make my fedora desktop lock the screen and unlock when it sees my key in.

HOW

Get the serial, idVendor, idProduct of the thing.

udevadm info -a -p $(udevadm info -q path -n /dev/hidraw0)

Create a /etc/udev/rules.d/85-screen-lock-toggle.rules

SUBSYSTEM=="usb", ACTION=="remove", ENV{ID_VENDOR_ID}=="1050", ENV{ID_MODEL_ID}=="0010", ENV{ID_SERIAL_SHORT}=="0001484196", RUN+="/usr/local/bin/gnome-lock enable"

Also you should probably reload the rules:

udevadm control --reload-rules

And you should create the 2 scripts:

~# cat /usr/local/bin/gnome-lock
#!/bin/bash
log="/tmp/yubi_lock_log"
echo "$(date) $(whoami) '$0' '$1'" >> ${log}

user=`ps aux | grep gnome-screensaver | head -n 1 | awk '{print $1}'`
export DISPLAY=":0"
if [ -n $user -a "$1" == "enable" ]
then
        sudo -u ${user} /usr/bin/gnome-screensaver-command -l >> ${log} 2>&1
fi