gparted/include/LUKS_Info.h

63 lines
1.8 KiB
C
Raw Normal View History

/* Copyright (C) 2015 Mike Fleetwood
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
/* LUKS_Info
*
* Cache of active Linux kernel Device-mapper encryption mappings.
* (Named LUKS because only encryption using the LUKS on disk format is
* recognised and handled).
*/
#ifndef GPARTED_LUKS_INFO_H
#define GPARTED_LUKS_INFO_H
#include "BlockSpecial.h"
#include "Utils.h"
Add loading of LUKS mapping offset and length (#760080) Also load the starting offset and length of the active dm-crypt mapping into the LUKS_Info module from the dmsetup output. This provides the location and size of the encrypted data within the underlying block device. Note that dmsetup reports in units of 512 bytes sectors [1], the GParted LUKS_Info module uses bytes and GParted Partition objects work in device sector size units. However the actual sector size of a dm-crypt mapping [2] is the same as that of the underlying block device [3]. # modprobe scsi_debug dev_size_mb=128 sector_size=4096 # fgrep scsi_debug /sys/block/*/device/model /sys/block/sdd/device/model:scsi_debug # parted /dev/sde print Error: /dev/sde: unrecognised disk label Model: Linux scsi_debug (scsi) Disk /dev/sde: 134MB [3] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup luksFormat /dev/sde # cryptsetup luksOpen /dev/sde sde_crypt # parted /dev/mapper/sde_crypt print Error: /dev/mapper/sde_crypt: unrecognised disk label Model: Linux device-mapper (crypt) (dm) Disk /dev/mapper/sde_crypt: 132MB [2] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup status sde_crypt /dev/mapper/sde_crypt is active. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sde offset: 4096 sectors size: 258048 sectors mode: read/write # dmsetup table --target crypt ... sde_crypt: 0 258048 crypt aes-cbc-essiv:sha256 0000000000000000000000000000000000000000000000000000000000000000 0 8:64 4096 [1] Both cryptsetup and dmsetup report the offset as 4096 and the size/ length as 258048. 128 MiB / (4096+258048) = 512 byte units, even on a 4096 byte sector size device. Update debugging of LUKS to this: # ./gpartedbin ====================== libparted : 2.4 ====================== DEBUG: /dev/sdb5: LUKS closed DEBUG: /dev/sdb6: LUKS open mapping /dev/mapper/sdb6_crypt, offset=2097152, length=534773760 /dev/sde: unrecognised disk label DEBUG: /dev/sde: LUKS open mapping /dev/mapper/sde_crypt, offset=2097152, length=132120576 Bug 760080 - Implement read-only LUKS support
2015-04-19 07:08:20 -06:00
#include <glibmm/ustring.h>
Add loading of LUKS mapping offset and length (#760080) Also load the starting offset and length of the active dm-crypt mapping into the LUKS_Info module from the dmsetup output. This provides the location and size of the encrypted data within the underlying block device. Note that dmsetup reports in units of 512 bytes sectors [1], the GParted LUKS_Info module uses bytes and GParted Partition objects work in device sector size units. However the actual sector size of a dm-crypt mapping [2] is the same as that of the underlying block device [3]. # modprobe scsi_debug dev_size_mb=128 sector_size=4096 # fgrep scsi_debug /sys/block/*/device/model /sys/block/sdd/device/model:scsi_debug # parted /dev/sde print Error: /dev/sde: unrecognised disk label Model: Linux scsi_debug (scsi) Disk /dev/sde: 134MB [3] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup luksFormat /dev/sde # cryptsetup luksOpen /dev/sde sde_crypt # parted /dev/mapper/sde_crypt print Error: /dev/mapper/sde_crypt: unrecognised disk label Model: Linux device-mapper (crypt) (dm) Disk /dev/mapper/sde_crypt: 132MB [2] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup status sde_crypt /dev/mapper/sde_crypt is active. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sde offset: 4096 sectors size: 258048 sectors mode: read/write # dmsetup table --target crypt ... sde_crypt: 0 258048 crypt aes-cbc-essiv:sha256 0000000000000000000000000000000000000000000000000000000000000000 0 8:64 4096 [1] Both cryptsetup and dmsetup report the offset as 4096 and the size/ length as 258048. 128 MiB / (4096+258048) = 512 byte units, even on a 4096 byte sector size device. Update debugging of LUKS to this: # ./gpartedbin ====================== libparted : 2.4 ====================== DEBUG: /dev/sdb5: LUKS closed DEBUG: /dev/sdb6: LUKS open mapping /dev/mapper/sdb6_crypt, offset=2097152, length=534773760 /dev/sde: unrecognised disk label DEBUG: /dev/sde: LUKS open mapping /dev/mapper/sde_crypt, offset=2097152, length=132120576 Bug 760080 - Implement read-only LUKS support
2015-04-19 07:08:20 -06:00
#include <vector>
namespace GParted
{
Add loading of LUKS mapping offset and length (#760080) Also load the starting offset and length of the active dm-crypt mapping into the LUKS_Info module from the dmsetup output. This provides the location and size of the encrypted data within the underlying block device. Note that dmsetup reports in units of 512 bytes sectors [1], the GParted LUKS_Info module uses bytes and GParted Partition objects work in device sector size units. However the actual sector size of a dm-crypt mapping [2] is the same as that of the underlying block device [3]. # modprobe scsi_debug dev_size_mb=128 sector_size=4096 # fgrep scsi_debug /sys/block/*/device/model /sys/block/sdd/device/model:scsi_debug # parted /dev/sde print Error: /dev/sde: unrecognised disk label Model: Linux scsi_debug (scsi) Disk /dev/sde: 134MB [3] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup luksFormat /dev/sde # cryptsetup luksOpen /dev/sde sde_crypt # parted /dev/mapper/sde_crypt print Error: /dev/mapper/sde_crypt: unrecognised disk label Model: Linux device-mapper (crypt) (dm) Disk /dev/mapper/sde_crypt: 132MB [2] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup status sde_crypt /dev/mapper/sde_crypt is active. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sde offset: 4096 sectors size: 258048 sectors mode: read/write # dmsetup table --target crypt ... sde_crypt: 0 258048 crypt aes-cbc-essiv:sha256 0000000000000000000000000000000000000000000000000000000000000000 0 8:64 4096 [1] Both cryptsetup and dmsetup report the offset as 4096 and the size/ length as 258048. 128 MiB / (4096+258048) = 512 byte units, even on a 4096 byte sector size device. Update debugging of LUKS to this: # ./gpartedbin ====================== libparted : 2.4 ====================== DEBUG: /dev/sdb5: LUKS closed DEBUG: /dev/sdb6: LUKS open mapping /dev/mapper/sdb6_crypt, offset=2097152, length=534773760 /dev/sde: unrecognised disk label DEBUG: /dev/sde: LUKS open mapping /dev/mapper/sde_crypt, offset=2097152, length=132120576 Bug 760080 - Implement read-only LUKS support
2015-04-19 07:08:20 -06:00
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
Add loading of LUKS mapping offset and length (#760080) Also load the starting offset and length of the active dm-crypt mapping into the LUKS_Info module from the dmsetup output. This provides the location and size of the encrypted data within the underlying block device. Note that dmsetup reports in units of 512 bytes sectors [1], the GParted LUKS_Info module uses bytes and GParted Partition objects work in device sector size units. However the actual sector size of a dm-crypt mapping [2] is the same as that of the underlying block device [3]. # modprobe scsi_debug dev_size_mb=128 sector_size=4096 # fgrep scsi_debug /sys/block/*/device/model /sys/block/sdd/device/model:scsi_debug # parted /dev/sde print Error: /dev/sde: unrecognised disk label Model: Linux scsi_debug (scsi) Disk /dev/sde: 134MB [3] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup luksFormat /dev/sde # cryptsetup luksOpen /dev/sde sde_crypt # parted /dev/mapper/sde_crypt print Error: /dev/mapper/sde_crypt: unrecognised disk label Model: Linux device-mapper (crypt) (dm) Disk /dev/mapper/sde_crypt: 132MB [2] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup status sde_crypt /dev/mapper/sde_crypt is active. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sde offset: 4096 sectors size: 258048 sectors mode: read/write # dmsetup table --target crypt ... sde_crypt: 0 258048 crypt aes-cbc-essiv:sha256 0000000000000000000000000000000000000000000000000000000000000000 0 8:64 4096 [1] Both cryptsetup and dmsetup report the offset as 4096 and the size/ length as 258048. 128 MiB / (4096+258048) = 512 byte units, even on a 4096 byte sector size device. Update debugging of LUKS to this: # ./gpartedbin ====================== libparted : 2.4 ====================== DEBUG: /dev/sdb5: LUKS closed DEBUG: /dev/sdb6: LUKS open mapping /dev/mapper/sdb6_crypt, offset=2097152, length=534773760 /dev/sde: unrecognised disk label DEBUG: /dev/sde: LUKS open mapping /dev/mapper/sde_crypt, offset=2097152, length=132120576 Bug 760080 - Implement read-only LUKS support
2015-04-19 07:08:20 -06:00
};
class LUKS_Info
{
public:
static void clear_cache();
Add loading of LUKS mapping offset and length (#760080) Also load the starting offset and length of the active dm-crypt mapping into the LUKS_Info module from the dmsetup output. This provides the location and size of the encrypted data within the underlying block device. Note that dmsetup reports in units of 512 bytes sectors [1], the GParted LUKS_Info module uses bytes and GParted Partition objects work in device sector size units. However the actual sector size of a dm-crypt mapping [2] is the same as that of the underlying block device [3]. # modprobe scsi_debug dev_size_mb=128 sector_size=4096 # fgrep scsi_debug /sys/block/*/device/model /sys/block/sdd/device/model:scsi_debug # parted /dev/sde print Error: /dev/sde: unrecognised disk label Model: Linux scsi_debug (scsi) Disk /dev/sde: 134MB [3] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup luksFormat /dev/sde # cryptsetup luksOpen /dev/sde sde_crypt # parted /dev/mapper/sde_crypt print Error: /dev/mapper/sde_crypt: unrecognised disk label Model: Linux device-mapper (crypt) (dm) Disk /dev/mapper/sde_crypt: 132MB [2] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup status sde_crypt /dev/mapper/sde_crypt is active. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sde offset: 4096 sectors size: 258048 sectors mode: read/write # dmsetup table --target crypt ... sde_crypt: 0 258048 crypt aes-cbc-essiv:sha256 0000000000000000000000000000000000000000000000000000000000000000 0 8:64 4096 [1] Both cryptsetup and dmsetup report the offset as 4096 and the size/ length as 258048. 128 MiB / (4096+258048) = 512 byte units, even on a 4096 byte sector size device. Update debugging of LUKS to this: # ./gpartedbin ====================== libparted : 2.4 ====================== DEBUG: /dev/sdb5: LUKS closed DEBUG: /dev/sdb6: LUKS open mapping /dev/mapper/sdb6_crypt, offset=2097152, length=534773760 /dev/sde: unrecognised disk label DEBUG: /dev/sde: LUKS open mapping /dev/mapper/sde_crypt, offset=2097152, length=132120576 Bug 760080 - Implement read-only LUKS support
2015-04-19 07:08:20 -06:00
static const LUKS_Mapping & get_cache_entry( const Glib::ustring & path );
private:
static void initialise_if_required();
static void load_cache();
static const LUKS_Mapping & get_cache_entry_internal( const Glib::ustring & path );
Add loading of LUKS mapping offset and length (#760080) Also load the starting offset and length of the active dm-crypt mapping into the LUKS_Info module from the dmsetup output. This provides the location and size of the encrypted data within the underlying block device. Note that dmsetup reports in units of 512 bytes sectors [1], the GParted LUKS_Info module uses bytes and GParted Partition objects work in device sector size units. However the actual sector size of a dm-crypt mapping [2] is the same as that of the underlying block device [3]. # modprobe scsi_debug dev_size_mb=128 sector_size=4096 # fgrep scsi_debug /sys/block/*/device/model /sys/block/sdd/device/model:scsi_debug # parted /dev/sde print Error: /dev/sde: unrecognised disk label Model: Linux scsi_debug (scsi) Disk /dev/sde: 134MB [3] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup luksFormat /dev/sde # cryptsetup luksOpen /dev/sde sde_crypt # parted /dev/mapper/sde_crypt print Error: /dev/mapper/sde_crypt: unrecognised disk label Model: Linux device-mapper (crypt) (dm) Disk /dev/mapper/sde_crypt: 132MB [2] Sector size (logical/physical): 4096B/4096B Partition Table: unknown # cryptsetup status sde_crypt /dev/mapper/sde_crypt is active. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sde offset: 4096 sectors size: 258048 sectors mode: read/write # dmsetup table --target crypt ... sde_crypt: 0 258048 crypt aes-cbc-essiv:sha256 0000000000000000000000000000000000000000000000000000000000000000 0 8:64 4096 [1] Both cryptsetup and dmsetup report the offset as 4096 and the size/ length as 258048. 128 MiB / (4096+258048) = 512 byte units, even on a 4096 byte sector size device. Update debugging of LUKS to this: # ./gpartedbin ====================== libparted : 2.4 ====================== DEBUG: /dev/sdb5: LUKS closed DEBUG: /dev/sdb6: LUKS open mapping /dev/mapper/sdb6_crypt, offset=2097152, length=534773760 /dev/sde: unrecognised disk label DEBUG: /dev/sde: LUKS open mapping /dev/mapper/sde_crypt, offset=2097152, length=132120576 Bug 760080 - Implement read-only LUKS support
2015-04-19 07:08:20 -06:00
static std::vector<LUKS_Mapping> luks_mapping_cache;
static bool cache_initialised;
};
}//GParted
#endif /* GPARTED_LUKS_INFO_H */