Commit Graph
100 Commits
Author SHA1 Message Date
Yu Watanabe d19434fbf8 tree-wide: fix typo 2023-10-31 14:35:33 +09:00
Luca Boccassi 6cd1f6546c Merge pull request #29332 from esposem/ukify_simplify
ukify: automatically infer --signtool from the parameters given
2023-10-27 00:10:28 +01:00
Zbigniew Jędrzejewski-Szmek e3696e6f63 ukify: fix .dtb section name in 'inspect'
Fixup for df4a46733a.
2023-10-11 17:34:43 +02:00
Emanuele Giuseppe Esposito 1277575408 ukify: override default option value with config file
If an option like SecureBootCertificateDir is given, it should override
the default '/etc/pki/pesign'. Until now the config file option were
always ignored if they had a default.

So from now on, every ConfigItem with a config_key and default field
should also give config_push = ConfigItem.config_set.
2023-10-10 07:06:24 -04:00
Emanuele Giuseppe Esposito 5c52078162 ukify: automatically infer --signtool from the parameters given
--signtool is actually useless: it can be inferred depending on if
--secureboot-certificate-name (pesign) is given, or
--secureboot-private-key and --secureboot-certificate (sbsign) is given.

Leave the option just for backwards compatibility.
2023-10-10 07:06:23 -04:00
Valentin Lefebvre 750674da0d ukify: explicitly import attribute
* Explicitly import attributes rsa and serialization from cryptography.hazmat

Signed-off-by: Valentin Lefebvre <valentin.lefebvre@suse.com>
2023-09-29 11:31:12 +02:00
Joerg Behrmann 7c52d5236a treewide: split commandline into command line 2023-09-20 16:37:23 +01:00
Alvin Alvarado a05fa30f88 ukify/man: Look for a config file in systemd folders if not specified
If the user does not specify a config file to use, ukify will try looking for one at {/run,/etc,/usr/local/lib,/usr/lib}/systemd/ukify.conf in order and then use the first one found. Also made sure the --config input is a pathlib.Path by specifying its type in its CONFIG_ITEMS entry.
Big cheers to Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> for helping!
2023-09-08 16:21:28 +02:00
Zbigniew Jędrzejewski-Szmek 594e27b0bc ukify: fail if the config file was not read
Inspired by https://github.com/systemd/systemd/pull/28997.
Noticed by Alvin Alvarado <alvin@striczkof.io>.
2023-08-29 15:16:35 +03:00
Daan De Meyer c1e704626a ukify: Use length= instead of ignore_padding= in inspect
ignore_padding= was only added in a recent version of pefile. Let's
set length= to the virtual size instead which is what ignore_padding
does behind the scenes so we're compatible with older versions of
pefile.
2023-08-10 19:35:21 +01:00
Luca Boccassi bd95029c3e Merge pull request #28743 from mrc0mmand/lint-python-scripts
tools: lint Python scripts
2023-08-10 19:13:45 +01:00
Frantisek Sumsal 79f902eb09 Add .pylintrc to globally suppress warnings we don't really care about
Also, drop the respective disable directives from existing files.
2023-08-10 18:13:29 +02:00
Zbigniew Jędrzejewski-Szmek 4d8c16b166 test: use pytest.raises wrapper
This way we check that the appropriate exception is raised,
not just ignore it.

Follow-up for e3c04a5c84.
2023-08-09 13:56:07 +02:00
Frantisek Sumsal 0be1de7ffc ukify: don't panic when prepending to an undefined list
Handle the case when all the arguments are passed in through a
configuration file:

$ cat ukify.conf
[UKI]
Linux = /boot/vmlinuz-linux
Initrd = /boot/initramfs-linux.img

Before:
$ src/ukify/ukify.py --config ukify.conf build
Traceback (most recent call last):
  File "/root/systemd/src/ukify/ukify.py", line 1604, in <module>
    main()
  File "/root/systemd/src/ukify/ukify.py", line 1590, in main
    opts = parse_args()
           ^^^^^^^^^^^^
  File "/root/systemd/src/ukify/ukify.py", line 1584, in parse_args
    apply_config(opts)
  File "/root/systemd/src/ukify/ukify.py", line 1431, in apply_config
    item.apply_config(namespace, section_name, group, key, value)
  File "/root/systemd/src/ukify/ukify.py", line 1123, in apply_config
    self.config_push(namespace, group, dest, value)
  File "/root/systemd/src/ukify/ukify.py", line 1019, in config_list_prepend
    setattr(namespace, dest, value + old)
                             ~~~~~~^~~~~
TypeError: can only concatenate list (not "NoneType") to list

After:
$ src/ukify/ukify.py --config ukify.conf build
Kernel version not specified, starting autodetection 😖.
Found uname version: 6.4.7-arch1-3
Wrote unsigned vmlinuz-linux.unsigned.efi

