git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fast-(import|export): improve on the signature algorithm name

From
Christian Couder <christian.couder@gmail.com>
Date
May 26, 2025, 10:34 UTC
Message-ID
<CAP8UFD2+h6hthbHQP_hmd5xXXCwizvSOd5tgGDHJ=V_eW1sgsw@mail.gmail.com>
In-Reply-To
<CABPp-BFrau4F1a_+umYw0qu8HYz3dTPXZ9oiHhawTSZpgAoGLw@mail.gmail.com>
On Thu, Apr 24, 2025 at 11:41 PM Elijah Newren <newren@gmail.com> wrote:
Show 30 quoted lines
>
> On Thu, Apr 24, 2025 at 1:39 PM Christian Couder
> <christian.couder@gmail.com> wrote:
> >
> > A recent commit, d9cb0e6ff8 (fast-export, fast-import: add support for
> > signed-commits, 2025-03-10), added support for signed commits.
> >
> > However, when processing signatures `git fast-export` outputs "gpgsig
> > sha1" not just when it encounters an OpenPGP SHA-1 signature, but also
> > when it encounters an SSH or X.509 signature. This is not very
> > informative to say the least, and this might prevent tools that process
> > the output from easily and properly handling signatures.
> >
> > Let's improve on that by reusing the existing code from
> > "gpg-interface.{c,h}" to detect the signature algorithm, and then put
> > the signature algorithm name (like "openpgp", "x509" or "ssh") instead
> > of "sha1" in the output. If we can't detect the signature algorithm we
> > will use "unknown". It might be a signature added by an external tool
> > and we should likely keep it.
> >
> > Similarly on the `git fast-import` side, let's use the existing code
> > from "gpg-interface.{c,h}" to check if a signature algorithm name is
> > valid. In case of an "unknown" signature algorithm name, we will warn
> > but still keep it. Future work might implement several options to let
> > users deal with it in different ways, and might implement checking
> > known signatures too.
>
> The last sentence is somewhat ambiguous about whether it is only about
> the "unknown" case or whether the second half of the sentence was
> switching tracks to discuss something else about the known cases.

Yeah, the second half of the sentence was about switching tracks to discuss other things we might do in the future.

Show 6 quoted lines
> Do
> you perhaps mean something like "Future work might implement several
> options to let users deal with an "unknown" signature algorithm, and
> when we have a valid signature algorithm, we may be able to not only
> verify the signature algorithm name but start verifying the signature
> itself to ensure it is valid as well."  ?
Yeah, that was the idea. Thanks for spelling it in a better way than I did.

In v2, I have actually tried an approach based on verifying signatures, and I'd be happy to know your opinion about the different approaches.

