]>
Commit | Line | Data |
---|---|---|
247503f2 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='signed commit tests' | |
4 | . ./test-lib.sh | |
661a1806 | 5 | GNUPGHOME_NOT_USED=$GNUPGHOME |
247503f2 JH |
6 | . "$TEST_DIRECTORY/lib-gpg.sh" |
7 | ||
8 | test_expect_success GPG 'create signed commits' ' | |
4b8d14b4 NV |
9 | test_when_finished "test_unconfig commit.gpgsign" && |
10 | ||
247503f2 JH |
11 | echo 1 >file && git add file && |
12 | test_tick && git commit -S -m initial && | |
13 | git tag initial && | |
14 | git branch side && | |
15 | ||
16 | echo 2 >file && test_tick && git commit -a -S -m second && | |
17 | git tag second && | |
18 | ||
19 | git checkout side && | |
20 | echo 3 >elif && git add elif && | |
21 | test_tick && git commit -m "third on side" && | |
22 | ||
23 | git checkout master && | |
24 | test_tick && git merge -S side && | |
25 | git tag merge && | |
26 | ||
27 | echo 4 >file && test_tick && git commit -a -m "fourth unsigned" && | |
28 | git tag fourth-unsigned && | |
29 | ||
c871a1d1 | 30 | test_tick && git commit --amend -S -m "fourth signed" && |
4b8d14b4 NV |
31 | git tag fourth-signed && |
32 | ||
33 | git config commit.gpgsign true && | |
34 | echo 5 >file && test_tick && git commit -a -m "fifth signed" && | |
35 | git tag fifth-signed && | |
36 | ||
37 | git config commit.gpgsign false && | |
38 | echo 6 >file && test_tick && git commit -a -m "sixth" && | |
39 | git tag sixth-unsigned && | |
40 | ||
41 | git config commit.gpgsign true && | |
42 | echo 7 >file && test_tick && git commit -a -m "seventh" --no-gpg-sign && | |
43 | git tag seventh-unsigned && | |
44 | ||
45 | test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ && | |
99094a7a | 46 | git tag seventh-signed && |
4baf839f JK |
47 | |
48 | echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 && | |
66948561 JH |
49 | git tag eighth-signed-alt && |
50 | ||
51 | # commit.gpgsign is still on but this must not be signed | |
41a74bd0 MÅ |
52 | echo 9 | git commit-tree HEAD^{tree} >oid && |
53 | test_line_count = 1 oid && | |
54 | git tag ninth-unsigned $(cat oid) && | |
66948561 | 55 | # explicit -S of course must sign. |
41a74bd0 MÅ |
56 | echo 10 | git commit-tree -S HEAD^{tree} >oid && |
57 | test_line_count = 1 oid && | |
70ddbd77 BR |
58 | git tag tenth-signed $(cat oid) && |
59 | ||
60 | # --gpg-sign[=<key-id>] must sign. | |
61 | echo 11 | git commit-tree --gpg-sign HEAD^{tree} >oid && | |
62 | test_line_count = 1 oid && | |
63 | git tag eleventh-signed $(cat oid) && | |
64 | echo 12 | git commit-tree --gpg-sign=B7227189 HEAD^{tree} >oid && | |
65 | test_line_count = 1 oid && | |
66 | git tag twelfth-signed-alt $(cat oid) | |
247503f2 JH |
67 | ' |
68 | ||
8e92c2cf | 69 | test_expect_success GPG 'verify and show signatures' ' |
247503f2 | 70 | ( |
66948561 | 71 | for commit in initial second merge fourth-signed \ |
70ddbd77 BR |
72 | fifth-signed sixth-signed seventh-signed tenth-signed \ |
73 | eleventh-signed | |
247503f2 | 74 | do |
8e92c2cf | 75 | git verify-commit $commit && |
247503f2 | 76 | git show --pretty=short --show-signature $commit >actual && |
7b1732c1 MG |
77 | grep "Good signature from" actual && |
78 | ! grep "BAD signature from" actual && | |
79 | echo $commit OK || exit 1 | |
247503f2 JH |
80 | done |
81 | ) && | |
82 | ( | |
66948561 JH |
83 | for commit in merge^2 fourth-unsigned sixth-unsigned \ |
84 | seventh-unsigned ninth-unsigned | |
247503f2 | 85 | do |
8e92c2cf | 86 | test_must_fail git verify-commit $commit && |
247503f2 | 87 | git show --pretty=short --show-signature $commit >actual && |
7b1732c1 MG |
88 | ! grep "Good signature from" actual && |
89 | ! grep "BAD signature from" actual && | |
90 | echo $commit OK || exit 1 | |
4baf839f JK |
91 | done |
92 | ) && | |
93 | ( | |
70ddbd77 | 94 | for commit in eighth-signed-alt twelfth-signed-alt |
4baf839f JK |
95 | do |
96 | git show --pretty=short --show-signature $commit >actual && | |
97 | grep "Good signature from" actual && | |
98 | ! grep "BAD signature from" actual && | |
99 | grep "not certified" actual && | |
100 | echo $commit OK || exit 1 | |
247503f2 JH |
101 | done |
102 | ) | |
103 | ' | |
104 | ||
434060ec | 105 | test_expect_success GPG 'verify-commit exits success on untrusted signature' ' |
8e98e5f2 | 106 | git verify-commit eighth-signed-alt 2>actual && |
107 | grep "Good signature from" actual && | |
108 | ! grep "BAD signature from" actual && | |
109 | grep "not certified" actual | |
110 | ' | |
111 | ||
aeff29dd | 112 | test_expect_success GPG 'verify signatures with --raw' ' |
113 | ( | |
114 | for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed | |
115 | do | |
116 | git verify-commit --raw $commit 2>actual && | |
117 | grep "GOODSIG" actual && | |
118 | ! grep "BADSIG" actual && | |
119 | echo $commit OK || exit 1 | |
120 | done | |
121 | ) && | |
122 | ( | |
123 | for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned | |
124 | do | |
125 | test_must_fail git verify-commit --raw $commit 2>actual && | |
126 | ! grep "GOODSIG" actual && | |
127 | ! grep "BADSIG" actual && | |
128 | echo $commit OK || exit 1 | |
129 | done | |
130 | ) && | |
131 | ( | |
132 | for commit in eighth-signed-alt | |
133 | do | |
134 | git verify-commit --raw $commit 2>actual && | |
135 | grep "GOODSIG" actual && | |
136 | ! grep "BADSIG" actual && | |
137 | grep "TRUST_UNDEFINED" actual && | |
138 | echo $commit OK || exit 1 | |
139 | done | |
140 | ) | |
141 | ' | |
142 | ||
8e92c2cf MG |
143 | test_expect_success GPG 'show signed commit with signature' ' |
144 | git show -s initial >commit && | |
145 | git show -s --show-signature initial >show && | |
146 | git verify-commit -v initial >verify.1 2>verify.2 && | |
147 | git cat-file commit initial >cat && | |
3f88c1b5 KM |
148 | grep -v -e "gpg: " -e "Warning: " show >show.commit && |
149 | grep -e "gpg: " -e "Warning: " show >show.gpg && | |
8e92c2cf MG |
150 | grep -v "^ " cat | grep -v "^gpgsig " >cat.commit && |
151 | test_cmp show.commit commit && | |
152 | test_cmp show.gpg verify.2 && | |
153 | test_cmp cat.commit verify.1 | |
154 | ' | |
155 | ||
247503f2 | 156 | test_expect_success GPG 'detect fudged signature' ' |
526d56e0 | 157 | git cat-file commit seventh-signed >raw && |
2f3cbcd8 | 158 | sed -e "s/^seventh/7th forged/" raw >forged1 && |
247503f2 | 159 | git hash-object -w -t commit forged1 >forged1.commit && |
9dd39821 | 160 | test_must_fail git verify-commit $(cat forged1.commit) && |
247503f2 JH |
161 | git show --pretty=short --show-signature $(cat forged1.commit) >actual1 && |
162 | grep "BAD signature from" actual1 && | |
163 | ! grep "Good signature from" actual1 | |
164 | ' | |
165 | ||
166 | test_expect_success GPG 'detect fudged signature with NUL' ' | |
526d56e0 | 167 | git cat-file commit seventh-signed >raw && |
247503f2 JH |
168 | cat raw >forged2 && |
169 | echo Qwik | tr "Q" "\000" >>forged2 && | |
170 | git hash-object -w -t commit forged2 >forged2.commit && | |
9dd39821 | 171 | test_must_fail git verify-commit $(cat forged2.commit) && |
247503f2 JH |
172 | git show --pretty=short --show-signature $(cat forged2.commit) >actual2 && |
173 | grep "BAD signature from" actual2 && | |
174 | ! grep "Good signature from" actual2 | |
175 | ' | |
176 | ||
c871a1d1 JH |
177 | test_expect_success GPG 'amending already signed commit' ' |
178 | git checkout fourth-signed^0 && | |
179 | git commit --amend -S --no-edit && | |
8e92c2cf | 180 | git verify-commit HEAD && |
c871a1d1 JH |
181 | git show -s --show-signature HEAD >actual && |
182 | grep "Good signature from" actual && | |
183 | ! grep "BAD signature from" actual | |
184 | ' | |
185 | ||
06ca0f45 JK |
186 | test_expect_success GPG 'show good signature with custom format' ' |
187 | cat >expect <<-\EOF && | |
188 | G | |
189 | 13B6F51ECDDE430D | |
190 | C O Mitter <committer@example.com> | |
3daaaabe | 191 | 73D758744BE721698EC54E8713B6F51ECDDE430D |
1a550529 | 192 | 73D758744BE721698EC54E8713B6F51ECDDE430D |
06ca0f45 | 193 | EOF |
1a550529 | 194 | git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" sixth-signed >actual && |
06ca0f45 JK |
195 | test_cmp expect actual |
196 | ' | |
197 | ||
198 | test_expect_success GPG 'show bad signature with custom format' ' | |
199 | cat >expect <<-\EOF && | |
200 | B | |
201 | 13B6F51ECDDE430D | |
202 | C O Mitter <committer@example.com> | |
3daaaabe | 203 | |
1a550529 | 204 | |
06ca0f45 | 205 | EOF |
1a550529 | 206 | git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" $(cat forged1.commit) >actual && |
06ca0f45 JK |
207 | test_cmp expect actual |
208 | ' | |
209 | ||
661a1806 | 210 | test_expect_success GPG 'show untrusted signature with custom format' ' |
06ca0f45 JK |
211 | cat >expect <<-\EOF && |
212 | U | |
1e690847 | 213 | 65A0EEA02E30CAD7 |
06ca0f45 | 214 | Eris Discordia <discord@example.net> |
1e690847 | 215 | F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7 |
1a550529 | 216 | D4BE22311AD3131E5EDA29A461092E85B7227189 |
06ca0f45 | 217 | EOF |
1a550529 | 218 | git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" eighth-signed-alt >actual && |
06ca0f45 JK |
219 | test_cmp expect actual |
220 | ' | |
221 | ||
661a1806 MG |
222 | test_expect_success GPG 'show unknown signature with custom format' ' |
223 | cat >expect <<-\EOF && | |
224 | E | |
1e690847 | 225 | 65A0EEA02E30CAD7 |
661a1806 | 226 | |
3daaaabe | 227 | |
1a550529 | 228 | |
661a1806 | 229 | EOF |
1a550529 | 230 | GNUPGHOME="$GNUPGHOME_NOT_USED" git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" eighth-signed-alt >actual && |
661a1806 MG |
231 | test_cmp expect actual |
232 | ' | |
233 | ||
06ca0f45 JK |
234 | test_expect_success GPG 'show lack of signature with custom format' ' |
235 | cat >expect <<-\EOF && | |
236 | N | |
237 | ||
238 | ||
3daaaabe | 239 | |
1a550529 | 240 | |
06ca0f45 | 241 | EOF |
1a550529 | 242 | git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" seventh-unsigned >actual && |
06ca0f45 JK |
243 | test_cmp expect actual |
244 | ' | |
245 | ||
fce04c3c MJ |
246 | test_expect_success GPG 'log.showsignature behaves like --show-signature' ' |
247 | test_config log.showsignature true && | |
248 | git show initial >actual && | |
249 | grep "gpg: Signature made" actual && | |
250 | grep "gpg: Good signature" actual | |
251 | ' | |
252 | ||
1865a647 HS |
253 | test_expect_success GPG 'check config gpg.format values' ' |
254 | test_config gpg.format openpgp && | |
255 | git commit -S --amend -m "success" && | |
256 | test_config gpg.format OpEnPgP && | |
257 | test_must_fail git commit -S --amend -m "fail" | |
258 | ' | |
259 | ||
da6cf1b3 MG |
260 | test_expect_success GPG 'detect fudged commit with double signature' ' |
261 | sed -e "/gpgsig/,/END PGP/d" forged1 >double-base && | |
262 | sed -n -e "/gpgsig/,/END PGP/p" forged1 | \ | |
263 | sed -e "s/^gpgsig//;s/^ //" | gpg --dearmor >double-sig1.sig && | |
264 | gpg -o double-sig2.sig -u 29472784 --detach-sign double-base && | |
265 | cat double-sig1.sig double-sig2.sig | gpg --enarmor >double-combined.asc && | |
266 | sed -e "s/^\(-.*\)ARMORED FILE/\1SIGNATURE/;1s/^/gpgsig /;2,\$s/^/ /" \ | |
267 | double-combined.asc > double-gpgsig && | |
268 | sed -e "/committer/r double-gpgsig" double-base >double-commit && | |
269 | git hash-object -w -t commit double-commit >double-commit.commit && | |
270 | test_must_fail git verify-commit $(cat double-commit.commit) && | |
271 | git show --pretty=short --show-signature $(cat double-commit.commit) >double-actual && | |
272 | grep "BAD signature from" double-actual && | |
273 | grep "Good signature from" double-actual | |
274 | ' | |
275 | ||
276 | test_expect_success GPG 'show double signature with custom format' ' | |
277 | cat >expect <<-\EOF && | |
278 | E | |
279 | ||
280 | ||
3daaaabe | 281 | |
1a550529 | 282 | |
da6cf1b3 | 283 | EOF |
1a550529 | 284 | git log -1 --format="%G?%n%GK%n%GS%n%GF%n%GP" $(cat double-commit.commit) >actual && |
da6cf1b3 MG |
285 | test_cmp expect actual |
286 | ' | |
287 | ||
247503f2 | 288 | test_done |