Resolves: #28688
2023-08-05 22:38:46 +01:00
Yu Watanabe dc4a00555a meson: set suite for all tests, and adjust suite for some tests 2023-08-03 20:37:16 +09:00
Daan De Meyer d713104abe ukify: Only run systemd-measure after adding all sections
We were running systemd-measure before adding the sbat section,
let's fix that.

Also make sure we only pass --linux to systemd-measure once instead
of twice.
2023-08-01 21:11:15 +01:00
Yu Watanabe e3c04a5c84 test-ukify: add tests for an empty argument 2023-07-29 19:57:35 +09:00
Yu Watanabe f0876c7ab9 ukify: check option length
Follow-up for df4a46733a.
2023-07-29 18:48:32 +09:00
Luca Boccassi 1a1a691ba7 Merge pull request #27621 from esposem/ukify_read
ukify: add an option to read the PE sections
2023-07-28 09:55:03 +01:00
Luca Boccassi 5a945fab7a ukify: fix armv7 architecture mapping
$ uname -m
armv7l

Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/obj-arm-linux-gnueabihf/src/kernel-install/60-ukify.install", line 223, in <module>
    main()
  File "/<<PKGBUILDDIR>>/obj-arm-linux-gnueabihf/src/kernel-install/60-ukify.install", line 219, in main
    call_ukify(opts)
  File "/<<PKGBUILDDIR>>/obj-arm-linux-gnueabihf/src/kernel-install/60-ukify.install", line 205, in call_ukify
    ukify['finalize_options'](opts2)
  File "/<<PKGBUILDDIR>>/obj-arm-linux-gnueabihf/ukify", line 1423, in finalize_options
    opts.efi_arch = guess_efi_arch()
                    ^^^^^^^^^^^^^^^^
  File "/<<PKGBUILDDIR>>/obj-arm-linux-gnueabihf/ukify", line 78, in guess_efi_arch
    raise ValueError(f'Unsupported architecture {arch}')
ValueError: Unsupported architecture armv7l
2023-07-24 21:10:48 +02:00
Yu Watanabe dc8b82a5b4 test-ukify: use systemd-measure and bootctl in build directory
And skip tests if systemd-measure is not found.
Then, we can safely run test_ukify.py directly.
2023-07-21 15:32:02 +02:00
Yu Watanabe 4fc925a026 test: fix a syntax error in test-ukify
Follow-up for d7d36252e5.

Fixes #28464.
2023-07-20 09:55:32 +02:00
Emanuele Giuseppe EspositoandZbigniew Jędrzejewski-Szmek 805d41e279 ukify/test_ukify: test display verb
Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2023-07-15 19:41:51 +02:00
Emanuele Giuseppe EspositoandZbigniew Jędrzejewski-Szmek df4a46733a ukify: add a verb to inspect the PE sections
Since PE can't be read with a normal editor, provide functionality to read PE
sections and output their name and when possible the content too.

ukify inspect <file> describes the sections and print the content of the
well-known sections to stdout.

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2023-07-15 19:41:51 +02:00
Daan De Meyer d7d36252e5 ukify: Derive public key from private key if not specified 2023-07-13 16:31:05 +01:00
Emanuele Giuseppe Esposito b708789dc4 ukify: refactor signing code
When ukify is not signing, it should not check if sbsign/pesign are
installed, nor print if they are missing or not.
2023-07-10 02:41:37 -04:00
Luca Boccassi 635c6ea622 ukify: measure sbat section too 2023-07-05 21:31:08 +01:00
Luca Boccassi a8b645dec8 ukify: enable --sbat for UKIs too
For confidential computing they want to be able to revoke initrds too, so allow
passing a specific --sbat section when building a UKI too, not just an addon.
Merge it with the stub and kernel sections.
2023-07-05 21:31:08 +01:00
Luca Boccassi c3f7501c4d ukify: merge .sbat sections from stub and kernel
If the kernel contains a .sbat section (they should start soon) then merge
it with the stub's so that revocations can apply to either component.

Fixes https://github.com/systemd/systemd/issues/27866
2023-06-30 17:17:56 +01:00
Frantisek Sumsal 9a27ef092e tree-wide: fix a couple of typos
As reported by Fossies.org.
2023-06-15 20:52:45 +02:00
Zbigniew Jędrzejewski-Szmek 814e4d7a67 ukify: make the certficate validity configurable
Requested in https://github.com/systemd/systemd/pull/27946/commits/4cc743319ae378d458050d6e0cfdeaa03addd379#r1228592001
2023-06-14 13:18:00 +02:00
Zbigniew Jędrzejewski-Szmek 13a29b0efb test_ukify: skip test requiring cryptography
I'll add the dep in Fedora spec so it does get tested at least
in some cases.
2023-06-14 13:18:00 +02:00
Zbigniew Jędrzejewski-Szmek ff7580e280 test_ukify: cleanups suggested by pylint 2023-06-14 13:18:00 +02:00
Zbigniew Jędrzejewski-Szmek a1c80efddc ukify: add 'genkey' verb
The idea is to make it easy to generate all the signing key and certs
that can be used for local signing. The verb is the modeled after
'mkosi genkey', but there are some important differences: we generate
the keys to the paths where they will be read from, both pcr signing
keys and the SecureBoot certificate+key.

If any of the outputs exist, operation is refused. Maybe we could add a
--force option in the future, but this operation should be rare, so I think
it's better to refuse to overwrite anything initially.

I'm only doing a token man page change here.
https://github.com/systemd/systemd/pull/27621 reworks the man page,
and the changes done here would conflict heavily with that work. I'll
submit a follow-up patch later.
2023-06-14 13:17:33 +02:00
Zbigniew Jędrzejewski-Szmek b09a5315f5 ukify: move verb mangling to finalize_options()
This simplifies the logic: finalize_options() is the step that does the
checks and the mangling. The checks for consistency are done in more places,
so we need to pass a verb (we only have 'build', but once we add other verbs,
any would do).
2023-06-12 11:12:02 +02:00
Zbigniew Jędrzejewski-Szmek 9a1cb2038e ukify: split out iteration over phase path groups and keys
In preparation for future changes.
2023-06-12 11:12:02 +02:00
Zbigniew Jędrzejewski-Szmek 24f4ff8a09 man,test: root or hardware is not needed for ukify 2023-06-12 11:12:02 +02:00
Zbigniew Jędrzejewski-Szmek 794385f5df ukify: fix synopsis in --help
Missed in a3b227d28a.
2023-06-12 11:12:02 +02:00
Zbigniew Jędrzejewski-Szmek 6fa7913830 ukify: use pager for --help
The output is now too long to fit on one page, let's use a pager automatically
like in other places.

The implementation is copied from mkosi, but adjusted to follow what other
systemd tools do.
2023-06-12 11:12:02 +02:00
Zbigniew Jędrzejewski-Szmek a3b227d28a ukify: add 'build' verb
The old syntax with linux + initrds as positional arguments is still accepted,
but a warning is emitted. We should remove the support for this after the
next release or so.

Adding a single verb by itself is not very useful, but opens the door to adding
other verbs.
2023-06-06 15:45:57 +02:00
Zbigniew Jędrzejewski-Szmek 320266b961 test_ukify: pass through path to addon stub
Without this, the tests would generally be skipped, since we haven't made a
release with the addon stub yet. But even if the file is there, we always want
to test the freshly-built item.
2023-06-06 15:45:57 +02:00
Zbigniew Jędrzejewski-Szmek 0d66468243 test_ukify: no stinky root needed for signing
C.f. b2efe28658.
2023-06-06 15:41:04 +02:00
Zbigniew Jędrzejewski-Szmek 1df35a4638 ukify: simplify creation of parser
00e5933f57 made all the positional arguments
optional, so let's take advantage of this to simplify variuos callers.
2023-06-06 15:41:01 +02:00
Zbigniew Jędrzejewski-Szmek c4fc25463e ukify: make code pylint clean
The linter is imperfect, but it is useful as a very quick
check for typos and other silly mistakes. Add a few annotations
and do one small change to make it think the code is perfect.
2023-06-05 16:07:52 +02:00
Lennart Poettering be2e63159f Merge pull request #27358 from bluca/pe_mule
stub: allow loading and verifying kernel command line addons
2023-05-25 03:56:06 -07:00
Malte PollandOtto Bittner 8d89d66ce8 ukify: fix handling signed kernel as file
The .linux section would contain the path to the signed kernel (instead of the signed kernel itself), since the python type of the variable is used to determine how it is handled when adding the pe sections.

Co-authored-by: Otto Bittner <cobittner@posteo.net>
2023-05-24 18:07:51 +01:00
Luca Boccassi c67d5a027d ukify: add default .sbat section for addons
In order to ensure addons can always be revoked via SBAT, and it is not
left out by mistake, have a default metadata entry if none is specified
by the caller.
https://github.com/rhboot/shim/blob/main/SBAT.md
2023-05-24 11:09:03 +01:00
Luca Boccassi f644ea3ed7 ukify: use empty stub for addons
Instead of picking up sd-stub, which is runnable, add an empty
addon stub that just returns an error if executed
2023-05-24 11:09:03 +01:00
Luca Boccassi b6f2e68602 stub/measure: document and measure .uname UKI section 2023-05-24 11:06:36 +01:00
Luca Boccassi fcb4ba6c14 Merge pull request #27539 from esposem/ukify_pesign
ukify: support pesign as alternative to sbsign
2023-05-11 10:45:59 +01:00