diff --git a/include/LUKS_Info.h b/include/LUKS_Info.h index 6ac6c9d0..0a9120f7 100644 --- a/include/LUKS_Info.h +++ b/include/LUKS_Info.h @@ -34,12 +34,19 @@ namespace GParted { +enum KeyLocation +{ + KEYLOC_DMCrypt = 0, // Master encryption key is stored in DeviceMapper crypt target + KEYLOC_KeyRing // Master encryption key was stored in kernel Key Ring +}; + struct LUKS_Mapping { Glib::ustring name; // Name of the dm-crypt mapping BlockSpecial container; // Underlying block device containing the LUKS mapping Byte_Value offset; // Offset to the start of the mapping in the underlying block device Byte_Value length; // Length of the mapping in the underlying block device + KeyLocation key_loc; // Location where the master encryption key is stored }; class LUKS_Info diff --git a/src/LUKS_Info.cc b/src/LUKS_Info.cc index 45612bbb..598acf68 100644 --- a/src/LUKS_Info.cc +++ b/src/LUKS_Info.cc @@ -72,7 +72,7 @@ void LUKS_Info::load_cache() // _status() function: // https://git.fedorahosted.org/cgit/lvm2.git/tree/tools/dmsetup.c?id=v2_02_118#n1715 // Field 5 onwards are called parameters and documented in the kernel source: - // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/device-mapper/dm-crypt.txt?id=v4.0 + // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/device-mapper/dm-crypt.txt?id=v5.0 std::vector lines; Utils::tokenize( output, lines, "\n" ); @@ -83,6 +83,7 @@ void LUKS_Info::load_cache() Utils::tokenize( lines[i], fields, " " ); const unsigned DMCRYPT_FIELD_Name = 0; const unsigned DMCRYPT_FIELD_length = 2; + const unsigned DMCRYPT_FIELD_key = 5; const unsigned DMCRYPT_FIELD_devpath = 7; const unsigned DMCRYPT_FIELD_offset = 8; @@ -126,6 +127,16 @@ void LUKS_Info::load_cache() else continue; + // Extract LUKS mapping master key location. Following the cryptsetup + // implementation method; first character of KEY field is ":" means the + // master key was stored in the kernel key ring, otherwise it is stored in + // the Device-Mapper crypt target itself. + // * cryptsetup/v2.3.5/lib/libdevmapper.c:_dm_target_query_crypt() + // https://gitlab.com/cryptsetup/cryptsetup/-/blob/v2.3.5/lib/libdevmapper.c#L2031 + // * cryptsetup/v2.3.5/src/cryptsetup.c:action_status() + // https://gitlab.com/cryptsetup/cryptsetup/-/blob/v2.3.5/src/cryptsetup.c#L839 + luks_map.key_loc = (fields[DMCRYPT_FIELD_key][0] == ':') ? KEYLOC_KeyRing : KEYLOC_DMCrypt; + luks_mapping_cache.push_back( luks_map ); } }