| 1472 | |
| 1473 | @dataclass |
| 1474 | class DiskEncryption: |
| 1475 | encryption_type: EncryptionType = EncryptionType.NO_ENCRYPTION |
| 1476 | encryption_password: Password | None = None |
| 1477 | partitions: list[PartitionModification] = field(default_factory=list) |
| 1478 | lvm_volumes: list[LvmVolume] = field(default_factory=list) |
| 1479 | hsm_device: Fido2Device | None = None |
| 1480 | iter_time: int = DEFAULT_ITER_TIME |
| 1481 | |
| 1482 | def __post_init__(self) -> None: |
| 1483 | if self.encryption_type in [EncryptionType.LUKS, EncryptionType.LVM_ON_LUKS] and not self.partitions: |
| 1484 | raise ValueError('Luks or LvmOnLuks encryption require partitions to be defined') |
| 1485 | |
| 1486 | if self.encryption_type == EncryptionType.LUKS_ON_LVM and not self.lvm_volumes: |
| 1487 | raise ValueError('LuksOnLvm encryption require LMV volumes to be defined') |
| 1488 | |
| 1489 | def should_generate_encryption_file(self, dev: PartitionModification | LvmVolume) -> bool: |
| 1490 | if isinstance(dev, PartitionModification): |
| 1491 | return dev in self.partitions and dev.mountpoint != Path('/') |
| 1492 | else: |
| 1493 | return dev in self.lvm_volumes and dev.mountpoint != Path('/') |
| 1494 | |
| 1495 | def json(self) -> _DiskEncryptionSerialization: |
| 1496 | obj: _DiskEncryptionSerialization = { |
| 1497 | 'encryption_type': self.encryption_type.value, |
| 1498 | 'partitions': [p.obj_id for p in self.partitions], |
| 1499 | 'lvm_volumes': [vol.obj_id for vol in self.lvm_volumes], |
| 1500 | } |
| 1501 | |
| 1502 | if self.hsm_device: |
| 1503 | obj['hsm_device'] = self.hsm_device.json() |
| 1504 | |
| 1505 | if self.iter_time != DEFAULT_ITER_TIME: # Only include if not default |
| 1506 | obj['iter_time'] = self.iter_time |
| 1507 | |
| 1508 | return obj |
| 1509 | |
| 1510 | @staticmethod |
| 1511 | def validate_enc( |
| 1512 | modifications: list[DeviceModification], |
| 1513 | lvm_config: LvmConfiguration | None = None, |
| 1514 | ) -> bool: |
| 1515 | partitions = [] |
| 1516 | |
| 1517 | for mod in modifications: |
| 1518 | for part in mod.partitions: |
| 1519 | partitions.append(part) |
| 1520 | |
| 1521 | if len(partitions) > 2: # assume one boot and at least 2 additional |
| 1522 | if lvm_config: |
| 1523 | return False |
| 1524 | |
| 1525 | return True |
| 1526 | |
| 1527 | @classmethod |
| 1528 | def parse_arg( |
| 1529 | cls, |
| 1530 | disk_config: DiskLayoutConfiguration, |
| 1531 | disk_encryption: _DiskEncryptionSerialization, |
no outgoing calls
no test coverage detected