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

Re: [PATCH 8/8] gpg-interface: handle alternative signature types

From
Stefan Beller <sbeller@google.com>
Date
Apr 9, 2018, 21:01 UTC
Message-ID
<CAGZ79kYQ0AO=Lp6hpsMfQK0PFt7veEwc+uK-0+JLrudAQ1iAXw@mail.gmail.com>
In-Reply-To
<20180409204129.43537-9-mastahyeti@gmail.com>
Hi Ben,
On Mon, Apr 9, 2018 at 1:41 PM, Ben Toews <mastahyeti@gmail.com> wrote:
Show 71 quoted lines
> From: Ben Toews <btoews@github.com>
>
> Currently you can only sign commits and tags using "gpg".
> You can _almost_ plug in a related tool like "gpgsm" (which
> uses S/MIME-style signatures instead of PGP) using
> gpg.program, as it has command-line compatibility. But there
> are a few rough edges:
>
>   1. gpgsm generates a slightly different PEM format than
>      gpg. It says:
>
>        -----BEGIN SIGNED MESSAGE-----
>
>      instead of:
>
>        -----BEGIN PGP SIGNATURE-----
>
>      This actually works OK for signed commits, where we
>      just dump the gpgsig header to gpg.program regardless.
>
>      But for tags, we actually have to parse out the
>      detached signature, and we fail to recognize the gpgsm
>      version.
>
>   2. You can't mix the two types of signatures easily, as
>      we'd send the output to whatever tool you've
>      configured. For verification, we'd ideally dispatch gpg
>      signatures to gpg, gpgsm ones to gpgsm, and so on. For
>      signing, you'd obviously have to pick a tool to use.
>
> This patch introduces a set of configuration options for
> defining a "signing tool", of which gpg may be just one.
> With this patch you can:
>
>   - define a new tool "foo" with signingtool.foo.program
>
>   - map PEM strings to it for verification using
>     signingtool.foo.pemtype
>
>   - set it as your default tool for creating signatures
>     using using signingtool.default
>
> This subsumes the existing gpg config, as we have baked-in
> config for signingtool.gpg that works just like the current
> hard-coded behavior. And setting gpg.program becomes an
> alias for signingtool.gpg.program.
>
> This is enough to plug in gpgsm like:
>
>   [signingtool "gpgsm"]
>   program = gpgsm
>   pemtype = "SIGNED MESSAGE"
>
> In the future, this config scheme gives us options for
> extending to other tools:
>
>   - the tools all have to accept gpg-like options for now,
>     but we could add signingtool.interface to meet other
>     standards
>
>   - we only match PEM headers now, but we could add other
>     config for matching non-PEM types
>
> The implementation is still in gpg-interface.c, and most of
> the code internally refers to this as "gpg". I've left it
> this way to keep the diff sane, and to make it clear that
> we're not breaking anything gpg-related. This is probably OK
> for now, as our tools must be gpg-like anyway. But renaming
> everything would be an obvious next-step refactoring if we
> want to offer support for more exotic tools (e.g., people
> have asked before on the list about using OpenBSD signify).
Please sign off your patch, see Documentation/SubmittingPatches
Show 47 quoted lines
> ---
>  Documentation/config.txt |  40 +++++++++---
>  builtin/fmt-merge-msg.c  |   6 +-
>  builtin/receive-pack.c   |   7 +-
>  builtin/tag.c            |   2 +-
>  commit.c                 |   2 +-
>  gpg-interface.c          | 165 ++++++++++++++++++++++++++++++++++++++++++-----
>  gpg-interface.h          |  24 ++++++-
>  log-tree.c               |   7 +-
>  ref-filter.c             |   2 +-
>  t/lib-gpg.sh             |  26 ++++++++
>  t/t7510-signed-commit.sh |  32 ++++++++-
>  tag.c                    |   2 +-
>  12 files changed, 272 insertions(+), 43 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 4e0cff87f6..7906123a59 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -1727,16 +1727,38 @@ grep.fallbackToNoIndex::
>         If set to true, fall back to git grep --no-index if git grep
>         is executed outside of a git repository.  Defaults to false.
>
> -gpg.program::
> -       Use this custom program instead of "`gpg`" found on `$PATH` when
> -       making or verifying a PGP signature. The program must support the
> -       same command-line interface as GPG, namely, to verify a detached
> -       signature, "`gpg --verify $file - <$signature`" is run, and the
> -       program is expected to signal a good signature by exiting with
> -       code 0, and to generate an ASCII-armored detached signature, the
> -       standard input of "`gpg -bsau $key`" is fed with the contents to be
> +signingtool.<name>.program::
> +       The name of the program on `$PATH` to execute when making or
> +       verifying a signature. This program will be used for making
> +       signatures if `<name>` is configured as `signingtool.default`.
> +       This program will be used for verifying signatures whose PEM
> +       block type matches `signingtool.<name>.pemtype` (see below). The
> +       program must support the same command-line interface as GPG.
> +       To verify a detached signature,
> +       "`gpg --verify $file - <$signature`" is run, and the program is
> +       expected to signal a good signature by exiting with code 0.
> +       To generate an ASCII-armored detached signature, the standard
> +       input of "`gpg -bsau $key`" is fed with the contents to be
>         signed, and the program is expected to send the result to its
> -       standard output.
> +       standard output. By default, `signingtool.gpg.program` is set to
> +       `gpg`.

