Compare commits

...

3 Commits

Author SHA1 Message Date
sebo-b d99d16d12e
Merge f6d1e2761b into cc983fc9dc 2025-04-14 14:41:01 +00:00
Sebastian Baberowski f6d1e2761b Fixed lint errors 2025-02-28 22:47:40 +01:00
Sebastian Baberowski fe09062bd3 ukify: added option to define custom boot phases 2025-02-26 00:05:02 +01:00
1 changed files with 25 additions and 17 deletions

View File

@ -279,6 +279,7 @@ class UkifyConfig:
pcrsig: Union[str, Path, None] pcrsig: Union[str, Path, None]
join_pcrsig: Optional[Path] join_pcrsig: Optional[Path]
phase_path_groups: Optional[list[str]] phase_path_groups: Optional[list[str]]
allow_custom_phases: bool
policy_digest: bool policy_digest: bool
profile: Optional[str] profile: Optional[str]
sb_cert: Union[str, Path, None] sb_cert: Union[str, Path, None]
@ -622,25 +623,10 @@ def parse_banks(s: str) -> list[str]:
return banks return banks
KNOWN_PHASES = (
'enter-initrd',
'leave-initrd',
'sysinit',
'ready',
'shutdown',
'final',
)
def parse_phase_paths(s: str) -> list[str]: def parse_phase_paths(s: str) -> list[str]:
# Split on commas or whitespace here. Commas might be hard to parse visually. # Split on commas or whitespace here. Commas might be hard to parse visually.
paths = re.split(r',|\s+', s) paths = re.split(r',|\s+', s)
for path in paths:
for phase in path.split(':'):
if phase not in KNOWN_PHASES:
raise argparse.ArgumentTypeError(f'Unknown boot phase {phase!r} ({path=})')
return paths return paths
@ -2159,6 +2145,12 @@ CONFIG_ITEMS = [
config_key='PCRSignature:/Phases', config_key='PCRSignature:/Phases',
config_push=ConfigItem.config_set_group, config_push=ConfigItem.config_set_group,
), ),
ConfigItem(
'--allow-custom-phases',
action=argparse.BooleanOptionalAction,
help='Allow use of custom defined phases',
config_key='PCRSignature:/AllowCustomPhases',
),
ConfigItem( ConfigItem(
'--tools', '--tools',
type=Path, type=Path,
@ -2322,6 +2314,16 @@ def resolve_at_path(value: Optional[str]) -> Union[Path, str, None]:
return value return value
KNOWN_PHASES = (
'enter-initrd',
'leave-initrd',
'sysinit',
'ready',
'shutdown',
'final',
)
def finalize_options(opts: argparse.Namespace) -> None: def finalize_options(opts: argparse.Namespace) -> None:
# Figure out which syntax is being used, one of: # Figure out which syntax is being used, one of:
# ukify verb --arg --arg --arg # ukify verb --arg --arg --arg
@ -2369,8 +2371,14 @@ def finalize_options(opts: argparse.Namespace) -> None:
raise ValueError('--pcr-certificate= specifications must match --pcr-private-key=') raise ValueError('--pcr-certificate= specifications must match --pcr-private-key=')
if n_pcr_pub is not None and n_pcr_cert is not None: if n_pcr_pub is not None and n_pcr_cert is not None:
raise ValueError('--pcr-public-key= and --pcr-certificate= cannot be used at the same time') raise ValueError('--pcr-public-key= and --pcr-certificate= cannot be used at the same time')
if n_phase_path_groups is not None and n_phase_path_groups != n_pcr_priv: if n_phase_path_groups is not None:
if n_phase_path_groups != n_pcr_priv:
raise ValueError('--phases= specifications must match --pcr-private-key=') raise ValueError('--phases= specifications must match --pcr-private-key=')
if not opts.allow_custom_phases:
for phase_path in itertools.chain.from_iterable(opts.phase_path_groups):
for phase in phase_path.split(':'):
if phase not in KNOWN_PHASES:
raise argparse.ArgumentTypeError(f'Unknown boot phase {phase!r} ({phase_path=})')
opts.cmdline = resolve_at_path(opts.cmdline) opts.cmdline = resolve_at_path(opts.cmdline)