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.

57 lines
2.1 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 'Vendor: %s' % deviceProperties['usb_device.vendor']
  37. print 'Product: %s' % deviceProperties['info.product']
  38. print 'Serial Number: %s' % deviceProperties['usb_device.serial']
  39. print
  40. print 'Volume\t\t\tUUID'
  41. showVolumes(storage)
  42. bus = dbus.SystemBus()
  43. halService = bus.get_object('org.freedesktop.Hal',
  44. '/org/freedesktop/Hal/Manager')
  45. halManager = dbus.Interface(halService, 'org.freedesktop.Hal.Manager')
  46. print 'Scanning USB devices...'
  47. for udi in halManager.FindDeviceStringMatch('info.bus', 'usb_device'):
  48. deviceObj = bus.get_object('org.freedesktop.Hal',
  49. udi)
  50. showProperties(udi)