Setup

Linux

Requirements:

  • UDEV (should be available in every modern Linux distribution)
  • possibility to install UDEV rule + bash script with root-permissions
  • Installed netcat (installed by default by many Linux distributions)

To make the USK Keylock work, follow these steps (works with Debian, Ubuntu and Gentoo, should work with others also or at least similar):

  1. open a shell
  2. cd /etc/udev
  3. svn export http://svn.root1.de/svn/usbkeylock/trunk/src/main/linux/etc/udev/ . --force <-- this requires root-permission. Either login as root, or use "sudo"

The last commands downloads the script + UDEV rule to your linux installation. If you don't have /etc/udev, please adapt accordingly...
Everytime you plugin a USB device (USB-Stick, USB Mouse, USB keyboard, ...), the downloaded script (/etc/udev/scripts/usbkeylock.sh) will be executed. If your Java application is running (see Demo Application below), the UsbKeyLockListener get's notified about each attached and detached USB devices.

Detection Time

If you use a USB memory stick, you should remove all partitions or disable auto-mount to speed up the detection. Otherwise automount might slow down the process.
Without auto-mount (I removed the partition), I'm able to detect the stick in <=1sec. So for locking/unlocking the application with a USB stick, it's fast enough...

Windows

There is currently no windows solution available. If you're an experienced Windows Developer and able create an agent which listens for atached/detached USB devices and can extract

  • VENDOR_ID
  • MODEL_ID
  • VENDOR
  • MODEL
  • SERIAL

please drop me a mail --> alex[at]root1.de

Java

Latest binary can be downloaded here:

http://jenkins.root1.de/job/UsbKeyLock%20-%20trunk/lastStableBuild/de.root1$usbkeylock/

Demo Application

package de.root1.usbkeylock;

import java.util.Date;
import java.util.List;

/**
 * Hello world!
 *
 */
public class DemoApp {

    public static void main(String[] args) {

        UsbKeyLock ukl = new UsbKeyLock();

        ukl.addListener(new UsbKeyLockListener() {

            @Override
            public void attached(Date timestamp, UsbDevice device) {
                System.out.println("Attached : " + timestamp + " --> " + device);
            }

            @Override
            public void detached(Date timestamp, UsbDevice device) {
                System.out.println("Detached: " + timestamp + " --> " + device);
            }
        });

        ukl.startDetection();
        List<UsbDevice> attachedDevices = ukl.getAttachedDevices();

        System.out.println("Currently, the following devices are attached to the USB system: ");
        for (UsbDevice usbDevice : attachedDevices) {
            System.out.println("-> "+usbDevice);
        }

    }
}

Output will look like this:

Currently, the following devices are attached to the USB system: 
-> UsbDevice{vendorId=0718, productId=063e, manufacturer=Imation, product=Nano_Pro, serial=07B60D0xxxxxxxxx}
-> UsbDevice{vendorId=0bb4, productId=0ca2, manufacturer=HTC, product=Android_Phone, serial=xxxxxxxxxxxx}
Detached: Wed Apr 18 16:17:17 CEST 2012 --> UsbDevice{vendorId=0718, productId=063e, manufacturer=Imation, product=Nano_Pro, serial=07B60D0xxxxxxxxx}
Attached : Wed Apr 18 16:17:15 CEST 2012 --> UsbDevice{vendorId=0718, productId=063e, manufacturer=Imation, product=Nano_Pro, serial=07B60D0xxxxxxxxx}

License

This project is licensed under GPL v3. So it's free /open source software. And it's also free of charge. But please don't violate the GPL ...

If you find this library useful, please let me know --> alex[at]root1.de