4 # - decryption/verification with signer key not available
5 # - verification of signatures from expired/revoked keys
7 test_description='PGP/MIME signature verification and decryption'
8 . ./test-lib.sh || exit 1
13 [ -d ${GNUPGHOME} ] && return
14 _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
15 at_exit_function _gnupg_exit
16 mkdir -m 0700 "$GNUPGHOME"
17 gpg --no-tty --import <$TEST_DIRECTORY/gnupg-secret-key.asc >"$GNUPGHOME"/import.log 2>&1
18 test_debug "cat $GNUPGHOME/import.log"
19 if (gpg --quick-random --version >/dev/null 2>&1) ; then
20 echo quick-random >> "$GNUPGHOME"/gpg.conf
21 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
22 echo debug-quick-random >> "$GNUPGHOME"/gpg.conf
24 echo no-emit-version >> "$GNUPGHOME"/gpg.conf
27 ##################################################
30 # Change this if we ship a new test key
31 FINGERPRINT="5AEAB11F5E33DCE875DDB75B6D92612D94E46381"
33 test_begin_subtest "emacs delivery of signed message"
36 "test signed message 001" \
37 "This is a test signed message." \
38 "(mml-secure-message-sign)"'
40 test_begin_subtest "signed part content-type indexing"
41 output=$(notmuch search mimetype:multipart/signed and mimetype:application/pgp-signature | notmuch_search_sanitize)
42 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test signed message 001 (inbox signed)"
44 test_begin_subtest "signature verification"
45 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
46 | notmuch_json_show_sanitize \
47 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
48 expected='[[[{"id": "XXXXX",
51 "filename": ["YYYYY"],
52 "timestamp": 946728000,
53 "date_relative": "2000-01-01",
54 "tags": ["inbox","signed"],
55 "headers": {"Subject": "test signed message 001",
56 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
57 "To": "test_suite@notmuchmail.org",
58 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
60 "sigstatus": [{"status": "good",
61 "fingerprint": "'$FINGERPRINT'",
62 "created": 946728000}],
63 "content-type": "multipart/signed",
65 "content-type": "text/plain",
66 "content": "This is a test signed message.\n"},
68 "content-type": "application/pgp-signature",
69 "content-length": "NONZERO"}]}]},
71 test_expect_equal_json \
75 test_begin_subtest "detection of modified signed contents"
77 "bad signed message 001" \
78 "Incriminating stuff. This is a test signed message." \
79 "(mml-secure-message-sign)"
81 file=$(notmuch search --output=files subject:"bad signed message 001")
83 sed -i 's/Incriminating stuff. //' ${file}
85 output=$(notmuch show --format=json --verify subject:"bad signed message 001" \
86 | notmuch_json_show_sanitize \
87 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
88 expected='[[[{"id": "XXXXX",
91 "filename": ["YYYYY"],
92 "timestamp": 946728000,
93 "date_relative": "2000-01-01",
94 "tags": ["inbox","signed"],
95 "headers": {"Subject": "bad signed message 001",
96 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
97 "To": "test_suite@notmuchmail.org",
98 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
100 "sigstatus": [{"status": "bad",
101 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}],
102 "content-type": "multipart/signed",
103 "content": [{"id": 2,
104 "content-type": "text/plain",
105 "content": "This is a test signed message.\n"},
107 "content-type": "application/pgp-signature",
108 "content-length": "NONZERO"}]}]},
110 test_expect_equal_json \
114 test_begin_subtest "corrupted pgp/mime signature"
116 "bad signed message 002" \
117 "Incriminating stuff. This is a test signed message." \
118 "(mml-secure-message-sign)"
120 file=$(notmuch search --output=files subject:"bad signed message 002")
122 awk '/-----BEGIN PGP SIGNATURE-----/{flag=1;print;next} \
123 /-----END PGP SIGNATURE-----/{flag=0;print;next} \
124 flag{gsub(/[A-Za-z]/,"0");print}!flag{print}' $file > $file.new
129 output=$(notmuch show --format=json --verify subject:"bad signed message 002" \
130 | notmuch_json_show_sanitize \
131 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
132 expected='[[[{"id": "XXXXX",
135 "filename": ["YYYYY"],
136 "timestamp": 946728000,
137 "date_relative": "2000-01-01",
138 "tags": ["inbox","signed"],
139 "headers": {"Subject": "bad signed message 002",
140 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
141 "To": "test_suite@notmuchmail.org",
142 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
145 "content-type": "multipart/signed",
146 "content": [{"id": 2,
147 "content-type": "text/plain",
148 "content": "Incriminating stuff. This is a test signed message.\n"},
150 "content-type": "application/pgp-signature",
151 "content-length": "NONZERO"}]}]},
153 test_expect_equal_json \
157 test_begin_subtest "signature verification with full owner trust"
158 test_subtest_broken_gmime_2
159 # give the key full owner trust
160 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
161 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
162 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
163 | notmuch_json_show_sanitize \
164 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
165 expected='[[[{"id": "XXXXX",
168 "filename": ["YYYYY"],
169 "timestamp": 946728000,
170 "date_relative": "2000-01-01",
171 "tags": ["inbox","signed"],
172 "headers": {"Subject": "test signed message 001",
173 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
174 "To": "test_suite@notmuchmail.org",
175 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
177 "sigstatus": [{"status": "good",
178 "fingerprint": "'$FINGERPRINT'",
179 "created": 946728000,
180 "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
181 "content-type": "multipart/signed",
182 "content": [{"id": 2,
183 "content-type": "text/plain",
184 "content": "This is a test signed message.\n"},
186 "content-type": "application/pgp-signature",
187 "content-length": "NONZERO"}]}]},
189 test_expect_equal_json \
193 test_begin_subtest "signature verification with signer key unavailable"
194 # move the gnupghome temporarily out of the way
195 mv "${GNUPGHOME}"{,.bak}
196 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
197 | notmuch_json_show_sanitize \
198 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
199 expected='[[[{"id": "XXXXX",
202 "filename": ["YYYYY"],
203 "timestamp": 946728000,
204 "date_relative": "2000-01-01",
205 "tags": ["inbox","signed"],
206 "headers": {"Subject": "test signed message 001",
207 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
208 "To": "test_suite@notmuchmail.org",
209 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
211 "sigstatus": [{"status": "error",
212 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
213 "errors": {"key-missing": true}}],
214 "content-type": "multipart/signed",
215 "content": [{"id": 2,
216 "content-type": "text/plain",
217 "content": "This is a test signed message.\n"},
219 "content-type": "application/pgp-signature",
220 "content-length": "NONZERO"}]}]},
222 test_expect_equal_json \
225 mv "${GNUPGHOME}"{.bak,}
227 test_begin_subtest "emacs delivery of encrypted message with attachment"
228 # create a test encrypted message with attachment
229 cat <<EOF >TESTATTACHMENT
232 test_expect_success \
234 "test encrypted message 001" \
235 "This is a test encrypted message.\n" \
236 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
238 test_begin_subtest "encrypted part content-type indexing"
239 output=$(notmuch search mimetype:multipart/encrypted and mimetype:application/pgp-encrypted and mimetype:application/octet-stream | notmuch_search_sanitize)
240 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
242 test_begin_subtest "decryption, --format=text"
243 output=$(notmuch show --format=text --decrypt subject:"test encrypted message 001" \
244 | notmuch_show_sanitize_all \
245 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
246 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
248 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
249 Subject: test encrypted message 001
250 From: Notmuch Test Suite <test_suite@notmuchmail.org>
251 To: test_suite@notmuchmail.org
252 Date: Sat, 01 Jan 2000 12:00:00 +0000
255 \fpart{ ID: 1, Content-type: multipart/encrypted
256 \fpart{ ID: 2, Content-type: application/pgp-encrypted
257 Non-text part: application/pgp-encrypted
259 \fpart{ ID: 3, Content-type: multipart/mixed
260 \fpart{ ID: 4, Content-type: text/plain
261 This is a test encrypted message.
263 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
264 Non-text part: application/octet-stream
274 test_begin_subtest "decryption, --format=json"
275 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
276 | notmuch_json_show_sanitize \
277 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
278 expected='[[[{"id": "XXXXX",
281 "filename": ["YYYYY"],
282 "timestamp": 946728000,
283 "date_relative": "2000-01-01",
284 "tags": ["encrypted","inbox"],
285 "headers": {"Subject": "test encrypted message 001",
286 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
287 "To": "test_suite@notmuchmail.org",
288 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
290 "encstatus": [{"status": "good"}],
292 "content-type": "multipart/encrypted",
293 "content": [{"id": 2,
294 "content-type": "application/pgp-encrypted",
295 "content-length": "NONZERO"},
297 "content-type": "multipart/mixed",
298 "content": [{"id": 4,
299 "content-type": "text/plain",
300 "content": "This is a test encrypted message.\n"},
302 "content-type": "application/octet-stream",
303 "content-disposition": "attachment",
304 "content-length": "NONZERO",
305 "content-transfer-encoding": "base64",
306 "filename": "TESTATTACHMENT"}]}]}]},
308 test_expect_equal_json \
312 test_begin_subtest "decryption, --format=json, --part=4"
313 output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
314 | notmuch_json_show_sanitize \
315 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
317 "content-type": "text/plain",
318 "content": "This is a test encrypted message.\n"}'
319 test_expect_equal_json \
323 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
328 subject:"test encrypted message 001" >OUTPUT
329 test_expect_equal_file TESTATTACHMENT OUTPUT
331 test_begin_subtest "decryption failure with missing key"
332 mv "${GNUPGHOME}"{,.bak}
333 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
334 | notmuch_json_show_sanitize \
335 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
336 expected='[[[{"id": "XXXXX",
339 "filename": ["YYYYY"],
340 "timestamp": 946728000,
341 "date_relative": "2000-01-01",
342 "tags": ["encrypted","inbox"],
343 "headers": {"Subject": "test encrypted message 001",
344 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
345 "To": "test_suite@notmuchmail.org",
346 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
348 "encstatus": [{"status": "bad"}],
349 "content-type": "multipart/encrypted",
350 "content": [{"id": 2,
351 "content-type": "application/pgp-encrypted",
352 "content-length": "NONZERO"},
354 "content-type": "application/octet-stream",
355 "content-length": "NONZERO"}]}]},
357 test_expect_equal_json \
360 mv "${GNUPGHOME}"{.bak,}
362 test_begin_subtest "emacs delivery of encrypted + signed message"
363 test_expect_success \
365 "test encrypted message 002" \
366 "This is another test encrypted message.\n" \
367 "(mml-secure-message-sign-encrypt)"'
369 test_begin_subtest "decryption + signature verification"
370 test_subtest_broken_gmime_2
371 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
372 | notmuch_json_show_sanitize \
373 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
374 expected='[[[{"id": "XXXXX",
377 "filename": ["YYYYY"],
378 "timestamp": 946728000,
379 "date_relative": "2000-01-01",
380 "tags": ["encrypted","inbox"],
381 "headers": {"Subject": "test encrypted message 002",
382 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
383 "To": "test_suite@notmuchmail.org",
384 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
386 "encstatus": [{"status": "good"}],
387 "sigstatus": [{"status": "good",
388 "fingerprint": "'$FINGERPRINT'",
389 "created": 946728000,
390 "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
391 "content-type": "multipart/encrypted",
392 "content": [{"id": 2,
393 "content-type": "application/pgp-encrypted",
394 "content-length": "NONZERO"},
396 "content-type": "text/plain",
397 "content": "This is another test encrypted message.\n"}]}]},
399 test_expect_equal_json \
403 test_begin_subtest "reply to encrypted message"
404 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
405 | notmuch_drop_mail_headers In-Reply-To References)
406 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
407 Subject: Re: test encrypted message 002
409 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
410 > This is another test encrypted message.'
415 test_begin_subtest "Reply within emacs to an encrypted message"
416 test_emacs "(let ((message-hidden-headers '())
417 (notmuch-crypto-process-mime 't))
418 (notmuch-show \"subject:test.encrypted.message.002\")
421 # the empty To: is probably a bug, but it's not to do with encryption
422 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' -e 'To:' < OUTPUT > OUTPUT.clean
424 From: Notmuch Test Suite <test_suite@notmuchmail.org>
425 Subject: Re: test encrypted message 002
426 --text follows this line--
427 <#secure method=pgpmime mode=signencrypt>
428 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
430 > This is another test encrypted message.
432 test_expect_equal_file EXPECTED OUTPUT.clean
434 test_begin_subtest "signature verification with revoked key"
435 # generate revocation certificate and load it to revoke key
438 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
443 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
444 | gpg --no-tty --quiet --import
445 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
446 | notmuch_json_show_sanitize \
447 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
448 expected='[[[{"id": "XXXXX",
451 "filename": ["YYYYY"],
452 "timestamp": 946728000,
453 "date_relative": "2000-01-01",
454 "tags": ["inbox","signed"],
455 "headers": {"Subject": "test signed message 001",
456 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
457 "To": "test_suite@notmuchmail.org",
458 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
460 "sigstatus": [{"status": "error",
461 "keyid": "6D92612D94E46381",
462 "errors": {"key-revoked": true}}],
463 "content-type": "multipart/signed",
464 "content": [{"id": 2,
465 "content-type": "text/plain",
466 "content": "This is a test signed message.\n"},
468 "content-type": "application/pgp-signature",
469 "content-length": "NONZERO"}]}]},
471 test_expect_equal_json \