Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_signature + SignatureCriterion interface #1452

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

castedo
Copy link
Contributor

@castedo castedo commented Nov 22, 2024

  • check_signature method for Commit/Tag as alternative to verify
  • SignatureCriterion interface to decouple crypto from git serialization
  • single simple InvalidSignature exception generic to whatever criterion
  • DRY re-impl for Commit/Tag verify using GpgSignatureCriterion

@castedo
Copy link
Contributor Author

castedo commented Nov 22, 2024

@jelmer Here is a potential start to a very new direction that can have lots of variations. Take your time to consider. I'm not in a rush to merge this.

This, or something similar to it, I wager will resolve future headaches and confusion and give dev-users flexibility to make a variety of trade-offs depending on what kind of signature criterion and implementation makes sense for their particular application.

Although verify_time is not used by git+gpg verification (I think) it is a full ssh-keygen feature and cgit passes a verify time to ssh-keygen.

This PR is attached to the "pr/decouple_sig_check" branch which I will squash and rebase. If you want to fork and modify off the code in this PR, do it from the "decouple_sig_check" feature branch which I will not squash and rebase and will maintain full git history for short-term feature tracking and merging.

I am using castedo/git-prepr.

@castedo
Copy link
Contributor Author

castedo commented Nov 22, 2024

This direction probably enables a fairly easy and low-risk resolution to #1369. The solution can be "implement your own subclass of SignatureCriterion, similar to GpgSignatureCriterion, but using python-gnupg", and call check_signature instead of verify.

@castedo
Copy link
Contributor Author

castedo commented Nov 22, 2024

@jelmer And feel free to ask questions and suggest alternatives. In this branch I'm adopting and not adopting some Python approaches that are pretty new to me. Like is abc.ABC worth using? Single simple Exceptions rather than a plethora of fine-grained exceptions? I dunno. I've been tending towards whatever is simpler and more minimal.

@castedo
Copy link
Contributor Author

castedo commented Nov 22, 2024

FYI, I am going to port the example code in #1448 to a SignatureCriterion subclass that I'll save in dulwich/dulwich/contrib on this branch (or a separate feature branch if you prefer).

@castedo castedo force-pushed the pr/decouple_sig_check branch 3 times, most recently from 88b0047 to 6676615 Compare November 22, 2024 19:05
* check_signature method for Commit/Tag as alternative to verify
* SignatureCriterion interface to decouple crypto from git serialization
* single simple InvalidSignature exception generic to whatever criterion
* DRY re-impl for Commit/Tag verify using GpgSignatureCriterion
* ssh-keygen based SignatureCriterion classes in contrib
@castedo
Copy link
Contributor Author

castedo commented Nov 22, 2024

And then here's an example of two pure-python criteria using sshsiglib:

https://gitlab.com/perm.pub/sshsiglib/-/blob/a0d551ecd5469ba3ec9c97b261ac8c2c6a152565/contrib/sshsig_criterion.py

One criterion, SshsigCheckCriterion, does not use any allowed signers file at all.
The other criterion, SshsigVerifyCriterion, uses the Hidos DSGL just-a-list-for-git sub-format (#1449).

# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
# License, Version 2.0.
# fmt: off
Copy link
Owner

Choose a reason for hiding this comment

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

why turn off fmt?

@@ -1531,6 +1534,10 @@ def raw_without_sig(self) -> bytes:
tmp.gpgsig = None
return tmp.as_raw_string()

def check_signature(self, criterion: SignatureCriterion) -> None:
if self.gpgsig:
Copy link
Owner

Choose a reason for hiding this comment

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

This seems like a bit of an odd interface; the commit stores whether the signature is PGP or SSH, so why does the caller need to care?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants