forked from systemd/mkosi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying OpenPGP implementation to use for signing
Fixes: systemd#3042
- Loading branch information
Showing
14 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ Packages= | |
python | ||
qemu-user-static | ||
shim | ||
sequoia-sop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ Repositories=non-free-firmware | |
[Content] | ||
Packages= | ||
linux-perf | ||
sqop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ Packages= | |
perf | ||
qemu-user-static | ||
rpmautospec | ||
sequoia-sop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ Repositories=universe | |
[Content] | ||
Packages= | ||
linux-tools-generic | ||
sqop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ Packages= | |
python3 | ||
qemu-user-static | ||
shim-signed | ||
sqop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,5 @@ Packages= | |
util-linux | ||
xfsprogs | ||
zstd | ||
sequoia-sop | ||
SELinuxRelabel=no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ Packages= | |
qemu-base | ||
reprepro | ||
sbsigntools | ||
sequoia-sop | ||
shadow | ||
squashfs-tools | ||
systemd-ukify | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ Packages= | |
qemu-system | ||
reprepro | ||
sbsigntool | ||
sqop | ||
squashfs-tools | ||
swtpm-tools | ||
systemd-container | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ Packages= | |
qemu-system-ppc-core | ||
qemu-system-s390x-core | ||
reprepro | ||
sequoia-sop | ||
ubu-keyring | ||
zypper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
|
||
import tempfile | ||
from collections.abc import Mapping | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from mkosi.run import find_binary, run | ||
|
||
from . import Image, ImageConfig | ||
|
||
pytestmark = pytest.mark.integration | ||
|
||
|
||
def test_signing_checksums_with_sop(config: ImageConfig) -> None: | ||
assert config.tools is not None, "Needs config.tools to check for SOP implementation" | ||
if find_binary("sqop", config.tools) is None: | ||
print("Needs `sqop` binary in PATH to perform sop tests.") | ||
return | ||
with tempfile.TemporaryDirectory() as path: | ||
tmp_path = Path(path) | ||
tmp_path.chmod(0o755) | ||
|
||
signing_key = tmp_path / "signing-key.pgp" | ||
signing_cert = tmp_path / "signing-cert.pgp" | ||
|
||
# create a brand new signing key | ||
with open(signing_key, "wb") as o: | ||
run(cmdline=["sqop", "generate-key", "--signing-only", "Test"], stdout=o) | ||
|
||
signing_key.chmod(0o755) | ||
|
||
# extract public key (certificate) | ||
with open(signing_key, "rb") as i, open(signing_cert, "wb") as o: | ||
run(cmdline=["sqop", "extract-cert"], stdin=i, stdout=o) | ||
|
||
signing_cert.chmod(0o755) | ||
|
||
with Image(config) as image: | ||
image.build( | ||
options=["--checksum=true", "--openpgp-tool=sqop", "--sign=true", f"--key={signing_key}"] | ||
) | ||
|
||
signed_file = image.output_dir / "image.SHA256SUMS" | ||
signature = image.output_dir / "image.SHA256SUMS.gpg" | ||
|
||
with open(signed_file, "rb") as i: | ||
run(cmdline=["sqop", "verify", signature, signing_cert], stdin=i) | ||
|
||
|
||
def test_signing_checksums_with_gpg(config: ImageConfig) -> None: | ||
with tempfile.TemporaryDirectory() as path: | ||
tmp_path = Path(path) | ||
tmp_path.chmod(0o777) | ||
|
||
signing_key = "mkosi-test@example.org" | ||
signing_cert = tmp_path / "signing-cert.pgp" | ||
gnupghome = tmp_path / ".gnupg" | ||
|
||
env: Mapping[str, str] = dict(GNUPGHOME=str(gnupghome)) | ||
|
||
# Creating GNUPGHOME directory and appending an *empty* common.conf | ||
# file stops GnuPG from spawning keyboxd which causes issues when switching | ||
# users. See https://stackoverflow.com/a/72278246 for details | ||
gnupghome.mkdir() | ||
(gnupghome / "common.conf").touch() | ||
|
||
# create a brand new signing key | ||
run(cmdline=["gpg", "--quick-gen-key", "--batch", "--passphrase", "", signing_key], env=env) | ||
|
||
# GnuPG will set 0o700 permissions so that the secret files are not available | ||
# to other users. Since this is for tests only and we need that keyring for signing | ||
# enable all permissions. We need write permissions since GnuPG creates temporary | ||
# files in this directory during operation. | ||
gnupghome.chmod(0o777) | ||
for p in gnupghome.rglob("*"): | ||
p.chmod(0o777) | ||
|
||
# export public key (certificate) | ||
with open(signing_cert, "wb") as o: | ||
run(cmdline=["gpg", "--export", signing_key], env=env, stdout=o) | ||
|
||
signing_cert.chmod(0o755) | ||
|
||
with open("/tmp/list", "wb") as o: | ||
run(["ls", "-la", gnupghome], stdout=o) | ||
|
||
with Image(config) as image: | ||
image.build(options=["--checksum=true", "--sign=true", f"--key={signing_key}"], env=env) | ||
|
||
signed_file = image.output_dir / "image.SHA256SUMS" | ||
signature = image.output_dir / "image.SHA256SUMS.gpg" | ||
|
||
with open(signed_file, "rb") as i: | ||
run(cmdline=["sqop", "verify", signature, signing_cert], stdin=i) |