Commit Graph
189 Commits
Author SHA1 Message Date
Thomas Hebb 32c3e1379d ukify: Fix regression in --no-sign-kernel flag
The man page says that --sign-kernel and --no-sign-kernel "override the
detection of whether to sign the Linux binary", so we should only
autodetect if neither are specified. But as of commit 02eabaffe9
("ukify: Add a unified interface for signing tools"), we autodetect even
when --no-sign-kernel is passed, which makes the flag useless.

The sign_kernel option is parsed using argparse.BooleanOptionalAction,
which sets it to either True, False, or None. commit 02eabaffe9
replaced `sign_kernel is None` with `not sign_kernel`. These are not the
same in Python, as the latter accepts False as well as None.

Restore the original check and fix type annotations accordingly.

Fixes: 02eabaffe9 ("ukify: Add a unified interface for signing tools")
2024-12-19 12:27:27 +09:00
Zbigniew Jędrzejewski-Szmek 544df97b41 ukify: ellipsize CN to not exceed maximum length
Currently the generation of the certificate fails if len(fqdn) >= 43.
Ellipsize the fqdn to let the tests pass in all cases.

Fixes https://github.com/systemd/systemd/issues/34581.
2024-12-02 16:55:57 +00:00
Zbigniew Jędrzejewski-Szmek ef20d06da6 ukify: Switch to JSON HWID description format (#35208)
Fixes #35176
2024-11-27 09:50:41 +01:00
Daan De Meyer d6047d9fb5 ukify: Fix typing error 2024-11-24 16:47:20 +01:00
Daan De Meyer a2aacbfad5 Move mypy.ini and ruff.toml to top level
This allows reusing them for integration-test-wrapper.py as well.
2024-11-24 16:47:20 +01:00
anonymix007 cf331f1c9b ukify: Switch to JSON HWID description format 2024-11-22 00:42:47 +03:00
Zbigniew Jędrzejewski-Szmek 5e7e4e4d49 ukify: fix parsing of SignTool configuration option
This partially reverts 02eabaffe9.
As noted in https://github.com/systemd/systemd/pull/35211:
> The configuration parsing simply stores the string as-is, rather than
> creating the appropriate object

One way to fix the issue would be to store the "appropriate object", i.e.
actually the class. But that makes the code very verbose, with the conversion
being done in two places. And that still doesn't fix the issue, because we need
to map the class objects back to the original name in error messages.

So instead, store the setting as a string and only map it to the class much
later. This makes the code simpler and fixes the error messages too.

Resolves https://github.com/systemd/systemd/pull/35193
2024-11-18 14:58:41 +00:00
anonymix007 61d6075775 ukify: Use new .hwids PE section format 2024-11-15 19:15:30 +00:00
anonymix007 0333b9d589 ukify: Support building UKIs with a .hwids section
This section contains a predefined set of HWIDs and the corresponding compatibles to be used in dtb matching
2024-11-14 16:42:42 +03:00
anonymix007 fa258f7729 ukify: Support building UKIs with .dtbauto sections 2024-11-14 16:42:35 +03:00
Lennart Poettering 67e003d7dd Introduce systemd-keyutil to do various key/certificate operations (#35095)
Let's gather generic key/certificate operations in a new tool
systemd-keyutil instead of spreading them across various special purpose
tools.

Fixes #35087
2024-11-11 16:09:07 +01:00
Valentin David 053452e22b ukify: Fix broken assert when building a signed addon
An assert always expected a kernel when signature key was present in command
line. That prevented building signed addons.

Fixes #35041
2024-11-10 05:44:30 +09:00
Daan De Meyer 4b1ad0398e Introduce systemd-keyutil to do various key/certificate operations
Let's gather generic key/certificate operations in a new tool
systemd-keyutil instead of spreading them across various special
purpose tools.

Fixes #35087
2024-11-08 15:00:21 +01:00
Daan De Meyer 64cc7ba517 ukify: Introduce --certificate-provider= option
This translates to --certificate-source=provider:<provider> for
signing tools invoked by ukify.
2024-11-07 20:33:08 +01:00
Daan De Meyer 65fbf3b194 ukify: Add --signing-provider= option 2024-11-06 15:18:46 +01:00
Daan De Meyer d835c4476b ukify: Add support for systemd-sbsign 2024-11-06 14:01:33 +01:00
Luca Boccassi c53df275d5 test: fix tool name in comment 2024-11-04 20:27:00 +00:00
Yu Watanabe e776ab8e21 ukify: fix typo
Follow-up for 02eabaffe9.
2024-10-17 00:44:41 +09:00
Jörg Behrmann 467d21a710 ukify: Add more mypy options
This achieves parity with the mypy config used in mkosi.

The import of builtins is needed because otherwise type is attempted to be
resolved to the variable in the scope.
2024-10-14 09:59:25 +02:00
Jörg Behrmann f1b6430ecf ukify: Add UkifyConfig
Using a dataclass instead of an argparse namespace to pass around the parsed
options allows to track the types properly.
2024-10-14 09:59:25 +02:00
Jörg Behrmann 02eabaffe9 ukify: Add a unified interface for signing tools 2024-10-14 09:59:25 +02:00
Jörg Behrmann 929d6225b2 ukify: Fix type of UKI.executable 2024-10-14 09:59:25 +02:00
Jörg Behrmann 9ba53499b9 ukify: Require both key and cert be set in generate_keys
If either is None the write in this branch of the code will fail.
2024-10-12 19:01:00 +02:00
Jörg Behrmann f5698a3f41 ukify: Add missing typing for iterator 2024-10-12 19:01:00 +02:00
Jörg Behrmann e9984357ad ukify: Fix systemd-measure detection in tests
Fixes: 206fa93c85
2024-10-10 15:59:33 +02:00
Yu Watanabe 6e27477666 ukify: fix return value type of resolve_at_path()
Follow-up for eca003de2f.
2024-10-10 08:02:13 +02:00
Daan De Meyer 224aa31f4a ukify: Read .profile from path starting with @ 2024-10-09 20:36:57 +02:00
Daan De Meyer eca003de2f ukify: Introduce resolve_at_path() 2024-10-09 20:36:55 +02:00
Daan De Meyer be64d42f9f ukify: Fix off by one error
We weren't measuring the profile section itself.
2024-10-09 19:51:08 +02:00
Jörg Behrmann 180f957acc ukify: Factor out sbat into constants 2024-10-09 12:11:57 +02:00
Jörg Behrmann 206fa93c85 ukify: Ensure that find_tool always returns a tool or throws an error
This also makes the error message configurable, so that find_sbsign and
find_pesign can be inlined again.
2024-10-09 12:11:57 +02:00
Jörg Behrmann 3d2144a214 ukify: Move summary option handling out of finalize_options
This way finalize_options will not call sys.exit by itself.
2024-10-09 12:11:57 +02:00
Jörg Behrmann e95193504b ukify: Type-annotate ukify 2024-10-09 12:11:57 +02:00
Jörg Behrmann 2572afa405 ukify: Make it lint clean 2024-10-09 12:11:57 +02:00
Jörg Behrmann 521bc9c6c0 ukify: Use OSError insteead of IOError
The latter was deprecated for the former and is only an alias for it.
2024-10-09 11:58:02 +02:00
Jörg Behrmann 89842331fb ukify: Use non-deprecated import for Sequence 2024-10-09 11:58:02 +02:00
Jörg Behrmann 8abfd07ea1 ukify: Sort imports 2024-10-09 11:58:02 +02:00
Jörg Behrmann 35d92c0367 ukify: Import Path directly 2024-10-09 11:58:02 +02:00
Jörg Behrmann 6a28cae99a ukify: Format with ruff 2024-10-09 11:58:02 +02:00
Daan De Meyer 16020c3324 ukify: Rework multi-profile UKIs
The API introduced in https://github.com/systemd/systemd/pull/34295
is less than ideal:

- It doesn't consider signing at all (ukify can't sign separately yet)
- Measurement is completely broken (all profile sections are marked to
  not be measured)
- It focuses on a very niche use case of extending existing UKIs and makes
  the more common use case of building a UKI with several profiles included
  much harder than needed.

Let's instead rework the API to focus on the primary use case of building
a UKI with multiple profiles added to it immediately. We require the profiles
to be built upfront as separate PE binaries with UKI. There's no need to sign
or measure these, they're solely vehicles for profile sections. This saves us
from having to complicate the command line and config parsing to support defining
multiple profiles.

To add the profiles when building a UKI, we introduce the new --add-profile
switch which takes a path to a PE binary describing a profile. The required
sections are read from each PE binary, measured and added as a profile.

The integration test is disabled until the new API is merged and exposed in
mkosi so that building a UKI with profiles can be left to mkosi and the integration
test will only test the switching between profiles and not the building of UKIs
with profiles.
2024-10-04 11:36:25 +02:00
Daan De Meyer 4f1c5a832c ukify: Fix Profile config setting 2024-10-03 23:15:32 +02:00
Daan De Meyer db0f9720d6 ukify: Introduce pe_strip_section_name() 2024-10-03 23:15:32 +02:00
Daan De Meyer 3891d57c4f Revert "ukify: add new --extend= switch for importing an existing UKI's sections to later extend"
This reverts commit b6570095ce.
2024-10-03 23:15:32 +02:00
Daan De Meyer 71f11a8f4c Revert "ukify: introduce new --measure-base= switch"
This reverts commit bc3e2c5a57.
2024-10-03 23:15:32 +02:00
Daan De Meyer 7af304d3b6 ukify: Remove special casing for .linux section
Now that we properly leave sufficient space for inline execution of
the .linux section, let's remove the special casing of the .linux
section as it doesn't need to be the last section anymore now.
2024-09-30 16:15:16 +02:00
Daan De Meyer 2188c759f9 ukify: Use SizeOfImage from linux image as virtual size of .linux section
The SizeOfImage is bigger than the image itself so that space is
guaranteed to be available for in place execution of the linux image. Let's
make sure we take this into account and use SizeOfImage as the section's virtual
size instead of the size of the image itself.

Fixes #34578
2024-09-30 15:52:59 +02:00
Daan De Meyer 83d4c135e8 ukify: Drop unused size() method 2024-09-30 13:42:23 +02:00
Daan De Meyer 7a7f306b6c ukify: Remove debug log
This prints a python data structure which we shouldn't do during
normal operation.
2024-09-17 22:34:13 +02:00
Lennart Poettering bc3e2c5a57 ukify: introduce new --measure-base= switch 2024-09-06 16:12:03 +02:00
Lennart Poettering b6570095ce ukify: add new --extend= switch for importing an existing UKI's sections to later extend
This options is pretty simple, it allows specifying an UKI whose
sections to import first, and place at the beginning of the new UKI.

This is useful for generating multi-profile UKIs piecemeal: generate the
base UKI first, then append a profile, and another one and another one.

The sections imported this way are not included in any PCR signature,
the assumption is that that already happened before in the imported UKI.
2024-09-06 16:12:03 +02:00