-
Notifications
You must be signed in to change notification settings - Fork 315
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: #3042
- Loading branch information
Showing
6 changed files
with
144 additions
and
33 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
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
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,72 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import contextlib | ||
import os | ||
import subprocess | ||
import tempfile | ||
import textwrap | ||
from collections.abc import Iterator | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from mkosi.distributions import Distribution | ||
from mkosi.run import run | ||
from mkosi.sandbox import umask | ||
from mkosi.tree import copy_tree | ||
from mkosi.types import PathString | ||
|
||
from . import Image, ImageConfig | ||
|
||
pytestmark = pytest.mark.integration | ||
|
||
def test_signing_checksums_with_sop(config: ImageConfig, tmp_path) -> None: | ||
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) | ||
|
||
# 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) | ||
|
||
with Image(config) as image: | ||
image.build(options=["--checksum=true", "--openpgp-tool=rsop", "--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, tmp_path) -> None: | ||
signing_key = "[email protected]" | ||
signing_cert = tmp_path / "signing-cert.pgp" | ||
|
||
env = dict(GNUPGHOME=tmp_path / ".gnupg") | ||
|
||
# create a brand new signing key | ||
run(cmdline = ["gpg", "--quick-gen-key", "--batch", "--passphrase", "", signing_key], env = env) | ||
|
||
# export public key (certificate) | ||
with open(signing_cert, "wb") as o: | ||
run(cmdline = ["gpg", "--export", signing_key], | ||
env = env, | ||
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) |