git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: "Robin H. Johnson" <robbat2@gentoo.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: GPG signing for git commit?
Date: Mon, 11 May 2009 20:39:38 +1000	[thread overview]
Message-ID: <fcaeb9bf0905110339q22692751jc12f5a199bf47740@mail.gmail.com> (raw)
In-Reply-To: <fcaeb9bf0905101553p56f5e8b2o6e6b550e9494b726@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]

On Mon, May 11, 2009 at 8:53 AM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> On Sat, May 9, 2009 at 5:03 AM, Robin H. Johnson <robbat2@gentoo.org> wrote:
>>> How about signing the tree SHA-1 and putting the signature in commit
>>> message? It's like gpg way of saying Signed-off-by. If the committer
>>> wants to sign again before pushing out, he could amend the commit,
>>> append his signature there; or make a no-change commit to contain his
>>> signature (probably from git-commit-tree because iirc git-commit won't
>>> let you make no-change commit)
>> Hmm, I like the sound of that, but I'm concerned it might be difficult
>> to enforce. If rewrite-history ever happens, it's also invalidated.
>
> Well if you rewrite and touch the trees, then every signature should
> be invalidated anyway. If you only touch commit message, it should
> remain valid because I only sign trees.

I went ahead and made two scripts git-gpg-sign and git-gpg-verify to
see if it works. Things that are signed in these scripts:
 - tree
 - parents
 - any other gpg signature
You probably don't want to sign the same commit too many times because
the signature will get huge.
-- 
Duy

[-- Attachment #2: git-gpg-sign --]
[-- Type: application/octet-stream, Size: 601 bytes --]

#!/bin/sh
PGP='/^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/'
COMMIT_GPGMSG="$(git rev-parse --git-dir)"/COMMIT_GPGMSG
GPGMSG="$(git rev-parse --git-dir)"/GPGMSG
git cat-file -p HEAD | sed -ne '1,/^$/p' | egrep '^tree |^parent ' > "$GPGMSG"

#if it's not valid, just drop it
git cat-file -p HEAD | grep -q '^-----BEGIN PGP MESSAGE-----$' &&
	git gpg-verify &&
	git cat-file -p HEAD | sed -ne "$PGP"p >> "$GPGMSG"
git cat-file -p HEAD | sed -e '1,/^$/d' | sed -e "$PGP"d > "$COMMIT_GPGMSG"
gpg --sign --armor -o - "$GPGMSG" >> "$COMMIT_GPGMSG"
git commit --amend -F "$COMMIT_GPGMSG" -e

[-- Attachment #3: git-gpg-verify --]
[-- Type: application/octet-stream, Size: 563 bytes --]

#!/bin/sh

die() {
	echo "$@"
	exit 1
}

PGP='/^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/'
C="$1"
GPGMSG1="$(git rev-parse --git-dir)"/GPGMSG1
GPGMSG2="$(git rev-parse --git-dir)"/GPGMSG2
[ -n "$1" ] || C=HEAD
git cat-file commit $C > "$GPGMSG1"
while grep -q '^-----BEGIN PGP MESSAGE-----$' "$GPGMSG1";do
	[ -f "$GPGMSG2" ] && rm -f "$GPGMSG2"
	gpg -o "$GPGMSG2" "$GPGMSG1" || die "Failed to verify"
	mv "$GPGMSG2" "$GPGMSG1"
done
git cat-file commit $C | sed -ne '1,/^$/p' | egrep '^tree |^parent '|cmp -s "$GPGMSG1" || die "Failed to verify"

  reply	other threads:[~2009-05-11 10:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-03 21:25 GPG signing for git commit? Chow Loong Jin
2009-04-03 22:54 ` Linus Torvalds
2009-04-06  6:05   ` Sam Vilain
2009-04-15 18:55     ` Robin H. Johnson
2009-04-15 19:20       ` Shawn O. Pearce
2009-04-15 22:29         ` Robin H. Johnson
2009-04-16 14:27           ` Shawn O. Pearce
2009-04-17  3:42             ` Sitaram Chamarty
2009-04-17 12:01               ` Jeff King
2009-04-17 18:36                 ` Sitaram Chamarty
2009-04-21 20:27                   ` Jeff King
2009-05-07  5:30       ` Nguyen Thai Ngoc Duy
2009-05-08 19:03         ` Robin H. Johnson
2009-05-10 22:53           ` Nguyen Thai Ngoc Duy
2009-05-11 10:39             ` Nguyen Thai Ngoc Duy [this message]
2009-04-07 17:55   ` Jakub Narebski
2009-04-07 18:04     ` Linus Torvalds

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

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

  git send-email \
    --in-reply-to=fcaeb9bf0905110339q22692751jc12f5a199bf47740@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=robbat2@gentoo.org \
    /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.
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 NNTP newsgroup(s).