I wonder if the mention of the default is best put at the pgp.program instead of here, although the mention of it being an alias strongly suggest we'd want to deprecate it eventually.

Show 20 quoted lines
> +
> +signingtool.<name>.pemtype::
> +       The PEM block type associated with the signing tool named
> +       `<name>`. For example, the block type of a GPG signature
> +       starting with `-----BEGIN PGP SIGNATURE-----` is `PGP
> +       SIGNATURE`. When verifying a signature with this PEM block type
> +       the program specified in `signingtool.<name>.program` will be
> +       used. By default `signingtool.gpg.pemtype` contains `PGP
> +       SIGNATURE` and `PGP MESSAGE`.
> +
> +signingtool.default::
> +       The `<name>` of the signing tool to use when creating
> +       signatures (e.g., setting it to "foo" will use use the program
> +       specified by `signingtool.foo.program`). Defaults to `gpg`.
> +
> +gpg.program::
> +       Historical alias for `signingtool.gpg.program`.
>
>  gui.commitMsgWidth::
>         Defines how wide the commit message window is in the
Show 5 quoted lines
> +/*
> + * Our default tool config is too complicated to specify as a constant
> + * initializer, so we lazily create it as needed.
> + */
> +static void init_signing_tool_defaults(void) {

Coding Style: please put the opening brace in a new line when staring a function (but not for statements).

Previous: Ben ToewsNext: Eric Sunshine
Message 18 of 46 in “gpg-interface: Multiple signing tools”
  1. 0/8 gpg-interface: Multiple signing toolsBen Toews, Apr 9, 2018
  2. 1/8 gpg-interface: handle bool user.signingkeyBen Toews, Apr 9, 2018
  3. Eric SunshineApr 9, 2018
  4. Jeff KingApr 10, 2018
  5. 3/8 gpg-interface: use size_t for signature buffer sizeBen Toews, Apr 9, 2018
  6. 2/8 gpg-interface: modernize function declarationsBen Toews, Apr 9, 2018
  7. 4/8 gpg-interface: fix const-correctness of "eol" pointerBen Toews, Apr 9, 2018
  8. 5/8 gpg-interface: extract gpg line matching helperBen Toews, Apr 9, 2018
  9. 7/8 gpg-interface: prepare for parsing arbitrary PEM blocksBen Toews, Apr 9, 2018
  10. 6/8 gpg-interface: find the last gpg signature lineBen Toews, Apr 9, 2018
  11. Eric SunshineApr 9, 2018
  12. Junio C HamanoApr 10, 2018
  13. Ben ToewsApr 10, 2018
  14. Junio C HamanoApr 10, 2018
  15. Junio C HamanoApr 10, 2018
  16. Ben ToewsApr 11, 2018
  17. 8/8 gpg-interface: handle alternative signature typesBen Toews, Apr 9, 2018
  18. Stefan BellerApr 9, 2018
  19. Eric SunshineApr 10, 2018
  20. Ben ToewsApr 10, 2018
  21. brian m. carlsonApr 14, 2018
  22. Junio C HamanoApr 16, 2018
  23. brian m. carlsonApr 17, 2018
  24. Junio C HamanoApr 17, 2018
  25. Ben ToewsApr 17, 2018
  26. Taylor BlauApr 17, 2018
  27. Ben ToewsMay 3, 2018
  28. Jeff KingMay 7, 2018
  29. Junio C HamanoMay 7, 2018
  30. brian m. carlsonMay 7, 2018
  31. Jeff KingMay 8, 2018
  32. brian m. carlsonMay 8, 2018
  33. Jeff KingMay 9, 2018
  34. Junio C HamanoApr 10, 2018
  35. Ben ToewsApr 10, 2018
  36. SZEDER GáborApr 11, 2018
  37. 0/9 gpg-interface: Multiple signing toolsBen Toews, Apr 13, 2018
  38. 2/9 gpg-interface: handle bool user.signingkeyBen Toews, Apr 13, 2018
  39. 3/9 gpg-interface: modernize function declarationsBen Toews, Apr 13, 2018
  40. 1/9 t7004: fix mistaken tag nameBen Toews, Apr 13, 2018
  41. 8/9 gpg-interface: prepare for parsing arbitrary PEM blocksBen Toews, Apr 13, 2018
  42. 4/9 gpg-interface: use size_t for signature buffer sizeBen Toews, Apr 13, 2018
  43. 5/9 gpg-interface: fix const-correctness of "eol" pointerBen Toews, Apr 13, 2018
  44. 6/9 gpg-interface: extract gpg line matching helperBen Toews, Apr 13, 2018
  45. 7/9 gpg-interface: find the last gpg signature lineBen Toews, Apr 13, 2018
  46. 9/9 gpg-interface: handle alternative signature typesBen Toews, Apr 13, 2018

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.