Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Add support for LUKS header backup. #1302

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

xyakimo1
Copy link
Contributor

Add methods:

  • Encrypted.HeaderBackup
  • Block.RestoreEncryptedHeader

@StorageGhoul
Copy link

Can one of the admins verify this patch?

@vojtechtrefny
Copy link
Member

Jenkins, ok to test.

@vojtechtrefny vojtechtrefny self-requested a review July 23, 2024 08:25
self.udev_settle()

# check that backup normally works
BACKUP_FILE = "/var/tmp/udisks_encrypted_header_backup.luks"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use tempfile to create a temporary directory for this, it will take care of cleanup.

udisks_linux_block_object_lock_for_cleanup (UDISKS_LINUX_BLOCK_OBJECT (object));
udisks_state_check_block (state, udisks_linux_block_object_get_device_number (UDISKS_LINUX_BLOCK_OBJECT (object)));

/* Fail if the device is not a LUKS device */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail if the header is completely wiped or corrupted in a way that blkid won't recognize it as a LUKS device.

self.assertEqual(ret, 0)
ret, out = udiskstestcase.UdisksTestCase.run_command("cryptsetup luksDump %s" % disk)
self.assertEqual(1, ret)
self.assertTrue(("Device %s is not a valid LUKS device." % disk) in out)
Copy link
Member

@vojtechtrefny vojtechtrefny Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a race condition here -- dd removes the header, but the change is not yet propagated from udev to udisks so the restore works even with the check for LUKS metadata in the code. You need to wait for the IdType property to become empty after calling dd with somethig like

fstype = self.get_property(device, '.Block', 'IdType')
fstype.assertEqual('')

(this is not the unittest's assertEqual but our own with wait).


# check that after reaping device and restoring header, cryptsetup will recognize header
device.Lock(self.no_options, dbus_interface=self.iface_prefix + '.Encrypted')
ret, out = udiskstestcase.UdisksTestCase.run_command("cryptsetup luksDump %s" % disk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use cryptsetup here, we created the encrypted device so we know it is LUKS :-)

data/org.freedesktop.UDisks2.xml Outdated Show resolved Hide resolved
data/org.freedesktop.UDisks2.xml Outdated Show resolved Hide resolved
data/org.freedesktop.UDisks2.xml Outdated Show resolved Hide resolved
data/org.freedesktop.UDisks2.xml Outdated Show resolved Hide resolved
Add methods:
  - Encrypted.HeaderBackup
  - Block.RestoreEncryptedHeader
Copy link
Member

@tbzatek tbzatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@tbzatek tbzatek merged commit a238e6f into storaged-project:master Aug 5, 2024
18 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants