gparted/include
Mike Fleetwood 099b85fe18 Capture LUKS mapping master encryption key location (#59)
ISSUE OVERVIEW

When GParted tries to resize an open LUKS encryption mapping and the
volume (master) key was stored in the kernel keyring service [1] it
fails like this:

    Check and repair file system ([Encrypted] ext4) on /dev/...(ERROR)
    + calibrate /dev/sdd1                                      (SUCCESS)
    + check file system on /dev/mapper/sdd1_crypt for errors...(SUCCESS)
    + grow encryption volume to fill the partition             (ERROR)
      + cryptsetup -v resize 'sdd1_crypt'                      (ERROR)
          Command failed with code -1 (wrong or missing parameters).
          Nothing to read on input.

This error occurs with cryptsetup >= 2.0, kernel >= 4.10 and LUKS2
format because the crypt Device-Mapper target no longer has the volume
key so cryptsetup resize prompts for a passphrase, but GParted doesn't
provide it.

THIS COMMIT

Additionally capture the location of the volume (master) key location
for active encryption mappings.  Do this the using the same method that
cryptsetup uses [2][3].  Namely if the first character of the KEY is a
":" then the key *was* stored in the kernel keyring service, otherwise
it *is* store in the Device-Mapper crypt target as previously.

    # echo -n badpassword | cryptsetup luksFormat --type luks1 /dev/sdb1 -
    # echo -n badpassword | cryptsetup luksOpen /dev/sdb1 sdb1_crypt
    # cryptsetup status sdb1_crypt | egrep 'type|key location'
      type:         LUKS1
      key location: dm-crypt

    # echo -n badpassword | cryptsetup luksFormat --type luks2 /dev/sdb2 -
    # echo -n badpassword | cryptsetup luksOpen /dev/sdb2 sdb2_crypt
    # cryptsetup status sdb2_crypt | egrep 'type|key location'
      type:         LUKS2
      key location: keyring

    # dmsetup table --target crypt
    sdb1_crypt: 0 520192 crypt aes-xts-plain64 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0 8:17 4096
    sdb2_crypt: 0 491520 crypt aes-xts-plain64 :64:logon:cryptsetup:3d040240-97ba-4559-af98-72c3be500498-d0 0 8:18 32768
                                               ^
First character of the KEY field --------------'

[1] Integration with the kernel keyring service
    https://gitlab.com/cryptsetup/cryptsetup/blob/v2.0.0/docs/Keyring.txt
    "
    Starting with cryptsetup 2.0 we load [Volume Key] VK in kernel
    keyring by default for LUKSv2 devices ...

    In summary, the key description visible in dm-crypt table line is a
    reference to VK that usually no longer exists in kernel keyring
    service if you used cryptsetup to for device activation.
    "

[2] cryptsetup/v2.3.5/lib/libdevmapper.c:_dm_target_query_crypt()
    https://gitlab.com/cryptsetup/cryptsetup/-/blob/v2.3.5/lib/libdevmapper.c#L2031
        if (key_[0] == ':')
            *act_flags |= CRYPT_ACTIVATE_KEYRING_KEY;

[3] cryptsetup/v2.3.5/src/cryptsetup.c:action_status()
    https://gitlab.com/cryptsetup/cryptsetup/-/blob/v2.3.5/src/cryptsetup.c#L839
        log_std("  key location: %s\n", (cad.flags & CRYPT_ACTIVATE_KEYRING_KEY) ? "keyring" : "dm-crypt");

Closes #59 - Resize of LUKS2 encrypted file system fails with "Nothing
             to read on input"
2021-04-25 15:49:35 +00:00
..
BlockSpecial.h Pre-populate BlockSpecial cache while reading /proc/partitions (#767842) 2016-08-06 09:47:58 -06:00
CopyBlocks.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
DMRaid.h Make 4 internally used only DMRaid methods private 2019-12-02 16:35:22 +00:00
Device.h Add missing includes into Devices module 2020-05-27 16:02:47 +00:00
DialogFeatures.h Rename DialogFeatures::treeview_filesystems_Columns member to fsname (!52) 2019-12-04 07:38:01 +00:00
DialogManageFlags.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
DialogPasswordEntry.h Clear previous LUKS unlock failure error before next attempt (#795617) 2018-06-19 10:54:48 -06:00
Dialog_Base_Partition.h Snap partition boundaries before dialogs update FS usage (#48) 2019-06-11 15:55:02 +00:00
Dialog_Disklabel.h Ensure icon sizes (#39) 2019-04-06 11:42:28 +01:00
Dialog_FileSystem_Label.h Simplify from Gtk::Table to HBox in FileSystem Label dialog 2018-06-18 10:15:33 -06:00
Dialog_Partition_Copy.h Pass the current device down to Dialog_Base_Partition class (#48) 2019-06-11 15:55:02 +00:00
Dialog_Partition_Info.h Use Gtk::Grid for Dialog_Partition_Info (!25) 2019-04-27 12:03:05 +01:00
Dialog_Partition_Name.h Simplify from Gtk::Table to HBox in Partition Name dialog 2018-06-18 10:15:33 -06:00
Dialog_Partition_New.h Rename member variable to default_fs 2021-03-04 16:55:06 +00:00
Dialog_Partition_Resize_Move.h Pass the current device down to Dialog_Base_Partition class (#48) 2019-06-11 15:55:02 +00:00
Dialog_Progress.h Rename Dialog_Progress member variable to m_curr_op 2019-04-11 10:06:36 -06:00
Dialog_Rescue_Data.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
DrawingAreaVisualDisk.h Use Gdk::RGBA (!25) 2019-04-27 12:03:04 +01:00
FS_Info.h Make FS_Info (blkid) cache incrementally loadable (#148) 2021-04-03 17:02:04 +00:00
FileSystem.h Also rename FS.filesystem member to fstype (!52) 2019-12-04 07:37:19 +00:00
Frame_Resizer_Base.h Use Gdk::RGBA (!25) 2019-04-27 12:03:04 +01:00
Frame_Resizer_Extended.h Put Frame_Resizer_{Base,Extended} modules into GParted namespace (!20) 2018-11-26 17:56:32 +00:00
GParted_Core.h Remove coding landmine in get_disk() (#152) 2021-04-15 16:33:01 +00:00
HBoxOperations.h Use Gtk::Box for HBoxOperations (!25) 2019-04-27 12:03:04 +01:00
LUKS_Info.h Capture LUKS mapping master encryption key location (#59) 2021-04-25 15:49:35 +00:00
LVM2_PV_Info.h Pass constant string by reference to lvm2_pv_size_to_num() 2021-03-10 16:40:44 +00:00
Makefile.am Split FILESYSTEMS and FILESYSTEM_MAP into separate module (!49) 2019-11-09 17:18:34 +00:00
MenuHelpers.h prepare-for-gtk3: Prepare for removal of Gtk::Menu_Helpers::Element (#7) 2019-02-11 08:57:18 +00:00
Mount_Info.h Add and set read-only mount flag in the Partition object (#10) 2018-09-20 16:30:15 +00:00
Operation.h Create and use general find_extended_partition() function 2017-01-14 08:49:58 -07:00
OperationChangeUUID.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationCheck.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationCopy.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationCreate.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationDelete.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationDetail.h Rename OperationDetailStatus STATUS_N_A to STATUS_WARNING 2017-11-26 10:53:52 -07:00
OperationFormat.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationLabelFileSystem.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationNamePartition.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationResizeMove.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OptionComboBox.h modern-gtk2: Delay construction of Gtk::TreeModel* objects (!17) 2018-11-12 21:50:42 +00:00
Partition.h Rename Partition.filesystem member to fstype (!52) 2019-12-03 13:24:44 +00:00
PartitionLUKS.h Rename enum FILESYSTEM to FSType 2018-01-28 10:09:35 -07:00
PartitionVector.h Create and use general find_extended_partition() function 2017-01-14 08:49:58 -07:00
PasswordRAMStore.h Change to insert or replace PasswordRAMStore::store() interface (#795617) 2018-04-30 09:10:48 -06:00
PipeCapture.h Refactor ::OnReadable() creating get_utf8_char_validated() (#136) 2021-02-22 16:14:35 +00:00
Proc_Partitions_Info.h Read partition names from /proc/partitions too (#131) 2021-02-10 16:30:13 +00:00
ProgressBar.h Write a generic progress bar class (#760709) 2016-02-12 09:09:56 -07:00
SWRaid_Info.h Display correct type of mdadm recognised ATARAID members (#75) 2019-12-02 16:35:22 +00:00
SupportedFileSystems.h Split FILESYSTEMS and FILESYSTEM_MAP into separate module (!49) 2019-11-09 17:18:34 +00:00
TreeView_Detail.h Remove unneeded #include <vector> from TreeView_Detail.h 2020-09-18 16:00:44 +00:00
Utils.h Rename Utils method parameters of type FSType (!52) 2019-12-04 07:38:00 +00:00
Win_GParted.h Replace Win_GParted::hbox member with local variables 2021-02-10 16:30:14 +00:00
btrfs.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00
exfat.h Add support for updating the exFAT UUID (!67) 2021-02-17 17:16:48 +00:00
ext2.h Remove checks for e4fsprogs commands (#794253) 2018-03-26 10:16:45 -06:00
f2fs.h Enhance F2FS support (!29) 2019-03-26 08:08:10 +00:00
fat16.h Switch to faster minfo and mdir to read FAT16/32 usage (#569921) 2019-07-04 10:51:50 -06:00
hfs.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
hfsplus.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
i18n.h Drop compose subdir (#46) 2019-03-27 16:45:22 +00:00
jfs.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00
linux_swap.h Make get_custom_text() and get_generic_text() return by reference 2018-06-18 10:15:33 -06:00
luks.h Make get_custom_text() and get_generic_text() return by reference 2018-06-18 10:15:33 -06:00
lvm2_pv.h Make get_custom_text() and get_generic_text() return by reference 2018-06-18 10:15:33 -06:00
minix.h Add support for minix file system (!12) 2018-08-24 20:22:08 +01:00
nilfs2.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00
ntfs.h Rework scope of fat16:: and ntfs::Change_UUID_Warning vectors 2018-06-18 14:47:17 -06:00
reiser4.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
reiserfs.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00
udf.h Set dynamic UDF file system size limits (#787204) 2018-01-28 10:09:35 -07:00
xfs.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00