Thanks!
[...]
> > +Signatures are not yet checked in the current implementation though.
>
> Thanks for calling this out.
[...]
Show 27 quoted lines
> > @@ -2830,12 +2831,15 @@ static void parse_new_commit(const char *arg)
> >                         "encoding %s\n",
> >                         encoding);
> >         if (sig_alg) {
> > -               if (!strcmp(sig_alg, "sha1"))
> > -                       strbuf_addstr(&new_data, "gpgsig ");
> > -               else if (!strcmp(sig_alg, "sha256"))
> > +               if (!strcmp(sig_alg, "sha256"))
> >                         strbuf_addstr(&new_data, "gpgsig-sha256 ");
> > -               else
> > -                       die("Expected gpgsig algorithm sha1 or sha256, got %s", sig_alg);
> > +               else if (valid_signature_name(sig_alg))
> > +                       strbuf_addstr(&new_data, "gpgsig ");
> > +               else if (!strcmp(sig_alg, "unknown")) {
> > +                       warning("Unknown gpgsig algorithm name!");
> > +                       strbuf_addstr(&new_data, "gpgsig ");
> > +               } else
> > +                       die("Invalid gpgsig algorithm name, got '%s'", sig_alg);
> >                 string_list_split_in_place(&siglines, sig.buf, "\n", -1);
> >                 strbuf_add_separated_string_list(&new_data, "\n ", &siglines);
> >                 strbuf_addch(&new_data, '\n');
>
> I'm not very familiar with gpg and other signatures, and was stuck
> trying to parse this logic when a review from Junio came in, and I
> decided to read it since he often "thinks out loud" to see if that'd
> explain it better.  Sadly, didn't help... ;-)  But I'll watch for any
> follow-up response you add over there.

Yeah, if we want to continue in the direction of this patch, let's discuss it over there.

Show 37 quoted lines
> > @@ -381,6 +381,62 @@ test_expect_success GPG 'signed-commits=warn-strip' '
> >
> >  '
> >
> > +test_expect_success GPGSM 'setup x509 signed commit' '
> > +
> > +       git checkout -b x509-signing main &&
> > +       test_config gpg.format x509 &&
> > +       test_config user.signingkey $GIT_COMMITTER_EMAIL &&
> > +       echo "x509 content" >file_for_x509 &&
> > +       git add file_for_x509 &&
> > +       git commit -S -m "X.509 signed commit" &&
> > +       X509_COMMIT=$(git rev-parse --verify HEAD) &&
> > +       git checkout main
> > +
> > +'
> > +
> > +test_expect_success GPGSM 'x509 signature identified' '
> > +
> > +       git fast-export --signed-commits=verbatim --reencode=no x509-signing >output 2>err &&
>
> Is --reencode=no important here or does this work with --reencode=yes
> as well?  (I understand the default being --reencode=abort and fact
> that you are reusing an example that used a specialized encoding means
> you need to specify something, was just curious if this particular
> value was important)
>
> > +       grep "^gpgsig x509" output &&
> > +       test ! -s err &&
> > +       (
> > +               cd new &&
> > +               git fast-import &&
> > +               STRIPPED=$(git rev-parse --verify refs/heads/x509-signing) &&
> > +               test $X509_COMMIT = $STRIPPED
>
> Ah, --reencode=no is critical for the test, but only because you are
> trying to ensure you get the same commit back.
Yeah, I think it's useful to check that we can get the same commit back.
> Should there also be a
> test for when something is tweaked, such as the encoding, and whether
> the signature is still found?
[...]
Show 8 quoted lines
> > +test_expect_success GPGSSH 'ssh signature identified' '
> > +
> > +       git fast-export --signed-commits=verbatim --reencode=no ssh-signing >output 2>err &&
>
> Out of curiosity, any particular reason to export the entire history
> instead of just the new commit you just added (though you'd likely
> want --reference-excluded-parents if you did that, which really ought
> to be the default)?  Anyway...
Thanks for your review and all your comments!

As I am not sure which approach is best and I am trying a different approach in v2, it might not be worth discussing some of the details of the approach I took in this v1 anymore. So I will skip answering some of your specific comments unless we decide to go back to that approach later.

Previous: Elijah NewrenNext: brian m. carlson
Message 17 of 65 in “fast-(import|export): improve on the signature algorithm name”
  1. fast-(import|export): improve on the signature algorithm nameChristian Couder, Apr 24, 2025
  2. Junio C HamanoApr 24, 2025
  3. Elijah NewrenApr 24, 2025
  4. Junio C HamanoApr 24, 2025
  5. Christian CouderMay 26, 2025
  6. Junio C HamanoMay 27, 2025
  7. Junio C HamanoMay 28, 2025
  8. Elijah NewrenMay 28, 2025
  9. Junio C HamanoMay 28, 2025
  10. Elijah NewrenMay 28, 2025
  11. Junio C HamanoMay 29, 2025
  12. Christian CouderJun 2, 2025
  13. Christian CouderJun 2, 2025
  14. Junio C HamanoJun 2, 2025
  15. Christian CouderMay 26, 2025
  16. Elijah NewrenApr 24, 2025
  17. Christian CouderMay 26, 2025
  18. brian m. carlsonApr 24, 2025
  19. Christian CouderMay 26, 2025
  20. Junio C HamanoApr 24, 2025
  21. 0/6 extract algo information from signaturesChristian Couder, May 26, 2025
  22. 1/6 gpg-interface: simplify ssh fingerprint parsingChristian Couder, May 26, 2025
  23. 2/6 gpg-interface: use left shift to define GPG_VERIFY_*Christian Couder, May 26, 2025
  24. 3/6 doc/verify-commit: update and improve the whole docChristian Couder, May 26, 2025
  25. 4/6 gpg-interface: extract hash algorithm from signature status outputChristian Couder, May 26, 2025
  26. 5/6 gpg-interface: extract SSH key type from signature status outputChristian Couder, May 26, 2025
  27. 6/6 verify-commit: add a --summary flagChristian Couder, May 26, 2025
  28. Elijah NewrenMay 26, 2025
  29. Christian CouderJun 19, 2025
  30. brian m. carlsonJun 2, 2025
  31. Christian CouderJun 19, 2025
  32. fast-(import|export): improve on commit signature output formatChristian Couder, Jun 18, 2025
  33. fast-(import|export): improve on commit signature output formatChristian Couder, Jun 19, 2025
  34. Junio C HamanoJun 19, 2025
  35. Christian CouderJul 8, 2025
  36. Elijah NewrenJun 19, 2025
  37. Christian CouderJun 20, 2025
  38. Junio C HamanoJun 20, 2025
  39. Christian CouderJul 8, 2025
  40. Elijah NewrenJun 26, 2025
  41. Christian CouderJul 8, 2025
  42. Junio C HamanoJul 7, 2025
  43. Christian CouderJul 8, 2025
  44. Junio C HamanoJul 8, 2025
  45. Patrick SteinhardtJul 8, 2025
  46. Christian CouderJul 8, 2025
  47. Junio C HamanoJul 8, 2025
  48. Christian CouderJul 9, 2025
  49. Junio C HamanoJul 9, 2025
  50. Patrick SteinhardtJul 10, 2025
  51. Christian CouderJul 10, 2025
  52. Junio C HamanoJul 10, 2025
  53. Christian CouderJul 8, 2025
  54. fast-(import|export): improve on commit signature output formatChristian Couder, Jul 8, 2025
  55. Junio C HamanoJul 8, 2025
  56. Elijah NewrenJul 8, 2025
  57. Junio C HamanoJul 9, 2025
  58. Elijah NewrenJul 9, 2025
  59. Christian CouderJul 9, 2025
  60. Christian CouderJul 9, 2025
  61. fast-(import|export): improve on commit signature output formatChristian Couder, Jul 9, 2025
  62. Junio C HamanoJul 9, 2025
  63. Elijah NewrenJul 14, 2025
  64. Junio C HamanoJul 14, 2025
  65. Christian CouderJul 25, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.