Skip to content

Commit 4395335

Browse files
authored
Merge pull request #308 from desultory/dev
prompt for user input on gpg key open failure, improve formatting
2 parents 0f67cf2 + ac9b69f commit 4395335

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/ugrd/crypto/cryptsetup.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "4.1.1"
2+
__version__ = "4.1.2"
33

44
from json import loads
55
from pathlib import Path
@@ -242,10 +242,18 @@ def _validate_cryptsetup_header(self, mapped_name: str) -> None:
242242
self.logger.warning(f"Unable to validate LUKS header for: {c_(mapped_name, 'red', bold=True)}\n")
243243
if "header_file" not in cryptsetup_info:
244244
self.logger.warning("If the header is detached, please set `header_file` in the configuration.")
245-
self.logger.warning("If the header is detached not accessible at build time, please set `validate_header = false`.")
246-
self.logger.critical("When header validation is disabled, it's up to the user to ensure valid headers are accessible at boot time, and that cryptsetup is built with the correct dependencies!")
247-
self.logger.warning("Validation is not supported for LUKS1. If LUKS1 is being used, please consider using LUKS2 if possible.\n")
248-
self.logger.info(f"Header validation can be disabled for this LUKS volume by setting the following configuration:\n\n[cryptsetup.{mapped_name}]\nvalidate_header = false\n\nor by setting `cryptsetup_header_validation = false` globally.\n")
245+
self.logger.warning(
246+
"If the header is detached not accessible at build time, please set `validate_header = false`."
247+
)
248+
self.logger.critical(
249+
"When header validation is disabled, it's up to the user to ensure valid headers are accessible at boot time, and that cryptsetup is built with the correct dependencies!"
250+
)
251+
self.logger.warning(
252+
"Validation is not supported for LUKS1. If LUKS1 is being used, please consider using LUKS2 if possible.\n"
253+
)
254+
self.logger.info(
255+
f"Header validation can be disabled for this LUKS volume by setting the following configuration:\n\n[cryptsetup.{mapped_name}]\nvalidate_header = false\n\nor by setting `cryptsetup_header_validation = false` globally.\n"
256+
)
249257

250258
raise e
251259

@@ -504,12 +512,18 @@ def _open_crypt_dev(self, name: str, parameters: dict) -> list[str]:
504512
key_command = parameters.get("key_command")
505513
plymouth_key_command = parameters.get("plymouth_key_command") if "ugrd.base.plymouth" in self["modules"] else None
506514

507-
_key_command_lines = f""" einfo "($i/$retries)[{name}] Running key command: {key_command}"
508-
if ! {key_command} > /run/ugrd/key_data; then
509-
ewarn 'Failed to run key command: {key_command}'
510-
{reset_command}
511-
continue
512-
fi"""
515+
# Build the key command lines
516+
_key_command_lines = "\n".join(
517+
[
518+
f'einfo "($i/$retries)[{name}] Running key command: {key_command}"',
519+
f"if ! {key_command} > /run/ugrd/key_data; then",
520+
f" ewarn 'Failed to run key command: {key_command}'",
521+
" prompt_user 'Press space to retry'" if not self["cryptsetup_autoretry"] else "",
522+
f" {reset_command}" if reset_command else "",
523+
" continue",
524+
"fi",
525+
]
526+
)
513527

514528
if key_command:
515529
self.logger.debug("[%s] Using key command: %s" % (name, key_command))

0 commit comments

Comments
 (0)