Move unlock_luks2_dev() (#4234)
This commit is contained in:
parent
35c2ff3ef5
commit
083a73eab1
|
|
@ -10,7 +10,7 @@ from parted import Device, Disk, DiskException, FileSystem, Geometry, IOExceptio
|
|||
|
||||
from ..command import SysCommand, SysCommandWorker
|
||||
from ..exceptions import DiskError, SysCallError, UnknownFilesystemFormat
|
||||
from ..luks import Luks2
|
||||
from ..luks import Luks2, unlock_luks2_dev
|
||||
from ..models.device import (
|
||||
DEFAULT_ITER_TIME,
|
||||
BDevice,
|
||||
|
|
@ -658,7 +658,7 @@ class DeviceHandler:
|
|||
if not part_mod.mapper_name:
|
||||
raise ValueError('No device path specified for modification')
|
||||
|
||||
luks_handler = self.unlock_luks2_dev(
|
||||
luks_handler = unlock_luks2_dev(
|
||||
part_mod.safe_dev_path,
|
||||
part_mod.mapper_name,
|
||||
enc_conf.encryption_password,
|
||||
|
|
@ -691,19 +691,6 @@ class DeviceHandler:
|
|||
if luks_handler is not None and luks_handler.mapper_dev is not None:
|
||||
luks_handler.lock()
|
||||
|
||||
def unlock_luks2_dev(
|
||||
self,
|
||||
dev_path: Path,
|
||||
mapper_name: str,
|
||||
enc_password: Password | None,
|
||||
) -> Luks2:
|
||||
luks_handler = Luks2(dev_path, mapper_name=mapper_name, password=enc_password)
|
||||
|
||||
if not luks_handler.is_unlocked():
|
||||
luks_handler.unlock()
|
||||
|
||||
return luks_handler
|
||||
|
||||
def umount_all_existing(self, device_path: Path) -> None:
|
||||
debug(f'Unmounting all existing partitions: {device_path}')
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ from .command import SysCommand, run
|
|||
from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError
|
||||
from .hardware import SysInfo
|
||||
from .locale.utils import verify_keyboard_layout, verify_x11_keyboard_layout
|
||||
from .luks import Luks2
|
||||
from .luks import Luks2, unlock_luks2_dev
|
||||
from .mirrors import MirrorListHandler
|
||||
from .models.bootloader import Bootloader
|
||||
from .models.locale import LocaleConfiguration
|
||||
|
|
@ -317,7 +317,7 @@ class Installer:
|
|||
partitions: list[PartitionModification],
|
||||
) -> dict[PartitionModification, Luks2]:
|
||||
return {
|
||||
part_mod: device_handler.unlock_luks2_dev(
|
||||
part_mod: unlock_luks2_dev(
|
||||
part_mod.dev_path,
|
||||
part_mod.mapper_name,
|
||||
self._disk_encryption.encryption_password,
|
||||
|
|
@ -344,7 +344,7 @@ class Installer:
|
|||
lvm_volumes: list[LvmVolume],
|
||||
) -> dict[LvmVolume, Luks2]:
|
||||
return {
|
||||
vol: device_handler.unlock_luks2_dev(
|
||||
vol: unlock_luks2_dev(
|
||||
vol.dev_path,
|
||||
vol.mapper_name,
|
||||
self._disk_encryption.encryption_password,
|
||||
|
|
|
|||
|
|
@ -237,3 +237,16 @@ class Luks2:
|
|||
uuid = self._get_luks_uuid()
|
||||
row = f'{self.mapper_name} UUID={uuid} {key_file} {opt}\n'
|
||||
crypttab.write(row)
|
||||
|
||||
|
||||
def unlock_luks2_dev(
|
||||
dev_path: Path,
|
||||
mapper_name: str,
|
||||
enc_password: Password | None,
|
||||
) -> Luks2:
|
||||
luks_handler = Luks2(dev_path, mapper_name=mapper_name, password=enc_password)
|
||||
|
||||
if not luks_handler.is_unlocked():
|
||||
luks_handler.unlock()
|
||||
|
||||
return luks_handler
|
||||
|
|
|
|||
Loading…
Reference in New Issue