Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Detect different kinds of storage devices attached to sd-export-usb #16

Merged
merged 8 commits into from
Nov 7, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
workaround for bus id issue
  • Loading branch information
Allie Crevier committed Nov 4, 2019
commit 3f9659098e99e2701f05a6be43a88c1a90453a14
23 changes: 3 additions & 20 deletions securedrop_export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,14 @@ def extract_tarball(self):
self.exit_gracefully(msg)

def check_usb_connected(self):

# If the USB is not attached via qvm-usb attach, lsusb will return empty string and a
# return code of 1
logging.info('Performing usb preflight')
try:
p = subprocess.check_output(["lsusb", "-s", "{}:".format(self.pci_bus_id)])
logging.info("lsusb -s {} : {}".format(self.pci_bus_id, p.decode("utf-8")))
subprocess.check_output(["lsblk", "-p", "-o", "KNAME", DEVICE])
self.exit_gracefully("USB_CONNECTED")
except subprocess.CalledProcessError:
msg = "ERROR_USB_CONFIGURATION"
self.exit_gracefully(msg)
n_usb = len(p.decode("utf-8").rstrip().split("\n"))
# If there is one device, it is the root hub.
if n_usb == 1:
logging.info('usb preflight - no external devices connected')
msg = "USB_NOT_CONNECTED"
self.exit_gracefully(msg)
# If there are two devices, it's the root hub and another device (presumably for export)
elif n_usb == 2:
logging.info('usb preflight - external device connected')
msg = "USB_CONNECTED"
self.exit_gracefully(msg)
# Else the result is unexpected
else:
msg = "ERROR_USB_CHECK"
self.exit_gracefully(msg)
self.exit_gracefully("USB_NOT_CONNECTED")

def check_luks_volume(self):
logging.info('Checking if volume is luks-encrypted')
Expand Down