Skip to content

Replace custom OpenPGP packet parsing with pysequoia #7433

Draft
dralley wants to merge 4 commits intopulp:mainfrom
dralley:use-pysequoia
Draft

Replace custom OpenPGP packet parsing with pysequoia #7433
dralley wants to merge 4 commits intopulp:mainfrom
dralley:use-pysequoia

Conversation

@dralley
Copy link
Contributor

@dralley dralley commented Mar 9, 2026

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

See: Pull Request Walkthrough

@dralley
Copy link
Contributor Author

dralley commented Mar 9, 2026

@mdellweg @gerrod3 This is first draft quality, I have not thoroughly reviewed this. But let me know what you think, and feel free to look at the pysequoia PR as well.

I will note, that I don't think pysequoia actually supports PQC yet (the patches exist but aren't merged yet, I think RH is applying them downstream in places). So we will need to make sure that it's not doing "too much" validation

Requires wiktor-k/pysequoia#61

@dralley dralley force-pushed the use-pysequoia branch 4 times, most recently from a4007d3 to ccf9278 Compare March 10, 2026 01:36
@dralley dralley changed the title Use pysequoia Replace custom OpenPGP packet parsing with pysequoia Mar 10, 2026
username (str): Empty string; primary UID not available without extending pysequoia.
data (bytes or None): The verified plaintext content for inline signatures, None for
detached signatures.
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not actually sure that we need this, but gpg_verify is public API, so I figured we would have to at least try. Unless we wait until the next breaking change release.

pyproject.toml Outdated
"psycopg[binary]>=3.1.8,<3.4", # SemVer, not explicitely stated, but mentioned on multiple changes.
"pyparsing>=3.1.0,<3.4", # Looks like only bugfixes in z-Stream.
"python-gnupg>=0.5.0,<0.6", # Looks like only bugfixes in z-Stream [changelog only in git]
"pysequoia @ git+https://github.com/wiktor-k/pysequoia.git@refs/pull/61/head",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neat

if "~=" in ops:
warnings.warn(f"{filename}:{nr}: Please avoid using ~= on {req.name}!")
elif "<" not in ops and "<=" not in ops and "==" not in ops:
elif "<" not in ops and "<=" not in ops and "==" not in ops and "@" not in line:
Copy link
Member

Choose a reason for hiding this comment

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

Well this check was actually intentional:
The check-commit wf fails until all the dependencies are in order again.
It should still allow the tests to run. But obviously prevent prematurely merging it.

Copy link
Contributor Author

@dralley dralley Mar 10, 2026

Choose a reason for hiding this comment

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

It wasn't reaching the tests IIRC

Copy link
Member

Choose a reason for hiding this comment

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

OIC this check is in the wrong place. It should be next to "check commit messages".

Copy link
Member

Choose a reason for hiding this comment

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

I think we even document that you can do this...

Copy link
Member

@mdellweg mdellweg left a comment

Choose a reason for hiding this comment

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

Nice work.

"raw_data": body,
"created": packet.signature_created,
}
# Note: Pulp's concept of "expiration time" is a duration starting at creation time
Copy link
Member

Choose a reason for hiding this comment

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

Oh it should have been expiration date?
"time" really is ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBF, pulp is using the terminology that was defined in the spec, so it was "correct", it's just that the terminology in the spec was ambiguous.

https://www.rfc-editor.org/rfc/rfc9580.html#name-signature-expiration-time

Opinions probably differ whether Sequoia providing expiration_time as something else is a good idea. Less ambiguous wording, but a bit confusing when it comes to the spec.

if isinstance(signature, str):
sig_data = stack.enter_context(open(signature, "rb")).read()
elif isinstance(signature, models.Artifact):
sig_data = stack.enter_context(signature.file).read()
Copy link
Member

Choose a reason for hiding this comment

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

Admittedly, again, this is not new. But do you think we can feed this as a stream into pysequoia?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By stream do you mean read the data lazily? e.g. just passing the file handle, not a bytes buffer?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's what i thought.
Specifically if it's an attached signature the file may be huge.

Copy link
Contributor Author

@dralley dralley Mar 10, 2026

Choose a reason for hiding this comment

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

Probably https://docs.python.org/3/c-api/buffer.html

Actually, no, at least not as easily as I would hope

Why are attached signatures large? You would extract the signature for checking, surely?

Copy link
Member

Choose a reason for hiding this comment

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

In case detached_data=None we assume that signature contains the actual data (possible multiple GB) and the attached signature. And re just slurp that into memory with read.
But again, not necessarily the scope of this pr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I suppose that is a problem with the existing implementation as well. Do we have an issue filed for that?

"pyparsing>=3.1.0,<3.4", # Looks like only bugfixes in z-Stream.
"python-gnupg>=0.5.0,<0.6", # Looks like only bugfixes in z-Stream [changelog only in git]
"pysequoia @ git+https://github.com/wiktor-k/pysequoia.git@refs/pull/61/head",
# "pysequoia>=0.1.32",
Copy link
Member

Choose a reason for hiding this comment

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

Are we now ready to drop the gpg dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so, I think the remaining usage was just in tests, but it's something I would double check before marking the PR ready

Copy link
Member

Choose a reason for hiding this comment

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

So moving it to the test_requirements wouldn't even tell us we really don't use it in the application... That is sad.

Copy link
Contributor Author

@dralley dralley Mar 10, 2026

Choose a reason for hiding this comment

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

The add-signing-service management command also exports keys from the system keyring using python-gnupg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not entirely sure how we will get rid of that one, tbh.

@dralley dralley force-pushed the use-pysequoia branch 2 times, most recently from b75892e to 56bd4a3 Compare March 11, 2026 15:09
dralley added 4 commits March 11, 2026 11:10
Use pysequoia instead

Generated-By: claude-opus-4.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants