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 . $(dirname "$0")/test-lib.sh || exit 1
10 ##################################################
14 test_begin_subtest "emacs delivery of signed message"
17 "test signed message 001" \
18 "This is a test signed message." \
19 "(mml-secure-message-sign)"'
21 test_begin_subtest "signed part content-type indexing"
22 output=$(notmuch search mimetype:multipart/signed and mimetype:application/pgp-signature | notmuch_search_sanitize)
23 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test signed message 001 (inbox signed)"
25 test_begin_subtest "signature verification"
26 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
27 | notmuch_json_show_sanitize \
28 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
29 expected='[[[{"id": "XXXXX",
32 "filename": ["YYYYY"],
33 "timestamp": 946728000,
34 "date_relative": "2000-01-01",
35 "tags": ["inbox","signed"],
36 "headers": {"Subject": "test signed message 001",
37 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
38 "To": "test_suite@notmuchmail.org",
39 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
41 "sigstatus": [{"status": "good",
42 "fingerprint": "'$FINGERPRINT'",
43 "created": 946728000}],
44 "content-type": "multipart/signed",
46 "content-type": "text/plain",
47 "content": "This is a test signed message.\n"},
49 "content-type": "application/pgp-signature",
50 "content-length": "NONZERO"}]}]},
52 test_expect_equal_json \
56 test_begin_subtest "detection of modified signed contents"
58 "bad signed message 001" \
59 "Incriminating stuff. This is a test signed message." \
60 "(mml-secure-message-sign)"
62 file=$(notmuch search --output=files subject:"bad signed message 001")
64 sed -i 's/Incriminating stuff. //' ${file}
66 output=$(notmuch show --format=json --verify subject:"bad signed message 001" \
67 | notmuch_json_show_sanitize \
68 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
69 expected='[[[{"id": "XXXXX",
72 "filename": ["YYYYY"],
73 "timestamp": 946728000,
74 "date_relative": "2000-01-01",
75 "tags": ["inbox","signed"],
76 "headers": {"Subject": "bad signed message 001",
77 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
78 "To": "test_suite@notmuchmail.org",
79 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
81 "sigstatus": [{"status": "bad",
82 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}],
83 "content-type": "multipart/signed",
85 "content-type": "text/plain",
86 "content": "This is a test signed message.\n"},
88 "content-type": "application/pgp-signature",
89 "content-length": "NONZERO"}]}]},
91 test_expect_equal_json \
95 test_begin_subtest "corrupted pgp/mime signature"
97 "bad signed message 002" \
98 "Incriminating stuff. This is a test signed message." \
99 "(mml-secure-message-sign)"
101 file=$(notmuch search --output=files subject:"bad signed message 002")
103 awk '/-----BEGIN PGP SIGNATURE-----/{flag=1;print;next} \
104 /-----END PGP SIGNATURE-----/{flag=0;print;next} \
105 flag{gsub(/[A-Za-z]/,"0");print}!flag{print}' $file > $file.new
110 output=$(notmuch show --format=json --verify subject:"bad signed message 002" \
111 | notmuch_json_show_sanitize \
112 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
113 expected='[[[{"id": "XXXXX",
116 "filename": ["YYYYY"],
117 "timestamp": 946728000,
118 "date_relative": "2000-01-01",
119 "tags": ["inbox","signed"],
120 "headers": {"Subject": "bad signed message 002",
121 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
122 "To": "test_suite@notmuchmail.org",
123 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
126 "content-type": "multipart/signed",
127 "content": [{"id": 2,
128 "content-type": "text/plain",
129 "content": "Incriminating stuff. This is a test signed message.\n"},
131 "content-type": "application/pgp-signature",
132 "content-length": "NONZERO"}]}]},
134 test_expect_equal_json \
138 test_begin_subtest "signature verification with full owner trust"
139 # give the key full owner trust
140 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
141 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
142 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
143 | notmuch_json_show_sanitize \
144 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
145 expected='[[[{"id": "XXXXX",
148 "filename": ["YYYYY"],
149 "timestamp": 946728000,
150 "date_relative": "2000-01-01",
151 "tags": ["inbox","signed"],
152 "headers": {"Subject": "test signed message 001",
153 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
154 "To": "test_suite@notmuchmail.org",
155 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
157 "sigstatus": [{"status": "good",
158 "fingerprint": "'$FINGERPRINT'",
159 "created": 946728000,
160 "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
161 "content-type": "multipart/signed",
162 "content": [{"id": 2,
163 "content-type": "text/plain",
164 "content": "This is a test signed message.\n"},
166 "content-type": "application/pgp-signature",
167 "content-length": "NONZERO"}]}]},
169 test_expect_equal_json \
173 test_begin_subtest "signature verification with signer key unavailable"
174 # move the gnupghome temporarily out of the way
175 mv "${GNUPGHOME}"{,.bak}
176 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
177 | notmuch_json_show_sanitize \
178 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
179 expected='[[[{"id": "XXXXX",
182 "filename": ["YYYYY"],
183 "timestamp": 946728000,
184 "date_relative": "2000-01-01",
185 "tags": ["inbox","signed"],
186 "headers": {"Subject": "test signed message 001",
187 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
188 "To": "test_suite@notmuchmail.org",
189 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
191 "sigstatus": [{"status": "error",
192 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
193 "errors": {"key-missing": true}}],
194 "content-type": "multipart/signed",
195 "content": [{"id": 2,
196 "content-type": "text/plain",
197 "content": "This is a test signed message.\n"},
199 "content-type": "application/pgp-signature",
200 "content-length": "NONZERO"}]}]},
202 test_expect_equal_json \
205 mv "${GNUPGHOME}"{.bak,}
207 test_begin_subtest "emacs delivery of encrypted message with attachment"
208 # create a test encrypted message with attachment
209 cat <<EOF >TESTATTACHMENT
212 test_expect_success \
214 "test encrypted message 001" \
215 "This is a test encrypted message.\n" \
216 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
218 test_begin_subtest "encrypted part content-type indexing"
219 output=$(notmuch search mimetype:multipart/encrypted and mimetype:application/pgp-encrypted and mimetype:application/octet-stream | notmuch_search_sanitize)
220 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
222 test_begin_subtest "decryption, --format=text"
223 output=$(notmuch show --format=text --decrypt=true subject:"test encrypted message 001" \
224 | notmuch_show_sanitize_all \
225 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
226 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
228 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
229 Subject: test encrypted message 001
230 From: Notmuch Test Suite <test_suite@notmuchmail.org>
231 To: test_suite@notmuchmail.org
232 Date: Sat, 01 Jan 2000 12:00:00 +0000
235 \fpart{ ID: 1, Content-type: multipart/encrypted
236 \fpart{ ID: 2, Content-type: application/pgp-encrypted
237 Non-text part: application/pgp-encrypted
239 \fpart{ ID: 3, Content-type: multipart/mixed
240 \fpart{ ID: 4, Content-type: text/plain
241 This is a test encrypted message.
243 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
244 Non-text part: application/octet-stream
254 test_begin_subtest "decryption, --format=json"
255 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
256 | notmuch_json_show_sanitize \
257 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
258 expected='[[[{"id": "XXXXX",
261 "filename": ["YYYYY"],
262 "timestamp": 946728000,
263 "date_relative": "2000-01-01",
264 "tags": ["encrypted","inbox"],
265 "headers": {"Subject": "test encrypted message 001",
266 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
267 "To": "test_suite@notmuchmail.org",
268 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
270 "encstatus": [{"status": "good"}],
271 "content-type": "multipart/encrypted",
272 "content": [{"id": 2,
273 "content-type": "application/pgp-encrypted",
274 "content-length": "NONZERO"},
276 "content-type": "multipart/mixed",
277 "content": [{"id": 4,
278 "content-type": "text/plain",
279 "content": "This is a test encrypted message.\n"},
281 "content-type": "application/octet-stream",
282 "content-disposition": "attachment",
283 "content-length": "NONZERO",
284 "content-transfer-encoding": "base64",
285 "filename": "TESTATTACHMENT"}]}]}]},
287 test_expect_equal_json \
291 test_begin_subtest "decryption, --format=json, --part=4"
292 output=$(notmuch show --format=json --part=4 --decrypt=true subject:"test encrypted message 001" \
293 | notmuch_json_show_sanitize \
294 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
296 "content-type": "text/plain",
297 "content": "This is a test encrypted message.\n"}'
298 test_expect_equal_json \
302 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
307 subject:"test encrypted message 001" >OUTPUT
308 test_expect_equal_file TESTATTACHMENT OUTPUT
310 test_begin_subtest "decryption failure with missing key"
311 mv "${GNUPGHOME}"{,.bak}
312 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
313 | notmuch_json_show_sanitize \
314 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
315 expected='[[[{"id": "XXXXX",
318 "filename": ["YYYYY"],
319 "timestamp": 946728000,
320 "date_relative": "2000-01-01",
321 "tags": ["encrypted","inbox"],
322 "headers": {"Subject": "test encrypted message 001",
323 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
324 "To": "test_suite@notmuchmail.org",
325 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
327 "encstatus": [{"status": "bad"}],
328 "content-type": "multipart/encrypted",
329 "content": [{"id": 2,
330 "content-type": "application/pgp-encrypted",
331 "content-length": "NONZERO"},
333 "content-type": "application/octet-stream",
334 "content-length": "NONZERO"}]}]},
336 test_expect_equal_json \
339 mv "${GNUPGHOME}"{.bak,}
341 test_begin_subtest "emacs delivery of encrypted + signed message"
342 test_expect_success \
344 "test encrypted message 002" \
345 "This is another test encrypted message.\n" \
346 "(mml-secure-message-sign-encrypt)"'
348 test_begin_subtest "decryption + signature verification"
349 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 002" \
350 | notmuch_json_show_sanitize \
351 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
352 expected='[[[{"id": "XXXXX",
355 "filename": ["YYYYY"],
356 "timestamp": 946728000,
357 "date_relative": "2000-01-01",
358 "tags": ["encrypted","inbox"],
359 "headers": {"Subject": "test encrypted message 002",
360 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
361 "To": "test_suite@notmuchmail.org",
362 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
364 "encstatus": [{"status": "good"}],
365 "sigstatus": [{"status": "good",
366 "fingerprint": "'$FINGERPRINT'",
367 "created": 946728000,
368 "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
369 "content-type": "multipart/encrypted",
370 "content": [{"id": 2,
371 "content-type": "application/pgp-encrypted",
372 "content-length": "NONZERO"},
374 "content-type": "text/plain",
375 "content": "This is another test encrypted message.\n"}]}]},
377 test_expect_equal_json \
381 test_begin_subtest "reply to encrypted message"
382 output=$(notmuch reply --decrypt=true subject:"test encrypted message 002" \
383 | notmuch_drop_mail_headers In-Reply-To References)
384 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
385 Subject: Re: test encrypted message 002
386 To: test_suite@notmuchmail.org
388 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
389 > This is another test encrypted message.'
394 test_begin_subtest "Reply within emacs to an encrypted message"
395 test_emacs "(let ((message-hidden-headers '())
396 (notmuch-crypto-process-mime 't))
397 (notmuch-show \"subject:test.encrypted.message.002\")
400 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' < OUTPUT > OUTPUT.clean
402 From: Notmuch Test Suite <test_suite@notmuchmail.org>
403 To: test_suite@notmuchmail.org
404 Subject: Re: test encrypted message 002
405 --text follows this line--
406 <#secure method=pgpmime mode=signencrypt>
407 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
409 > This is another test encrypted message.
411 test_expect_equal_file EXPECTED OUTPUT.clean
413 test_begin_subtest "signature verification with revoked key"
414 # generate revocation certificate and load it to revoke key
417 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
422 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
423 | gpg --no-tty --quiet --import
424 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
425 | notmuch_json_show_sanitize \
426 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
427 expected='[[[{"id": "XXXXX",
430 "filename": ["YYYYY"],
431 "timestamp": 946728000,
432 "date_relative": "2000-01-01",
433 "tags": ["inbox","signed"],
434 "headers": {"Subject": "test signed message 001",
435 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
436 "To": "test_suite@notmuchmail.org",
437 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
439 "sigstatus": [{"status": "error",
440 "keyid": "6D92612D94E46381",
441 "errors": {"key-revoked": true}}],
442 "content-type": "multipart/signed",
443 "content": [{"id": 2,
444 "content-type": "text/plain",
445 "content": "This is a test signed message.\n"},
447 "content-type": "application/pgp-signature",
448 "content-length": "NONZERO"}]}]},
450 test_expect_equal_json \