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

[PATCHv2] gpg-interface: check gpg signature for correct header

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jun 14, 2016, 12:05 UTC
Message-ID
<b057610446674c3323fbba09494229621ec4c032.1465905749.git.git@drmicha.warpmail.net>
In-Reply-To
<26353a3d-e495-075f-4f84-b34a2420a6cf@drmicha.warpmail.net>

When we create a signature, it may happen that gpg returns with "success" but not with an actual detached signature on stdout.

Check for the correct header to catch these cases better. We use the same parse_signature function for that that we use otherwise, so that gpg specifics are localised there.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
So, this is the real thing.

Between you and me: parse_signature in fact is more lenient, but hey - it's exactly as lenient as we are otherwise, bar running gpg --verify.

 gpg-interface.c |  2 +-
 t/t7004-tag.sh  | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index c4b1e8c..784953c 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -185,7 +185,7 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
 
 	sigchain_pop(SIGPIPE);
 
-	if (finish_command(&gpg) || !len || len < 0)
+	if (finish_command(&gpg) || !len || len < 0 || parse_signature(signature->buf, signature->len) == signature->len)
 		return error(_("gpg failed to sign the data"));
 
 	/* Strip CR from the line endings, in case we are on Windows. */
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index f9b7d79..467e968 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1202,10 +1202,18 @@ test_expect_success GPG,RFC1991 \
 # try to sign with bad user.signingkey
 git config user.signingkey BobTheMouse
 test_expect_success GPG \
-	'git tag -s fails if gpg is misconfigured' \
+	'git tag -s fails if gpg is misconfigured (bad key)' \
 	'test_must_fail git tag -s -m tail tag-gpg-failure'
 git config --unset user.signingkey
 
+# try to produce invalid signature
+git config gpg.program echo
+test_expect_success GPG \
+	'git tag -s fails if gpg is misconfigured (bad signature format)' \
+	'test_must_fail git tag -s -m tail tag-gpg-failure'
+git config --unset gpg.program
+
+
 # try to verify without gpg:
 
 rm -rf gpghome
-- 
2.9.0.382.g87fd384
Previous: Michael J GruberNext: Michael J Gruber
Message 13 of 31 in “I lost my commit signature”
  1. ZhenTianJun 14, 2016
  2. Jeff KingJun 14, 2016
  3. ZhenTianJun 14, 2016
  4. Jeff KingJun 14, 2016
  5. ZhenTianJun 14, 2016
  6. Jeff KingJun 14, 2016
  7. ZhenTianJun 14, 2016
  8. Michael J GruberJun 14, 2016
  9. gpg-interface: check gpg signature for correct headerMichael J Gruber, Jun 14, 2016
  10. Jeff KingJun 14, 2016
  11. Michael J GruberJun 14, 2016
  12. Michael J GruberJun 14, 2016
  13. [PATCHv2] gpg-interface: check gpg signature for correct headerMichael J Gruber, Jun 14, 2016
  14. [PATCHv3] gpg-interface: check gpg signature creation statusMichael J Gruber, Jun 14, 2016
  15. Junio C HamanoJun 14, 2016
  16. Jeff KingJun 14, 2016
  17. Jeff KingJun 14, 2016
  18. Junio C HamanoJun 14, 2016
  19. Jeff KingJun 15, 2016
  20. Michael J GruberJun 15, 2016
  21. Jeff KingJun 16, 2016
  22. Michael J GruberJun 16, 2016
  23. Jeff KingJun 15, 2016
  24. ZhenTianJun 15, 2016
  25. Jeff KingJun 15, 2016
  26. Michael J GruberJun 15, 2016
  27. ZhenTianJun 15, 2016
  28. Jeff KingJun 16, 2016
  29. Junio C HamanoJun 16, 2016
  30. Michael J GruberJun 17, 2016
  31. Junio C HamanoJun 17, 2016

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.