Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ def encrypt(
enc_password: Password | None,
lock_after_create: bool = True,
iter_time: int = DEFAULT_ITER_TIME,
cipher: str | None = None,
) -> Luks2:
luks_handler = Luks2(
dev_path,
mapper_name=mapper_name,
password=enc_password,
cipher=cipher,
)

key_file = luks_handler.encrypt(iter_time=iter_time)
Expand Down Expand Up @@ -316,6 +318,7 @@ def format_encrypted(
dev_path,
mapper_name=mapper_name,
password=enc_conf.encryption_password,
cipher=enc_conf.cipher,
)

key_file = luks_handler.encrypt(iter_time=enc_conf.iter_time)
Expand Down
44 changes: 43 additions & 1 deletion archinstall/lib/disk/encryption_menu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import override
from typing import Any, override

from archinstall.lib.disk.fido import Fido2
from archinstall.lib.menu.abstract_menu import AbstractSubMenu
Expand All @@ -10,6 +10,7 @@
DEFAULT_ITER_TIME,
DeviceModification,
DiskEncryption,
EncryptionCipher,
EncryptionType,
Fido2Device,
LvmConfiguration,
Expand Down Expand Up @@ -47,6 +48,37 @@ def __init__(
allow_reset=True,
)

async def _select_cipher(self, current_value: Any) -> Any:
items = [MenuItem(cipher.value, value=cipher) for cipher in EncryptionCipher]
group = MenuItemGroup(items)

result = await Selection[EncryptionCipher](
group,
header=tr('Select encryption cipher'),
allow_skip=True,
allow_reset=True,
).show()

match result.type_:
case ResultType.Selection:
selected_enum = result.get_value()
self._enc_config.cipher = selected_enum
return selected_enum
case _:
return current_value

def _prev_cipher(self, item: MenuItem) -> str | None:
val = item.value if item.value else getattr(self._enc_config, 'cipher', None)

if not val:
val_str = 'aes-xts-plain64'
elif hasattr(val, 'value'):
val_str = val.value
else:
val_str = str(val)

return f'{tr("Encryption cipher")}: {val_str}'

def _define_menu_options(self) -> list[MenuItem]:
return [
MenuItem(
Expand All @@ -72,6 +104,14 @@ def _define_menu_options(self) -> list[MenuItem]:
preview_action=self._prev_iter_time,
key='iter_time',
),
MenuItem(
text=tr('Encryption cipher'),
action=self._select_cipher,
value=self._enc_config.cipher if hasattr(self._enc_config, 'cipher') and self._enc_config.cipher else EncryptionCipher.AES_XTS_PLAIN64,
preview_action=self._prev_cipher,
dependencies=[self._check_dep_enc_type],
key='cipher',
),
MenuItem(
text=tr('Partitions'),
action=lambda x: select_partitions_to_encrypt(self._device_modifications, x),
Expand Down Expand Up @@ -132,6 +172,7 @@ async def show(self) -> DiskEncryption | None:
iter_time: int | None = self._item_group.find_by_key('iter_time').value
enc_partitions = self._item_group.find_by_key('partitions').value
enc_lvm_vols = self._item_group.find_by_key('lvm_volumes').value
cipher_value: str | None = self._item_group.find_by_key('cipher').value

assert enc_type is not None
assert enc_partitions is not None
Expand All @@ -151,6 +192,7 @@ async def show(self) -> DiskEncryption | None:
lvm_volumes=enc_lvm_vols,
hsm_device=enc_config.hsm_device,
iter_time=iter_time or DEFAULT_ITER_TIME,
cipher=cipher_value,
)

return None
Expand Down
6 changes: 6 additions & 0 deletions archinstall/lib/disk/luks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Luks2:
password: Password | None = None
key_file: Path | None = None
auto_unmount: bool = False
cipher: str | None = None

@property
def mapper_dev(self) -> Path | None:
Expand Down Expand Up @@ -94,6 +95,11 @@ def encrypt(
str(iter_time),
*key_file_arg,
'--use-urandom',
]
if self.cipher:
cmd += ['--cipher', self.cipher]

cmd += [
'luksFormat',
str(self.luks_dev_path),
]
Expand Down
8 changes: 8 additions & 0 deletions archinstall/lib/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,10 @@ class _DiskEncryptionSerialization(TypedDict):
hsm_device: NotRequired[_Fido2DeviceSerialization]
iter_time: NotRequired[int]

class EncryptionCipher(Enum):
AES_XTS_PLAIN64 = "aes-xts-plain64"
AES_ADIANTUM_PLAIN64 = "aes-adiantum-plain64"
CHACHA20_RANDOM_PLAIN64 = "chacha20-random-plain64"

@dataclass
class DiskEncryption:
Expand All @@ -1478,6 +1482,7 @@ class DiskEncryption:
lvm_volumes: list[LvmVolume] = field(default_factory=list)
hsm_device: Fido2Device | None = None
iter_time: int = DEFAULT_ITER_TIME
cipher: EncryptionCipher | None = None

def __post_init__(self) -> None:
if self.encryption_type in [EncryptionType.LUKS, EncryptionType.LVM_ON_LUKS] and not self.partitions:
Expand Down Expand Up @@ -1505,6 +1510,9 @@ def json(self) -> _DiskEncryptionSerialization:
if self.iter_time != DEFAULT_ITER_TIME: # Only include if not default
obj['iter_time'] = self.iter_time

if self.cipher:
obj['cipher'] = self.cipher

return obj

@staticmethod
Expand Down