2015-06-22 01:14:37 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='signed tag tests'
|
|
|
|
. ./test-lib.sh
|
|
|
|
. "$TEST_DIRECTORY/lib-gpg.sh"
|
|
|
|
|
|
|
|
test_expect_success GPG 'create signed tags' '
|
|
|
|
echo 1 >file && git add file &&
|
|
|
|
test_tick && git commit -m initial &&
|
|
|
|
git tag -s -m initial initial &&
|
|
|
|
git branch side &&
|
|
|
|
|
|
|
|
echo 2 >file && test_tick && git commit -a -m second &&
|
|
|
|
git tag -s -m second second &&
|
|
|
|
|
|
|
|
git checkout side &&
|
|
|
|
echo 3 >elif && git add elif &&
|
|
|
|
test_tick && git commit -m "third on side" &&
|
|
|
|
|
|
|
|
git checkout master &&
|
|
|
|
test_tick && git merge -S side &&
|
|
|
|
git tag -s -m merge merge &&
|
|
|
|
|
|
|
|
echo 4 >file && test_tick && git commit -a -S -m "fourth unsigned" &&
|
|
|
|
git tag -a -m fourth-unsigned fourth-unsigned &&
|
|
|
|
|
|
|
|
test_tick && git commit --amend -S -m "fourth signed" &&
|
|
|
|
git tag -s -m fourth fourth-signed &&
|
|
|
|
|
|
|
|
echo 5 >file && test_tick && git commit -a -m "fifth" &&
|
|
|
|
git tag fifth-unsigned &&
|
|
|
|
|
|
|
|
git config commit.gpgsign true &&
|
|
|
|
echo 6 >file && test_tick && git commit -a -m "sixth" &&
|
|
|
|
git tag -a -m sixth sixth-unsigned &&
|
|
|
|
|
|
|
|
test_tick && git rebase -f HEAD^^ && git tag -s -m 6th sixth-signed HEAD^ &&
|
|
|
|
git tag -m seventh -s seventh-signed &&
|
|
|
|
|
|
|
|
echo 8 >file && test_tick && git commit -a -m eighth &&
|
|
|
|
git tag -uB7227189 -m eighth eighth-signed-alt
|
|
|
|
'
|
|
|
|
|
2018-07-20 10:28:07 +02:00
|
|
|
test_expect_success GPGSM 'create signed tags x509 ' '
|
|
|
|
test_config gpg.format x509 &&
|
|
|
|
test_config user.signingkey $GIT_COMMITTER_EMAIL &&
|
2019-11-05 18:07:27 +01:00
|
|
|
echo 9 >file && test_tick && git commit -a -m "ninth gpgsm-signed" &&
|
|
|
|
git tag -s -m ninth ninth-signed-x509
|
2018-07-20 10:28:07 +02:00
|
|
|
'
|
|
|
|
|
2015-06-22 01:14:37 +02:00
|
|
|
test_expect_success GPG 'verify and show signatures' '
|
|
|
|
(
|
|
|
|
for tag in initial second merge fourth-signed sixth-signed seventh-signed
|
|
|
|
do
|
|
|
|
git verify-tag $tag 2>actual &&
|
|
|
|
grep "Good signature from" actual &&
|
|
|
|
! grep "BAD signature from" actual &&
|
|
|
|
echo $tag OK || exit 1
|
|
|
|
done
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
for tag in fourth-unsigned fifth-unsigned sixth-unsigned
|
|
|
|
do
|
|
|
|
test_must_fail git verify-tag $tag 2>actual &&
|
|
|
|
! grep "Good signature from" actual &&
|
|
|
|
! grep "BAD signature from" actual &&
|
|
|
|
echo $tag OK || exit 1
|
|
|
|
done
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
for tag in eighth-signed-alt
|
|
|
|
do
|
|
|
|
git verify-tag $tag 2>actual &&
|
|
|
|
grep "Good signature from" actual &&
|
|
|
|
! grep "BAD signature from" actual &&
|
|
|
|
grep "not certified" actual &&
|
|
|
|
echo $tag OK || exit 1
|
|
|
|
done
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2018-07-20 10:28:07 +02:00
|
|
|
test_expect_success GPGSM 'verify and show signatures x509' '
|
2019-11-05 18:07:27 +01:00
|
|
|
git verify-tag ninth-signed-x509 2>actual &&
|
2018-07-20 10:28:07 +02:00
|
|
|
grep "Good signature from" actual &&
|
|
|
|
! grep "BAD signature from" actual &&
|
2019-11-05 18:07:27 +01:00
|
|
|
echo ninth-signed-x509 OK
|
2018-07-20 10:28:07 +02:00
|
|
|
'
|
|
|
|
|
gpg-interface: add minTrustLevel as a configuration option
Previously, signature verification for merge and pull operations checked
if the key had a trust-level of either TRUST_NEVER or TRUST_UNDEFINED in
verify_merge_signature(). If that was the case, the process die()d.
The other code paths that did signature verification relied entirely on
the return code from check_commit_signature(). And signatures made with
a good key, irregardless of its trust level, was considered valid by
check_commit_signature().
This difference in behavior might induce users to erroneously assume
that the trust level of a key in their keyring is always considered by
Git, even for operations where it is not (e.g. during a verify-commit or
verify-tag).
The way it worked was by gpg-interface.c storing the result from the
key/signature status *and* the lowest-two trust levels in the `result`
member of the signature_check structure (the last of these status lines
that were encountered got written to `result`). These are documented in
GPG under the subsection `General status codes` and `Key related`,
respectively [1].
The GPG documentation says the following on the TRUST_ status codes [1]:
"""
These are several similar status codes:
- TRUST_UNDEFINED <error_token>
- TRUST_NEVER <error_token>
- TRUST_MARGINAL [0 [<validation_model>]]
- TRUST_FULLY [0 [<validation_model>]]
- TRUST_ULTIMATE [0 [<validation_model>]]
For good signatures one of these status lines are emitted to
indicate the validity of the key used to create the signature.
The error token values are currently only emitted by gpgsm.
"""
My interpretation is that the trust level is conceptionally different
from the validity of the key and/or signature. That seems to also have
been the assumption of the old code in check_signature() where a result
of 'G' (as in GOODSIG) and 'U' (as in TRUST_NEVER or TRUST_UNDEFINED)
were both considered a success.
The two cases where a result of 'U' had special meaning were in
verify_merge_signature() (where this caused git to die()) and in
format_commit_one() (where it affected the output of the %G? format
specifier).
I think it makes sense to refactor the processing of TRUST_ status lines
such that users can configure a minimum trust level that is enforced
globally, rather than have individual parts of git (e.g. merge) do it
themselves (except for a grace period with backward compatibility).
I also think it makes sense to not store the trust level in the same
struct member as the key/signature status. While the presence of a
TRUST_ status code does imply that the signature is good (see the first
paragraph in the included snippet above), as far as I can tell, the
order of the status lines from GPG isn't well-defined; thus it would
seem plausible that the trust level could be overwritten with the
key/signature status if they were stored in the same member of the
signature_check structure.
This patch introduces a new configuration option: gpg.minTrustLevel. It
consolidates trust-level verification to gpg-interface.c and adds a new
`trust_level` member to the signature_check structure.
Backward-compatibility is maintained by introducing a special case in
verify_merge_signature() such that if no user-configurable
gpg.minTrustLevel is set, then the old behavior of rejecting
TRUST_UNDEFINED and TRUST_NEVER is enforced. If, on the other hand,
gpg.minTrustLevel is set, then that value overrides the old behavior.
Similarly, the %G? format specifier will continue show 'U' for
signatures made with a key that has a trust level of TRUST_UNDEFINED or
TRUST_NEVER, even though the 'U' character no longer exist in the
`result` member of the signature_check structure. A new format
specifier, %GT, is also introduced for users that want to show all
possible trust levels for a signature.
Another approach would have been to simply drop the trust-level
requirement in verify_merge_signature(). This would also have made the
behavior consistent with other parts of git that perform signature
verification. However, requiring a minimum trust level for signing keys
does seem to have a real-world use-case. For example, the build system
used by the Qubes OS project currently parses the raw output from
verify-tag in order to assert a minimum trust level for keys used to
sign git tags [2].
[1] https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=doc/doc/DETAILS;h=bd00006e933ac56719b1edd2478ecd79273eae72;hb=refs/heads/master
[2] https://github.com/QubesOS/qubes-builder/blob/9674c1991deef45b1a1b1c71fddfab14ba50dccf/scripts/verify-git-tag#L43
Signed-off-by: Hans Jerry Illikainen <hji@dyntopia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-12-27 14:55:57 +01:00
|
|
|
test_expect_success GPGSM 'verify and show signatures x509 with low minTrustLevel' '
|
|
|
|
test_config gpg.minTrustLevel undefined &&
|
|
|
|
git verify-tag ninth-signed-x509 2>actual &&
|
|
|
|
grep "Good signature from" actual &&
|
|
|
|
! grep "BAD signature from" actual &&
|
|
|
|
echo ninth-signed-x509 OK
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success GPGSM 'verify and show signatures x509 with matching minTrustLevel' '
|
|
|
|
test_config gpg.minTrustLevel fully &&
|
|
|
|
git verify-tag ninth-signed-x509 2>actual &&
|
|
|
|
grep "Good signature from" actual &&
|
|
|
|
! grep "BAD signature from" actual &&
|
|
|
|
echo ninth-signed-x509 OK
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success GPGSM 'verify and show signatures x509 with high minTrustLevel' '
|
|
|
|
test_config gpg.minTrustLevel ultimate &&
|
|
|
|
test_must_fail git verify-tag ninth-signed-x509 2>actual &&
|
|
|
|
grep "Good signature from" actual &&
|
|
|
|
! grep "BAD signature from" actual &&
|
|
|
|
echo ninth-signed-x509 OK
|
|
|
|
'
|
|
|
|
|
2015-06-22 01:14:37 +02:00
|
|
|
test_expect_success GPG 'detect fudged signature' '
|
|
|
|
git cat-file tag seventh-signed >raw &&
|
tests: make forging GPG signed commits and tags more robust
A couple of test scripts create forged GPG signed commits or tags to
check that such forgery can't fool various git commands' signature
verification. All but one of those test scripts are prone to
occasional failures because the forgery creates a bogus GPG signature,
and git commands error out with an unexpected error message, e.g.
"Commit deadbeef does not have a GPG signature" instead of "... has a
bad GPG signature".
't5573-pull-verify-signatures.sh', 't7510-signed-commit.sh' and
't7612-merge-verify-signatures.sh' create forged signed commits like
this:
git commit -S -m "bad on side" &&
git cat-file commit side-bad >raw &&
sed -e "s/bad/forged bad/" raw >forged &&
git hash-object -w -t commit forged >forged.commit
On rare occasions the given pattern occurs not only in the commit
message but in the GPG signature as well, and after it's replaced in
the signature the resulting signature becomes invalid, GPG will report
CRC error and that it couldn't find any signature, which will then
ultimately cause the test failure.
Since in all three cases the pattern to be replaced during the forgery
is the first word of the commit message's subject line, and since the
GPG signature in the commit object is indented by a space, let's just
anchor those patterns to the beginning of the line to prevent this
issue.
The test script 't7030-verify-tag.sh' creates a forged signed tag
object in a similar way by replacing the pattern "seventh", but the
GPG signature in tag objects is not indented by a space, so the above
solution is not applicable in this case. However, in the tag object
in question the pattern "seventh" occurs not only in the tag message
but in the 'tag' header as well. To create a forged tag object it's
sufficient to replace only one of the two occurences, so modify the
sed script to limit the pattern to the 'tag' header (i.e. a line
beginning with "tag ", which, because of the space character, can
never occur in the base64-encoded GPG signature).
Note that the forgery in 't7004-tag.sh' is not affected by this issue:
while 't7004' does create a forged signed tag kind of the same way,
it replaces "signed-tag" in the tag object, which, because of the '-'
character, can never occur in the base64-encoded GPG signarute.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-06-04 15:39:26 +02:00
|
|
|
sed -e "/^tag / s/seventh/7th forged/" raw >forged1 &&
|
2015-06-22 01:14:37 +02:00
|
|
|
git hash-object -w -t tag forged1 >forged1.tag &&
|
|
|
|
test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
|
|
|
|
grep "BAD signature from" actual1 &&
|
|
|
|
! grep "Good signature from" actual1
|
|
|
|
'
|
|
|
|
|
2015-06-22 01:14:43 +02:00
|
|
|
test_expect_success GPG 'verify signatures with --raw' '
|
|
|
|
(
|
|
|
|
for tag in initial second merge fourth-signed sixth-signed seventh-signed
|
|
|
|
do
|
|
|
|
git verify-tag --raw $tag 2>actual &&
|
|
|
|
grep "GOODSIG" actual &&
|
|
|
|
! grep "BADSIG" actual &&
|
|
|
|
echo $tag OK || exit 1
|
|
|
|
done
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
for tag in fourth-unsigned fifth-unsigned sixth-unsigned
|
|
|
|
do
|
|
|
|
test_must_fail git verify-tag --raw $tag 2>actual &&
|
|
|
|
! grep "GOODSIG" actual &&
|
|
|
|
! grep "BADSIG" actual &&
|
|
|
|
echo $tag OK || exit 1
|
|
|
|
done
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
for tag in eighth-signed-alt
|
|
|
|
do
|
|
|
|
git verify-tag --raw $tag 2>actual &&
|
|
|
|
grep "GOODSIG" actual &&
|
|
|
|
! grep "BADSIG" actual &&
|
|
|
|
grep "TRUST_UNDEFINED" actual &&
|
|
|
|
echo $tag OK || exit 1
|
|
|
|
done
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2018-07-20 10:28:07 +02:00
|
|
|
test_expect_success GPGSM 'verify signatures with --raw x509' '
|
2019-11-05 18:07:27 +01:00
|
|
|
git verify-tag --raw ninth-signed-x509 2>actual &&
|
2018-07-20 10:28:07 +02:00
|
|
|
grep "GOODSIG" actual &&
|
|
|
|
! grep "BADSIG" actual &&
|
2019-11-05 18:07:27 +01:00
|
|
|
echo ninth-signed-x509 OK
|
2018-07-20 10:28:07 +02:00
|
|
|
'
|
|
|
|
|
2016-04-18 00:26:57 +02:00
|
|
|
test_expect_success GPG 'verify multiple tags' '
|
|
|
|
tags="fourth-signed sixth-signed seventh-signed" &&
|
|
|
|
for i in $tags
|
|
|
|
do
|
|
|
|
git verify-tag -v --raw $i || return 1
|
|
|
|
done >expect.stdout 2>expect.stderr.1 &&
|
|
|
|
grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
|
|
|
|
git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
|
|
|
|
grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
|
|
|
|
test_cmp expect.stdout actual.stdout &&
|
|
|
|
test_cmp expect.stderr actual.stderr
|
|
|
|
'
|
|
|
|
|
2018-07-20 10:28:07 +02:00
|
|
|
test_expect_success GPGSM 'verify multiple tags x509' '
|
2019-11-05 18:07:27 +01:00
|
|
|
tags="seventh-signed ninth-signed-x509" &&
|
2018-07-20 10:28:07 +02:00
|
|
|
for i in $tags
|
|
|
|
do
|
|
|
|
git verify-tag -v --raw $i || return 1
|
|
|
|
done >expect.stdout 2>expect.stderr.1 &&
|
|
|
|
grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
|
|
|
|
git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
|
|
|
|
grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
|
|
|
|
test_cmp expect.stdout actual.stdout &&
|
|
|
|
test_cmp expect.stderr actual.stderr
|
|
|
|
'
|
|
|
|
|
t7004, t7030: fix here-doc syntax errors
Jan Palus noticed that some here-doc are spelled incorrectly,
resulting the entire remainder of the test snippet being slurped
into the "expect" file as if it were data, e.g. in this sequence
cat >expect <<EOF &&
... expectation ...
EOF
git $cmd_being_tested >actual &&
test_cmp expect actual
the last command of the test is "cat" that sends everything to
'expect' and succeeds.
Fixing these issues in t7004 and t7030 reveals that "git tag -v"
and "git verify-tag" with their --format option do not work as the
test was expecting originally. Instead of showing both valid tags
and tags with incorrect signatures on their output, tags that do not
pass verification are omitted from the output. Another breakage that
is uncovered is that these tests must be restricted to environment
where gpg is available.
Arguably, that is a safer behaviour, and because the format
specifiers like %(tag) do not have a way to show if the signature
verifies correctly, the command with the --format option cannot be
used to get a list of tags annotated with their signature validity
anyway.
For now, let's fix the here-doc syntax, update the expectation to
match the reality, and update the test prerequisite.
Maybe later when we extend the --format language available to "git
tag -v" and "git verify-tag" to include things like "%(gpg:status)",
we may want to change the behaviour so that piping a list of tag
names into
xargs git verify-tag --format='%(gpg:status) %(tag)'
becomes a good way to produce such a list, but that is a separate
topic.
Noticed-by: Jan Palus <jan.palus@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Santiago Torres <santiago@nyu.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-23 23:28:47 +01:00
|
|
|
test_expect_success GPG 'verifying tag with --format' '
|
|
|
|
cat >expect <<-\EOF &&
|
2017-01-18 00:37:22 +01:00
|
|
|
tagname : fourth-signed
|
t7004, t7030: fix here-doc syntax errors
Jan Palus noticed that some here-doc are spelled incorrectly,
resulting the entire remainder of the test snippet being slurped
into the "expect" file as if it were data, e.g. in this sequence
cat >expect <<EOF &&
... expectation ...
EOF
git $cmd_being_tested >actual &&
test_cmp expect actual
the last command of the test is "cat" that sends everything to
'expect' and succeeds.
Fixing these issues in t7004 and t7030 reveals that "git tag -v"
and "git verify-tag" with their --format option do not work as the
test was expecting originally. Instead of showing both valid tags
and tags with incorrect signatures on their output, tags that do not
pass verification are omitted from the output. Another breakage that
is uncovered is that these tests must be restricted to environment
where gpg is available.
Arguably, that is a safer behaviour, and because the format
specifiers like %(tag) do not have a way to show if the signature
verifies correctly, the command with the --format option cannot be
used to get a list of tags annotated with their signature validity
anyway.
For now, let's fix the here-doc syntax, update the expectation to
match the reality, and update the test prerequisite.
Maybe later when we extend the --format language available to "git
tag -v" and "git verify-tag" to include things like "%(gpg:status)",
we may want to change the behaviour so that piping a list of tag
names into
xargs git verify-tag --format='%(gpg:status) %(tag)'
becomes a good way to produce such a list, but that is a separate
topic.
Noticed-by: Jan Palus <jan.palus@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Santiago Torres <santiago@nyu.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-23 23:28:47 +01:00
|
|
|
EOF
|
2017-01-18 00:37:22 +01:00
|
|
|
git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
t7004, t7030: fix here-doc syntax errors
Jan Palus noticed that some here-doc are spelled incorrectly,
resulting the entire remainder of the test snippet being slurped
into the "expect" file as if it were data, e.g. in this sequence
cat >expect <<EOF &&
... expectation ...
EOF
git $cmd_being_tested >actual &&
test_cmp expect actual
the last command of the test is "cat" that sends everything to
'expect' and succeeds.
Fixing these issues in t7004 and t7030 reveals that "git tag -v"
and "git verify-tag" with their --format option do not work as the
test was expecting originally. Instead of showing both valid tags
and tags with incorrect signatures on their output, tags that do not
pass verification are omitted from the output. Another breakage that
is uncovered is that these tests must be restricted to environment
where gpg is available.
Arguably, that is a safer behaviour, and because the format
specifiers like %(tag) do not have a way to show if the signature
verifies correctly, the command with the --format option cannot be
used to get a list of tags annotated with their signature validity
anyway.
For now, let's fix the here-doc syntax, update the expectation to
match the reality, and update the test prerequisite.
Maybe later when we extend the --format language available to "git
tag -v" and "git verify-tag" to include things like "%(gpg:status)",
we may want to change the behaviour so that piping a list of tag
names into
xargs git verify-tag --format='%(gpg:status) %(tag)'
becomes a good way to produce such a list, but that is a separate
topic.
Noticed-by: Jan Palus <jan.palus@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Santiago Torres <santiago@nyu.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-23 23:28:47 +01:00
|
|
|
test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
|
2017-01-18 00:37:22 +01:00
|
|
|
test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty actual-forged
|
2017-01-18 00:37:22 +01:00
|
|
|
'
|
|
|
|
|
2015-06-22 01:14:37 +02:00
|
|
|
test_done
|