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 test_subtest_known_broken
240 output=$(notmuch search mimetype:multipart/encrypted and mimetype:application/pgp-encrypted and mimetype:application/octet-stream | notmuch_search_sanitize)
241 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
243 test_begin_subtest "decryption, --format=text"
244 output=$(notmuch show --format=text --decrypt subject:"test encrypted message 001" \
245 | notmuch_show_sanitize_all \
246 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
247 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
249 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
250 Subject: test encrypted message 001
251 From: Notmuch Test Suite <test_suite@notmuchmail.org>
252 To: test_suite@notmuchmail.org
253 Date: Sat, 01 Jan 2000 12:00:00 +0000
256 \fpart{ ID: 1, Content-type: multipart/encrypted
257 \fpart{ ID: 2, Content-type: application/pgp-encrypted
258 Non-text part: application/pgp-encrypted
260 \fpart{ ID: 3, Content-type: multipart/mixed
261 \fpart{ ID: 4, Content-type: text/plain
262 This is a test encrypted message.
264 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
265 Non-text part: application/octet-stream
275 test_begin_subtest "decryption, --format=json"
276 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
277 | notmuch_json_show_sanitize \
278 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
279 expected='[[[{"id": "XXXXX",
282 "filename": ["YYYYY"],
283 "timestamp": 946728000,
284 "date_relative": "2000-01-01",
285 "tags": ["encrypted","inbox"],
286 "headers": {"Subject": "test encrypted message 001",
287 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
288 "To": "test_suite@notmuchmail.org",
289 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
291 "encstatus": [{"status": "good"}],
293 "content-type": "multipart/encrypted",
294 "content": [{"id": 2,
295 "content-type": "application/pgp-encrypted",
296 "content-length": "NONZERO"},
298 "content-type": "multipart/mixed",
299 "content": [{"id": 4,
300 "content-type": "text/plain",
301 "content": "This is a test encrypted message.\n"},
303 "content-type": "application/octet-stream",
304 "content-disposition": "attachment",
305 "content-length": "NONZERO",
306 "content-transfer-encoding": "base64",
307 "filename": "TESTATTACHMENT"}]}]}]},
309 test_expect_equal_json \
313 test_begin_subtest "decryption, --format=json, --part=4"
314 output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
315 | notmuch_json_show_sanitize \
316 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
318 "content-type": "text/plain",
319 "content": "This is a test encrypted message.\n"}'
320 test_expect_equal_json \
324 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
329 subject:"test encrypted message 001" >OUTPUT
330 test_expect_equal_file TESTATTACHMENT OUTPUT
332 test_begin_subtest "decryption failure with missing key"
333 mv "${GNUPGHOME}"{,.bak}
334 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
335 | notmuch_json_show_sanitize \
336 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
337 expected='[[[{"id": "XXXXX",
340 "filename": ["YYYYY"],
341 "timestamp": 946728000,
342 "date_relative": "2000-01-01",
343 "tags": ["encrypted","inbox"],
344 "headers": {"Subject": "test encrypted message 001",
345 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
346 "To": "test_suite@notmuchmail.org",
347 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
349 "encstatus": [{"status": "bad"}],
350 "content-type": "multipart/encrypted",
351 "content": [{"id": 2,
352 "content-type": "application/pgp-encrypted",
353 "content-length": "NONZERO"},
355 "content-type": "application/octet-stream",
356 "content-length": "NONZERO"}]}]},
358 test_expect_equal_json \
361 mv "${GNUPGHOME}"{.bak,}
363 test_begin_subtest "emacs delivery of encrypted + signed message"
364 test_expect_success \
366 "test encrypted message 002" \
367 "This is another test encrypted message.\n" \
368 "(mml-secure-message-sign-encrypt)"'
370 test_begin_subtest "decryption + signature verification"
371 test_subtest_broken_gmime_2
372 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
373 | notmuch_json_show_sanitize \
374 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
375 expected='[[[{"id": "XXXXX",
378 "filename": ["YYYYY"],
379 "timestamp": 946728000,
380 "date_relative": "2000-01-01",
381 "tags": ["encrypted","inbox"],
382 "headers": {"Subject": "test encrypted message 002",
383 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
384 "To": "test_suite@notmuchmail.org",
385 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
387 "encstatus": [{"status": "good"}],
388 "sigstatus": [{"status": "good",
389 "fingerprint": "'$FINGERPRINT'",
390 "created": 946728000,
391 "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
392 "content-type": "multipart/encrypted",
393 "content": [{"id": 2,
394 "content-type": "application/pgp-encrypted",
395 "content-length": "NONZERO"},
397 "content-type": "text/plain",
398 "content": "This is another test encrypted message.\n"}]}]},
400 test_expect_equal_json \
404 test_begin_subtest "reply to encrypted message"
405 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
406 | notmuch_drop_mail_headers In-Reply-To References)
407 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
408 Subject: Re: test encrypted message 002
410 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
411 > This is another test encrypted message.'
416 test_begin_subtest "Reply within emacs to an encrypted message"
417 test_emacs "(let ((message-hidden-headers '())
418 (notmuch-crypto-process-mime 't))
419 (notmuch-show \"subject:test.encrypted.message.002\")
422 # the empty To: is probably a bug, but it's not to do with encryption
423 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' -e 'To:' < OUTPUT > OUTPUT.clean
425 From: Notmuch Test Suite <test_suite@notmuchmail.org>
426 Subject: Re: test encrypted message 002
427 --text follows this line--
428 <#secure method=pgpmime mode=signencrypt>
429 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
431 > This is another test encrypted message.
433 test_expect_equal_file EXPECTED OUTPUT.clean
435 test_begin_subtest "signature verification with revoked key"
436 # generate revocation certificate and load it to revoke key
439 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
444 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
445 | gpg --no-tty --quiet --import
446 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
447 | notmuch_json_show_sanitize \
448 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
449 expected='[[[{"id": "XXXXX",
452 "filename": ["YYYYY"],
453 "timestamp": 946728000,
454 "date_relative": "2000-01-01",
455 "tags": ["inbox","signed"],
456 "headers": {"Subject": "test signed message 001",
457 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
458 "To": "test_suite@notmuchmail.org",
459 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
461 "sigstatus": [{"status": "error",
462 "keyid": "6D92612D94E46381",
463 "errors": {"key-revoked": true}}],
464 "content-type": "multipart/signed",
465 "content": [{"id": 2,
466 "content-type": "text/plain",
467 "content": "This is a test signed message.\n"},
469 "content-type": "application/pgp-signature",
470 "content-length": "NONZERO"}]}]},
472 test_expect_equal_json \