Added --crypt-x options as parameters, that passes in the values to the .encrypt() function to set iter-time, key-size and hash-type.
This commit is contained in:
parent
f1333eb77c
commit
205d217a44
|
|
@ -72,6 +72,9 @@ def define_arguments():
|
|||
parser.add_argument("--script", default="guided", nargs="?", help="Script to run for installation", type=str)
|
||||
parser.add_argument("--mount-point","--mount_point", nargs="?", type=str, help="Define an alternate mount point for installation")
|
||||
parser.add_argument("--debug", action="store_true", default=False, help="Adds debug info into the log")
|
||||
parser.add_argument("--crypt-iter-time", default='10000', nargs="?", type=str)
|
||||
parser.add_argument("--crypt-key-size", default='512', nargs="?", type=str)
|
||||
parser.add_argument("--crypt-hash-type", default='sha512', nargs="?", type=str)
|
||||
parser.add_argument("--plugin", nargs="?", type=str)
|
||||
|
||||
def parse_unspecified_argument_list(unknowns :list, multiple :bool = False, error :bool = False) -> dict:
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ import pathlib
|
|||
import glob
|
||||
import logging
|
||||
import re
|
||||
from typing import Union, Dict, TYPE_CHECKING, Any, Iterator
|
||||
from typing import Union, Dict, TYPE_CHECKING, Any, Iterator, Optional
|
||||
from dataclasses import dataclass
|
||||
|
||||
# https://stackoverflow.com/a/39757388/929999
|
||||
if TYPE_CHECKING:
|
||||
from ..installer import Installer
|
||||
from .helpers import get_mount_info
|
||||
from .helpers import get_mount_info, get_mount_fs_type
|
||||
from ..exceptions import DiskError
|
||||
from ..general import SysCommand
|
||||
from ..output import log
|
||||
|
|
@ -24,6 +24,37 @@ class BtrfsSubvolume:
|
|||
options :str
|
||||
root :bool = False
|
||||
|
||||
@property
|
||||
def MapperDev(self):
|
||||
return self._mapperdev
|
||||
|
||||
def mount(self, target :str, fs :Optional[str] = None, options :str = '') -> bool:
|
||||
log(f'Mounting {self} to {target}', level=logging.INFO)
|
||||
if not fs:
|
||||
if not self.MapperDev.filesystem:
|
||||
raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.')
|
||||
fs = self.MapperDev.filesystem
|
||||
|
||||
fs_type = get_mount_fs_type(fs)
|
||||
|
||||
pathlib.Path(target).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# TODO: Detect if destination is already mounted some how.
|
||||
# Otherwise we won't be able to mount the subvolume.
|
||||
|
||||
# TODO options should be better be a list than a string
|
||||
if options:
|
||||
options = f"{options},subvol={self.name}"
|
||||
else:
|
||||
options = f"subvol={self.name}"
|
||||
|
||||
try:
|
||||
SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.MapperDev.path} {target}")
|
||||
except SysCallError as err:
|
||||
raise DiskError(f"Could not mount {self.path} to {target} using options {options}: {err}")
|
||||
|
||||
return True
|
||||
|
||||
def get_subvolumes_from_findmnt(struct :Dict[str, Any], index=0) -> Iterator[BtrfsSubvolume]:
|
||||
if '@' in struct['source']:
|
||||
subvolume = re.findall(r'\[.*?\]', struct['source'])[0][1:-1]
|
||||
|
|
|
|||
|
|
@ -123,7 +123,12 @@ class Filesystem:
|
|||
else:
|
||||
loopdev = f"{storage.get('ENC_IDENTIFIER', 'ai')}{pathlib.Path(partition['device_instance'].path).name}"
|
||||
|
||||
partition['device_instance'].encrypt(password=partition['!password'])
|
||||
partition['device_instance'].encrypt(
|
||||
password=partition['!password'],
|
||||
key_size=storage['arguments']['crypt-key-size'],
|
||||
hash_type=storage['arguments']['crypt-hash-type'],
|
||||
iter_time=storage['arguments']['crypt-iter-time']
|
||||
)
|
||||
# Immediately unlock the encrypted device to format the inner volume
|
||||
with luks2(partition['device_instance'], loopdev, partition['!password'], auto_unmount=True) as unlocked_device:
|
||||
if not partition.get('wipe'):
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import json
|
|||
from dataclasses import dataclass
|
||||
from typing import Optional, List, Dict, Any, Iterator, TYPE_CHECKING
|
||||
|
||||
from ..exceptions import SysCallError
|
||||
from ..exceptions import SysCallError, DiskError
|
||||
from ..general import SysCommand
|
||||
from ..output import log
|
||||
|
||||
|
|
@ -103,12 +103,10 @@ class MapperDev:
|
|||
|
||||
try:
|
||||
if options:
|
||||
mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.path} {target}")
|
||||
SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.path} {target}")
|
||||
else:
|
||||
mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} {self.path} {target}")
|
||||
|
||||
SysCommand(f"/usr/bin/mount -t {fs_type} {self.path} {target}")
|
||||
except SysCallError as err:
|
||||
raise DiskError(f"Could not mount {self.path} to {target} using options {options}: {err}")
|
||||
|
||||
return True
|
||||
|
||||
return True
|
||||
|
|
@ -107,7 +107,7 @@ class luks2:
|
|||
|
||||
pw_given = False
|
||||
while cryptworker.is_alive():
|
||||
if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker and pw_given is False:
|
||||
if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker._trace_log and pw_given is False:
|
||||
cryptworker.write(password)
|
||||
pw_given = True
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ class luks2:
|
|||
|
||||
pw_given = False
|
||||
while cryptworker.is_alive():
|
||||
if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker and pw_given is False:
|
||||
if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker._trace_log and pw_given is False:
|
||||
cryptworker.write(password)
|
||||
pw_given = True
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue