Hardware authentication for Linux using ordinary USB Flash Drives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

  1. #!/usr/bin/env python2.4
  2. import dbus
  3. bus = dbus.SystemBus()
  4. halService = bus.get_object('org.freedesktop.Hal',
  5. '/org/freedesktop/Hal/Manager')
  6. halManager = dbus.Interface(halService, 'org.freedesktop.Hal.Manager')
  7. def getStorageDevice(udi):
  8. for child in halManager.FindDeviceByCapability('storage'):
  9. deviceObj = bus.get_object('org.freedesktop.Hal',
  10. child)
  11. deviceProperties = deviceObj.GetAllProperties(
  12. dbus_interface = 'org.freedesktop.Hal.Device')
  13. if deviceProperties['storage.physical_device'] == udi + '_if0':
  14. return child
  15. return None
  16. def showVolumes(udi):
  17. for volume in halManager.FindDeviceByCapability('volume'):
  18. deviceObj = bus.get_object('org.freedesktop.Hal',
  19. volume)
  20. deviceProperties = deviceObj.GetAllProperties(
  21. dbus_interface = 'org.freedesktop.Hal.Device')
  22. if deviceProperties['block.storage_device'] != udi:
  23. continue
  24. print '%s\t\t%s' % (deviceProperties['block.device'],
  25. deviceProperties['volume.uuid'])
  26. def showProperties(udi):
  27. storage = getStorageDevice(udi)
  28. if storage is None:
  29. return
  30. print
  31. deviceObj = bus.get_object('org.freedesktop.Hal',
  32. udi)
  33. deviceProperties = deviceObj.GetAllProperties(
  34. dbus_interface = 'org.freedesktop.Hal.Device')
  35. print 'Device %s' % udi
  36. print 'Serial Number: %s' % deviceProperties['usb_device.serial']
  37. print
  38. print 'Volume\t\t\tUUID'
  39. showVolumes(storage)
  40. bus = dbus.SystemBus()
  41. halService = bus.get_object('org.freedesktop.Hal',
  42. '/org/freedesktop/Hal/Manager')
  43. halManager = dbus.Interface(halService, 'org.freedesktop.Hal.Manager')
  44. print 'Scanning USB devices...'
  45. for udi in halManager.FindDeviceStringMatch('info.bus', 'usb_device'):
  46. deviceObj = bus.get_object('org.freedesktop.Hal',
  47. udi)
  48. showProperties(udi)