git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Denton Liu <liu.denton@gmail.com>, Jeff King <peff@peff.net>
Subject: [PATCH 6/6] gpg-interface: remove other signature headers before verifying
Date: Mon, 11 Jan 2021 00:37:40 +0000	[thread overview]
Message-ID: <20210111003740.1319996-8-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20210111003740.1319996-1-sandals@crustytoothpaste.net>

When we have a multiply signed commit, we need to remove the signature
in the header before verifying the object, since the trailing signature
will not be over both pieces of data.  Do so, and verify that we
validate the signature appropriately.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 gpg-interface.c |  2 ++
 t/t7004-tag.sh  | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/gpg-interface.c b/gpg-interface.c
index c6274c14af..127aecfc2b 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "commit.h"
 #include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
@@ -366,6 +367,7 @@ int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct
 	size_t match = parse_signed_buffer(buf, size);
 	if (match != size) {
 		strbuf_add(payload, buf, match);
+		remove_signature(payload);
 		strbuf_add(signature, buf + match, size - match);
 		return 1;
 	}
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 05f411c821..6fb4e3cf11 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -17,6 +17,13 @@ tag_exists () {
 	git show-ref --quiet --verify refs/tags/"$1"
 }
 
+test_expect_success 'setup' '
+	test_oid_cache <<-EOM
+	othersigheader sha1:gpgsig-sha256
+	othersigheader sha256:gpgsig
+	EOM
+'
+
 test_expect_success 'listing all tags in an empty tree should succeed' '
 	git tag -l &&
 	git tag
@@ -1371,6 +1378,24 @@ test_expect_success GPG \
 	'test_config gpg.program echo &&
 	 test_must_fail git tag -s -m tail tag-gpg-failure'
 
+# try to produce invalid signature
+test_expect_success GPG 'git verifies tag is valid with double signature' '
+	git tag -s -m tail tag-gpg-double-sig &&
+	git cat-file tag tag-gpg-double-sig >tag &&
+	othersigheader=$(test_oid othersigheader) &&
+	sed -ne "/^\$/q;p" tag >new-tag &&
+	cat <<-EOM >>new-tag &&
+	$othersigheader -----BEGIN PGP SIGNATURE-----
+	 someinvaliddata
+	 -----END PGP SIGNATURE-----
+	EOM
+	sed -e "1,/^tagger/d" tag >>new-tag &&
+	new_tag=$(git hash-object -t tag -w new-tag) &&
+	git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
+	git verify-tag tag-gpg-double-sig &&
+	git fsck
+'
+
 # try to sign with bad user.signingkey
 test_expect_success GPGSM \
 	'git tag -s fails if gpgsm is misconfigured (bad key)' \

  parent reply	other threads:[~2021-01-11  0:40 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11  0:37 [PATCH 0/5] Support for commits signed by multiple algorithms brian m. carlson
2021-01-11  0:37 ` [PATCH 1/5] commit: ignore additional signatures when parsing signed commits brian m. carlson
2021-01-11  0:37 ` [PATCH 2/5] gpg-interface: improve interface for parsing tags brian m. carlson
2021-01-12  4:58   ` Junio C Hamano
2021-01-14 23:18     ` brian m. carlson
2021-01-15  1:47       ` Junio C Hamano
2021-01-11  0:37 ` [PATCH 3/5] commit: allow parsing arbitrary buffers with headers brian m. carlson
2021-01-11  0:37 ` [PATCH 4/5] ref-filter: hoist signature parsing brian m. carlson
2021-01-11  0:37 ` [PATCH 5/6] fixup! commit: ignore additional signatures when parsing signed commits brian m. carlson
2021-01-11  0:43   ` brian m. carlson
2021-01-11  0:37 ` [PATCH 5/5] gpg-interface: remove other signature headers before verifying brian m. carlson
2021-01-11  0:37 ` brian m. carlson [this message]
2021-01-11  3:58 ` [PATCH v2 0/5] Support for commits signed by multiple algorithms brian m. carlson
2021-01-11  3:58   ` [PATCH v2 1/5] commit: ignore additional signatures when parsing signed commits brian m. carlson
2021-01-12 17:03     ` SZEDER Gábor
2021-01-11  3:58   ` [PATCH v2 2/5] gpg-interface: improve interface for parsing tags brian m. carlson
2021-01-12  5:24     ` Junio C Hamano
2021-01-11  3:58   ` [PATCH v2 3/5] commit: allow parsing arbitrary buffers with headers brian m. carlson
2021-01-11  3:58   ` [PATCH v2 4/5] ref-filter: hoist signature parsing brian m. carlson
2021-01-11  3:58   ` [PATCH v2 5/5] gpg-interface: remove other signature headers before verifying brian m. carlson
2021-01-11 22:16   ` [PATCH v2 0/5] Support for commits signed by multiple algorithms Junio C Hamano
2021-01-11 23:29     ` brian m. carlson
2021-01-12  2:03       ` Junio C Hamano
2021-01-12  2:24         ` brian m. carlson
2021-01-18 23:49   ` [PATCH v3 0/6] " brian m. carlson
2021-01-18 23:49     ` [PATCH v3 1/6] ref-filter: switch some uses of unsigned long to size_t brian m. carlson
2021-01-18 23:49     ` [PATCH v3 2/6] commit: ignore additional signatures when parsing signed commits brian m. carlson
2021-01-18 23:49     ` [PATCH v3 3/6] gpg-interface: improve interface for parsing tags brian m. carlson
2021-01-18 23:49     ` [PATCH v3 4/6] commit: allow parsing arbitrary buffers with headers brian m. carlson
2021-01-18 23:49     ` [PATCH v3 5/6] ref-filter: hoist signature parsing brian m. carlson
2021-01-18 23:49     ` [PATCH v3 6/6] gpg-interface: remove other signature headers before verifying brian m. carlson
2021-02-11  2:08     ` [PATCH v4 0/6] Support for commits signed by multiple algorithms brian m. carlson
2021-02-11  2:08       ` [PATCH v4 1/6] ref-filter: switch some uses of unsigned long to size_t brian m. carlson
2021-02-11  2:08       ` [PATCH v4 2/6] commit: ignore additional signatures when parsing signed commits brian m. carlson
2021-02-11  2:08       ` [PATCH v4 3/6] gpg-interface: improve interface for parsing tags brian m. carlson
2021-02-11  2:08       ` [PATCH v4 4/6] commit: allow parsing arbitrary buffers with headers brian m. carlson
2021-02-11  2:08       ` [PATCH v4 5/6] ref-filter: hoist signature parsing brian m. carlson
2021-02-11  2:08       ` [PATCH v4 6/6] gpg-interface: remove other signature headers before verifying brian m. carlson
2021-02-11  7:45       ` [PATCH v4 0/6] Support for commits signed by multiple algorithms Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210111003740.1319996-8-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=liu.denton@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).