Skip to content

Commit

Permalink
Allow unlocking locked Stratis Pool devices
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Apr 18, 2024
1 parent 5183fbb commit ca10ce1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
37 changes: 36 additions & 1 deletion blivetgui/blivet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,18 @@ def create_disk_label(self, blivet_device, label_type):

return ProxyDataContainer(success=True, actions=actions, message=None, exception=None, traceback=None)

def luks_decrypt(self, blivet_device, passphrase):
def unlock_device(self, blivet_device, passphrase):
""" Unlock/open this LUKS/dm-crypt encrypted device
"""

if blivet_device.format.type == "luks":
return self._luks_unlock(blivet_device, passphrase)
elif blivet_device.format.type == "stratis":
return self._stratis_unlock(blivet_device, passphrase)
else:
return False

def _luks_unlock(self, blivet_device, passphrase):
""" Decrypt selected luks device
:param blivet_device: device to decrypt
Expand Down Expand Up @@ -1590,6 +1601,30 @@ def luks_decrypt(self, blivet_device, passphrase):
self.storage.devicetree.populate()
return True

def _stratis_unlock(self, blivet_device, passphrase):
""" Unlock Stratis pool on this device
:param blivet_device: stratis blockdev with a locked pool
:type blivet_device: StorageDevice
:param passphrase: passphrase
:type passphrase: str
"""

log_msg = "Opening Stratis device '%s':\n" % blivet_device
log_utils_call(log=self.log, message=log_msg,
user_input={"device": blivet_device})

blivet_device.format.passphrase = passphrase

try:
blivet_device.format.unlock_pool()
except blivet.errors.StratisError:
return False
else:
self.storage.devicetree.populate()
return True

def blivet_cancel_actions(self, actions):
""" Cancel scheduled actions
"""
Expand Down
2 changes: 1 addition & 1 deletion blivetgui/blivetgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def decrypt_device(self, _widget=None):
response = self.run_dialog(dialog)

if response:
ret = self.client.remote_call("luks_decrypt", self.list_partitions.selected_partition[0], response)
ret = self.client.remote_call("unlock_device", self.list_partitions.selected_partition[0], response)

if not ret:
msg = _("Unlocking failed. Are you sure provided password is correct?")
Expand Down
3 changes: 2 additions & 1 deletion blivetgui/list_partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def activate_action_buttons(self, selected_device):
if device.format:
if device.format.type == "luks" and not device.format.status and device.format.exists:
self.blivet_gui.activate_device_actions(["decrypt"])

elif device.format.type == "stratis" and device.format.locked_pool and not device.children:
self.blivet_gui.activate_device_actions(["decrypt"])
elif device.format.mountable and device.format.system_mountpoint:
self.blivet_gui.activate_device_actions(["unmount"])

Expand Down

0 comments on commit ca10ce1

Please sign in to comment.