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 ##################################################
15 test_begin_subtest "emacs delivery of signed message"
18 "test signed message 001" \
19 "This is a test signed message." \
20 "(mml-secure-message-sign)"'
22 test_begin_subtest "signed part content-type indexing"
23 output=$(notmuch search mimetype:multipart/signed and mimetype:application/pgp-signature | notmuch_search_sanitize)
24 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test signed message 001 (inbox signed)"
26 test_begin_subtest "signature verification"
27 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
28 | notmuch_json_show_sanitize \
29 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
30 expected='[[[{"id": "XXXXX",
33 "filename": ["YYYYY"],
34 "timestamp": 946728000,
35 "date_relative": "2000-01-01",
36 "tags": ["inbox","signed"],
37 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'"}]}},
38 "headers": {"Subject": "test signed message 001",
39 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
40 "To": "test_suite@notmuchmail.org",
41 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
43 "sigstatus": [{"status": "good",
44 "fingerprint": "'$FINGERPRINT'",
46 "userid": "'"$SELF_USERID"'"}],
47 "content-type": "multipart/signed",
49 "content-type": "text/plain",
50 "content": "This is a test signed message.\n"},
52 "content-type": "application/pgp-signature",
53 "content-length": "NONZERO"}]}]},
55 test_expect_equal_json \
59 test_begin_subtest "detection of modified signed contents"
61 "bad signed message 001" \
62 "Incriminating stuff. This is a test signed message." \
63 "(mml-secure-message-sign)"
65 file=$(notmuch search --output=files subject:"bad signed message 001")
67 sed -i 's/Incriminating stuff. //' ${file}
69 output=$(notmuch show --format=json --verify subject:"bad signed message 001" \
70 | notmuch_json_show_sanitize \
71 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
72 expected='[[[{"id": "XXXXX",
75 "filename": ["YYYYY"],
76 "timestamp": 946728000,
77 "date_relative": "2000-01-01",
78 "tags": ["inbox","signed"],
79 "crypto": {"signed": {"status": [{ "status": "bad", "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}]}},
80 "headers": {"Subject": "bad signed message 001",
81 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
82 "To": "test_suite@notmuchmail.org",
83 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
85 "sigstatus": [{"status": "bad",
86 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}],
87 "content-type": "multipart/signed",
89 "content-type": "text/plain",
90 "content": "This is a test signed message.\n"},
92 "content-type": "application/pgp-signature",
93 "content-length": "NONZERO"}]}]},
95 test_expect_equal_json \
99 test_begin_subtest "corrupted pgp/mime signature"
101 "bad signed message 002" \
102 "Incriminating stuff. This is a test signed message." \
103 "(mml-secure-message-sign)"
105 file=$(notmuch search --output=files subject:"bad signed message 002")
107 awk '/-----BEGIN PGP SIGNATURE-----/{flag=1;print;next} \
108 /-----END PGP SIGNATURE-----/{flag=0;print;next} \
109 flag{gsub(/[A-Za-z]/,"0");print}!flag{print}' $file > $file.new
114 output=$(notmuch show --format=json --verify subject:"bad signed message 002" \
115 | notmuch_json_show_sanitize \
116 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
117 expected='[[[{"id": "XXXXX",
121 "filename": ["YYYYY"],
122 "timestamp": 946728000,
123 "date_relative": "2000-01-01",
124 "tags": ["inbox","signed"],
125 "headers": {"Subject": "bad signed message 002",
126 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
127 "To": "test_suite@notmuchmail.org",
128 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
131 "content-type": "multipart/signed",
132 "content": [{"id": 2,
133 "content-type": "text/plain",
134 "content": "Incriminating stuff. This is a test signed message.\n"},
136 "content-type": "application/pgp-signature",
137 "content-length": "NONZERO"}]}]},
139 test_expect_equal_json \
143 test_begin_subtest "signature verification without full user ID validity"
144 # give the key no owner trust, removes validity on all user IDs of the
145 # certificate in the absence of other trusted certifiers:
146 gpg --quiet --batch --no-tty --export-ownertrust > "$GNUPGHOME/ownertrust.bak"
147 echo "${FINGERPRINT}:3:" | gpg --quiet --batch --no-tty --import-ownertrust
148 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
149 | notmuch_json_show_sanitize \
150 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
151 expected='[[[{"id": "XXXXX",
154 "filename": ["YYYYY"],
155 "timestamp": 946728000,
156 "date_relative": "2000-01-01",
157 "tags": ["inbox","signed"],
158 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "fingerprint": "'$FINGERPRINT'"}]}},
159 "headers": {"Subject": "test signed message 001",
160 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
161 "To": "test_suite@notmuchmail.org",
162 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
164 "sigstatus": [{"status": "good",
165 "fingerprint": "'$FINGERPRINT'",
166 "created": 946728000}],
167 "content-type": "multipart/signed",
168 "content": [{"id": 2,
169 "content-type": "text/plain",
170 "content": "This is a test signed message.\n"},
172 "content-type": "application/pgp-signature",
173 "content-length": "NONZERO"}]}]},
175 test_expect_equal_json \
178 gpg --quiet --batch --no-tty --import-ownertrust < "$GNUPGHOME/ownertrust.bak"
180 test_begin_subtest "signature verification with signer key unavailable"
181 # move the gnupghome temporarily out of the way
182 mv "${GNUPGHOME}"{,.bak}
183 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
184 | notmuch_json_show_sanitize \
185 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
186 expected='[[[{"id": "XXXXX",
189 "filename": ["YYYYY"],
190 "timestamp": 946728000,
191 "date_relative": "2000-01-01",
192 "tags": ["inbox","signed"],
193 "crypto": {"signed": {"status": [{"errors": {"key-missing": true}, "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'", "status": "error"}]}},
194 "headers": {"Subject": "test signed message 001",
195 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
196 "To": "test_suite@notmuchmail.org",
197 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
199 "sigstatus": [{"status": "error",
200 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
201 "errors": {"key-missing": true}}],
202 "content-type": "multipart/signed",
203 "content": [{"id": 2,
204 "content-type": "text/plain",
205 "content": "This is a test signed message.\n"},
207 "content-type": "application/pgp-signature",
208 "content-length": "NONZERO"}]}]},
210 test_expect_equal_json \
213 mv "${GNUPGHOME}"{.bak,}
215 test_begin_subtest "emacs delivery of encrypted message with attachment"
216 # create a test encrypted message with attachment
217 cat <<EOF >TESTATTACHMENT
220 test_expect_success \
222 "test encrypted message 001" \
223 "This is a test encrypted message.\n" \
224 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
226 test_begin_subtest "encrypted part content-type indexing"
227 output=$(notmuch search mimetype:multipart/encrypted and mimetype:application/pgp-encrypted and mimetype:application/octet-stream | notmuch_search_sanitize)
228 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
230 test_begin_subtest "decryption, --format=text"
231 output=$(notmuch show --format=text --decrypt=true subject:"test encrypted message 001" \
232 | notmuch_show_sanitize_all \
233 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
234 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
236 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
237 Subject: test encrypted message 001
238 From: Notmuch Test Suite <test_suite@notmuchmail.org>
239 To: test_suite@notmuchmail.org
240 Date: Sat, 01 Jan 2000 12:00:00 +0000
243 \fpart{ ID: 1, Content-type: multipart/encrypted
244 \fpart{ ID: 2, Content-type: application/pgp-encrypted
245 Non-text part: application/pgp-encrypted
247 \fpart{ ID: 3, Content-type: multipart/mixed
248 \fpart{ ID: 4, Content-type: text/plain
249 This is a test encrypted message.
251 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
252 Non-text part: application/octet-stream
262 test_begin_subtest "decryption, --format=json"
263 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
264 | notmuch_json_show_sanitize \
265 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
266 expected='[[[{"id": "XXXXX",
269 "filename": ["YYYYY"],
270 "timestamp": 946728000,
271 "date_relative": "2000-01-01",
272 "tags": ["encrypted","inbox"],
273 "crypto": {"decrypted": {"status": "full"}},
274 "headers": {"Subject": "test encrypted message 001",
275 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
276 "To": "test_suite@notmuchmail.org",
277 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
279 "encstatus": [{"status": "good"}],
280 "content-type": "multipart/encrypted",
281 "content": [{"id": 2,
282 "content-type": "application/pgp-encrypted",
283 "content-length": "NONZERO"},
285 "content-type": "multipart/mixed",
286 "content": [{"id": 4,
287 "content-type": "text/plain",
288 "content": "This is a test encrypted message.\n"},
290 "content-type": "application/octet-stream",
291 "content-disposition": "attachment",
292 "content-length": "NONZERO",
293 "content-transfer-encoding": "base64",
294 "filename": "TESTATTACHMENT"}]}]}]},
296 test_expect_equal_json \
300 test_begin_subtest "decryption, --format=json, --part=4"
301 output=$(notmuch show --format=json --part=4 --decrypt=true subject:"test encrypted message 001" \
302 | notmuch_json_show_sanitize \
303 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
305 "content-type": "text/plain",
306 "content": "This is a test encrypted message.\n"}'
307 test_expect_equal_json \
311 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
316 subject:"test encrypted message 001" >OUTPUT
317 test_expect_equal_file TESTATTACHMENT OUTPUT
319 test_begin_subtest "decryption failure with missing key"
320 mv "${GNUPGHOME}"{,.bak}
321 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
322 | notmuch_json_show_sanitize \
323 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
324 expected='[[[{"id": "XXXXX",
328 "filename": ["YYYYY"],
329 "timestamp": 946728000,
330 "date_relative": "2000-01-01",
331 "tags": ["encrypted","inbox"],
332 "headers": {"Subject": "test encrypted message 001",
333 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
334 "To": "test_suite@notmuchmail.org",
335 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
337 "encstatus": [{"status": "bad"}],
338 "content-type": "multipart/encrypted",
339 "content": [{"id": 2,
340 "content-type": "application/pgp-encrypted",
341 "content-length": "NONZERO"},
343 "content-type": "application/octet-stream",
344 "content-length": "NONZERO"}]}]},
346 test_expect_equal_json \
349 mv "${GNUPGHOME}"{.bak,}
351 test_begin_subtest "emacs delivery of encrypted + signed message"
352 test_expect_success \
354 "test encrypted message 002" \
355 "This is another test encrypted message.\n" \
356 "(mml-secure-message-sign-encrypt)"'
358 test_begin_subtest "decryption + signature verification"
359 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 002" \
360 | notmuch_json_show_sanitize \
361 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
362 expected='[[[{"id": "XXXXX",
365 "filename": ["YYYYY"],
366 "timestamp": 946728000,
367 "date_relative": "2000-01-01",
368 "tags": ["encrypted","inbox"],
369 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'"}],
371 "decrypted": {"status": "full"}},
372 "headers": {"Subject": "test encrypted message 002",
373 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
374 "To": "test_suite@notmuchmail.org",
375 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
377 "encstatus": [{"status": "good"}],
378 "sigstatus": [{"status": "good",
379 "fingerprint": "'$FINGERPRINT'",
380 "created": 946728000,
381 "userid": "'"$SELF_USERID"'"}],
382 "content-type": "multipart/encrypted",
383 "content": [{"id": 2,
384 "content-type": "application/pgp-encrypted",
385 "content-length": "NONZERO"},
387 "content-type": "text/plain",
388 "content": "This is another test encrypted message.\n"}]}]},
390 test_expect_equal_json \
394 test_begin_subtest "reply to encrypted message"
395 output=$(notmuch reply --decrypt=true subject:"test encrypted message 002" \
396 | notmuch_drop_mail_headers In-Reply-To References)
397 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
398 Subject: Re: test encrypted message 002
399 To: test_suite@notmuchmail.org
401 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
402 > This is another test encrypted message.'
407 test_begin_subtest "Reply within emacs to an encrypted message"
408 test_emacs "(let ((message-hidden-headers '())
409 (notmuch-crypto-process-mime 't))
410 (notmuch-show \"subject:test.encrypted.message.002\")
413 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' < OUTPUT > OUTPUT.clean
415 From: Notmuch Test Suite <test_suite@notmuchmail.org>
416 To: test_suite@notmuchmail.org
417 Subject: Re: test encrypted message 002
418 --text follows this line--
419 <#secure method=pgpmime mode=signencrypt>
420 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
422 > This is another test encrypted message.
424 test_expect_equal_file EXPECTED OUTPUT.clean
426 test_begin_subtest "signature verification with revoked key"
427 # generate revocation certificate and load it to revoke key
430 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
435 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
436 | gpg --no-tty --quiet --import
437 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
438 | notmuch_json_show_sanitize \
439 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
440 expected='[[[{"id": "XXXXX",
443 "filename": ["YYYYY"],
444 "timestamp": 946728000,
445 "date_relative": "2000-01-01",
446 "tags": ["inbox","signed"],
447 "crypto": {"signed": {"status": [{"errors": {"key-revoked": true}, "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'", "status": "error"}]}},
448 "headers": {"Subject": "test signed message 001",
449 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
450 "To": "test_suite@notmuchmail.org",
451 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
453 "sigstatus": [{"status": "error",
454 "keyid": "6D92612D94E46381",
455 "errors": {"key-revoked": true}}],
456 "content-type": "multipart/signed",
457 "content": [{"id": 2,
458 "content-type": "text/plain",
459 "content": "This is a test signed message.\n"},
461 "content-type": "application/pgp-signature",
462 "content-length": "NONZERO"}]}]},
464 test_expect_equal_json \