Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functest_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest<10
pytest-custom_exit_code
pytest-xdist
python-gnupg
pysequoia
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we even repeating the dependency here? (It's not optional in pyproject, right?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functional tests can run outside the environment where Pulp is installed.

proxy.py~=2.4.10
trustme~=1.2.1

Expand Down
35 changes: 27 additions & 8 deletions pulpcore/app/management/commands/add-signing-service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

import gnupg
import subprocess

from pathlib import Path

Expand Down Expand Up @@ -72,13 +71,33 @@ def handle(self, *args, **options):
)
)

gpg = gnupg.GPG(gnupghome=options["gnupghome"], keyring=options["keyring"])
gpg_cmd = ["gpg"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we need this to use sequoia too in order to handle all the new algorithms and keyfile formats?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even sequoia doesn't "support" them yet because the IETF draft isn't final yet. You have to install a special build to get them. So it's out of scope for now. At some point, probably, but even then it might be a host-dependent thing.

if options["gnupghome"]:
gpg_cmd += ["--homedir", options["gnupghome"]]
if options["keyring"]:
gpg_cmd += ["--keyring", options["keyring"]]

key_list = gpg.list_keys(keys=[key_id])
if not len(key_list) == 1:
raise CommandError(_("There are {} keys matching the key id.").format(len(key_list)))
fingerprint = key_list[0]["fingerprint"]
public_key = gpg.export_keys(key_id)
result = subprocess.run(
gpg_cmd + ["--with-colons", "--fingerprint", key_id],
capture_output=True,
text=True,
)
if result.returncode != 0:
raise CommandError(result.stderr.strip())

fpr_lines = [line for line in result.stdout.splitlines() if line.startswith("fpr:")]
if len(fpr_lines) != 1:
raise CommandError(_("There are {} keys matching the key id.").format(len(fpr_lines)))
fingerprint = fpr_lines[0].split(":")[9]

result = subprocess.run(
gpg_cmd + ["--armor", "--export", key_id],
capture_output=True,
text=True,
)
if result.returncode != 0:
raise CommandError(result.stderr.strip())
public_key = result.stdout

try:
script_path = Path(script).resolve(strict=True)
Expand Down
16 changes: 9 additions & 7 deletions pulpcore/app/models/openpgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from aiohttp.web_response import Response
from django.db import models
from django.utils import timezone
from pysequoia import armor, ArmorKind

from pulpcore.app.models import AutoAddObjPermsMixin, Content, Distribution, Repository
from pulpcore.app.openpgp import wrap_armor
from pulpcore.app.util import get_domain_pk, gpg_verify


Expand Down Expand Up @@ -47,6 +48,7 @@ def represent(self, repository_version=None):
else:
content_filter = {}
data = self.packet()
# note: because these queries aren't ordered, the result may be nondetermininistic
for signature in self.openpgp_signatures.filter(**content_filter):
data += signature.packet()
for user_id in self.user_ids.filter(**content_filter):
Expand All @@ -61,7 +63,7 @@ def represent(self, repository_version=None):
data += public_subkey.packet()
for signature in public_subkey.openpgp_signatures.filter(**content_filter):
data += signature.packet()
return wrap_armor(data)
return armor(data, ArmorKind.PublicKey).strip() # avoid trailing newline

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
Expand Down Expand Up @@ -127,11 +129,11 @@ class OpenPGPSignature(_OpenPGPContent):

sha256 = models.CharField(max_length=128)
signature_type = models.PositiveSmallIntegerField()
created = models.DateTimeField() # 2
expiration_time = models.DurationField(null=True) # 3
key_expiration_time = models.DurationField(null=True) # 9
issuer = models.CharField(max_length=16, null=True) # 16
signers_user_id = models.CharField(null=True) # 28
created = models.DateTimeField()
expiration_time = models.DurationField(null=True)
key_expiration_time = models.DurationField(null=True)
issuer = models.CharField(max_length=16, null=True)
signers_user_id = models.CharField(null=True)
signed_content = models.ForeignKey(
Content, related_name="openpgp_signatures", on_delete=models.PROTECT
)
Expand Down
Loading
Loading