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
9 . $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
11 ##################################################
16 test_begin_subtest "emacs delivery of signed message"
19 "test signed message 001" \
20 "This is a test signed message." \
21 "(mml-secure-message-sign)"'
23 test_begin_subtest "signed part content-type indexing"
24 output=$(notmuch search mimetype:multipart/signed and mimetype:application/pgp-signature | notmuch_search_sanitize)
25 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test signed message 001 (inbox signed)"
27 test_begin_subtest "signature verification"
28 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
29 | notmuch_json_show_sanitize \
30 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
31 expected='[[[{"id": "XXXXX",
34 "filename": ["YYYYY"],
35 "timestamp": 946728000,
36 "date_relative": "2000-01-01",
37 "tags": ["inbox","signed"],
38 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "email": "'"$SELF_EMAIL"'", "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'"}]}},
39 "headers": {"Subject": "test signed message 001",
40 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
41 "To": "test_suite@notmuchmail.org",
42 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
44 "sigstatus": [{"status": "good",
45 "fingerprint": "'$FINGERPRINT'",
47 "email": "'"$SELF_EMAIL"'",
48 "userid": "'"$SELF_USERID"'"}],
49 "content-type": "multipart/signed",
51 "content-type": "text/plain",
52 "content": "This is a test signed message.\n"},
54 "content-type": "application/pgp-signature",
55 "content-length": "NONZERO"}]}]},
57 test_expect_equal_json \
61 test_begin_subtest "detection of modified signed contents"
63 "bad signed message 001" \
64 "Incriminating stuff. This is a test signed message." \
65 "(mml-secure-message-sign)"
67 file=$(notmuch search --output=files subject:"bad signed message 001")
69 sed -i 's/Incriminating stuff. //' ${file}
71 output=$(notmuch show --format=json --verify subject:"bad signed message 001" \
72 | notmuch_json_show_sanitize \
73 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
74 expected='[[[{"id": "XXXXX",
77 "filename": ["YYYYY"],
78 "timestamp": 946728000,
79 "date_relative": "2000-01-01",
80 "tags": ["inbox","signed"],
81 "crypto": {"signed": {"status": [{ "status": "bad", "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}]}},
82 "headers": {"Subject": "bad signed message 001",
83 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
84 "To": "test_suite@notmuchmail.org",
85 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
87 "sigstatus": [{"status": "bad",
88 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}],
89 "content-type": "multipart/signed",
91 "content-type": "text/plain",
92 "content": "This is a test signed message.\n"},
94 "content-type": "application/pgp-signature",
95 "content-length": "NONZERO"}]}]},
97 test_expect_equal_json \
101 test_begin_subtest "corrupted pgp/mime signature"
103 "bad signed message 002" \
104 "Incriminating stuff. This is a test signed message." \
105 "(mml-secure-message-sign)"
107 file=$(notmuch search --output=files subject:"bad signed message 002")
109 awk '/-----BEGIN PGP SIGNATURE-----/{flag=1;print;next} \
110 /-----END PGP SIGNATURE-----/{flag=0;print;next} \
111 flag{gsub(/[A-Za-z]/,"0");print}!flag{print}' $file > $file.new
116 output=$(notmuch show --format=json --verify subject:"bad signed message 002" \
117 | notmuch_json_show_sanitize \
118 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
119 expected='[[[{"id": "XXXXX",
123 "filename": ["YYYYY"],
124 "timestamp": 946728000,
125 "date_relative": "2000-01-01",
126 "tags": ["inbox","signed"],
127 "headers": {"Subject": "bad signed message 002",
128 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
129 "To": "test_suite@notmuchmail.org",
130 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
133 "content-type": "multipart/signed",
134 "content": [{"id": 2,
135 "content-type": "text/plain",
136 "content": "Incriminating stuff. This is a test signed message.\n"},
138 "content-type": "application/pgp-signature",
139 "content-length": "NONZERO"}]}]},
141 test_expect_equal_json \
145 test_begin_subtest "signature verification without full user ID validity"
146 # give the key no owner trust, removes validity on all user IDs of the
147 # certificate in the absence of other trusted certifiers:
148 gpg --quiet --batch --no-tty --export-ownertrust > "$GNUPGHOME/ownertrust.bak"
149 echo "${FINGERPRINT}:3:" | gpg --quiet --batch --no-tty --import-ownertrust
150 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
151 | notmuch_json_show_sanitize \
152 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
153 expected='[[[{"id": "XXXXX",
156 "filename": ["YYYYY"],
157 "timestamp": 946728000,
158 "date_relative": "2000-01-01",
159 "tags": ["inbox","signed"],
160 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "fingerprint": "'$FINGERPRINT'"}]}},
161 "headers": {"Subject": "test signed message 001",
162 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
163 "To": "test_suite@notmuchmail.org",
164 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
166 "sigstatus": [{"status": "good",
167 "fingerprint": "'$FINGERPRINT'",
168 "created": 946728000}],
169 "content-type": "multipart/signed",
170 "content": [{"id": 2,
171 "content-type": "text/plain",
172 "content": "This is a test signed message.\n"},
174 "content-type": "application/pgp-signature",
175 "content-length": "NONZERO"}]}]},
177 test_expect_equal_json \
180 gpg --quiet --batch --no-tty --import-ownertrust < "$GNUPGHOME/ownertrust.bak"
182 test_begin_subtest "signature verification with signer key unavailable"
183 # move the gnupghome temporarily out of the way
184 mv "${GNUPGHOME}"{,.bak}
185 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
186 | notmuch_json_show_sanitize \
187 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
188 expected='[[[{"id": "XXXXX",
191 "filename": ["YYYYY"],
192 "timestamp": 946728000,
193 "date_relative": "2000-01-01",
194 "tags": ["inbox","signed"],
195 "crypto": {"signed": {"status": [{"errors": {"key-missing": true}, "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'", "status": "error"}]}},
196 "headers": {"Subject": "test signed message 001",
197 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
198 "To": "test_suite@notmuchmail.org",
199 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
201 "sigstatus": [{"status": "error",
202 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
203 "errors": {"key-missing": true}}],
204 "content-type": "multipart/signed",
205 "content": [{"id": 2,
206 "content-type": "text/plain",
207 "content": "This is a test signed message.\n"},
209 "content-type": "application/pgp-signature",
210 "content-length": "NONZERO"}]}]},
212 test_expect_equal_json \
215 mv "${GNUPGHOME}"{.bak,}
217 test_begin_subtest "emacs delivery of encrypted message with attachment"
218 # create a test encrypted message with attachment
219 cat <<EOF >TESTATTACHMENT
222 test_expect_success \
224 "test encrypted message 001" \
225 "This is a test encrypted message.\n" \
226 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
228 test_begin_subtest "encrypted part content-type indexing"
229 output=$(notmuch search mimetype:multipart/encrypted and mimetype:application/pgp-encrypted and mimetype:application/octet-stream | notmuch_search_sanitize)
230 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
232 test_begin_subtest "decryption, --format=text"
233 output=$(notmuch show --format=text --decrypt=true subject:"test encrypted message 001" \
234 | notmuch_show_sanitize_all \
235 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
236 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
238 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
239 Subject: test encrypted message 001
240 From: Notmuch Test Suite <test_suite@notmuchmail.org>
241 To: test_suite@notmuchmail.org
242 Date: Sat, 01 Jan 2000 12:00:00 +0000
245 \fpart{ ID: 1, Content-type: multipart/encrypted
246 \fpart{ ID: 2, Content-type: application/pgp-encrypted
247 Non-text part: application/pgp-encrypted
249 \fpart{ ID: 3, Content-type: multipart/mixed
250 \fpart{ ID: 4, Content-type: text/plain
251 This is a test encrypted message.
253 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
254 Non-text part: application/octet-stream
264 test_begin_subtest "decryption, --format=json"
265 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
266 | notmuch_json_show_sanitize \
267 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
268 expected='[[[{"id": "XXXXX",
271 "filename": ["YYYYY"],
272 "timestamp": 946728000,
273 "date_relative": "2000-01-01",
274 "tags": ["encrypted","inbox"],
275 "crypto": {"decrypted": {"status": "full"}},
276 "headers": {"Subject": "test encrypted message 001",
277 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
278 "To": "test_suite@notmuchmail.org",
279 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
281 "encstatus": [{"status": "good"}],
282 "content-type": "multipart/encrypted",
283 "content": [{"id": 2,
284 "content-type": "application/pgp-encrypted",
285 "content-length": "NONZERO"},
287 "content-type": "multipart/mixed",
288 "content": [{"id": 4,
289 "content-type": "text/plain",
290 "content": "This is a test encrypted message.\n"},
292 "content-type": "application/octet-stream",
293 "content-disposition": "attachment",
294 "content-length": "NONZERO",
295 "content-transfer-encoding": "base64",
296 "filename": "TESTATTACHMENT"}]}]}]},
298 test_expect_equal_json \
302 test_begin_subtest "decryption, --format=json, --part=4"
303 output=$(notmuch show --format=json --part=4 --decrypt=true subject:"test encrypted message 001" \
304 | notmuch_json_show_sanitize \
305 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
307 "content-type": "text/plain",
308 "content": "This is a test encrypted message.\n"}'
309 test_expect_equal_json \
313 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
318 subject:"test encrypted message 001" >OUTPUT
319 test_expect_equal_file TESTATTACHMENT OUTPUT
321 test_begin_subtest "decryption failure with missing key"
322 mv "${GNUPGHOME}"{,.bak}
323 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
324 | notmuch_json_show_sanitize \
325 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
326 expected='[[[{"id": "XXXXX",
330 "filename": ["YYYYY"],
331 "timestamp": 946728000,
332 "date_relative": "2000-01-01",
333 "tags": ["encrypted","inbox"],
334 "headers": {"Subject": "test encrypted message 001",
335 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
336 "To": "test_suite@notmuchmail.org",
337 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
339 "encstatus": [{"status": "bad"}],
340 "content-type": "multipart/encrypted",
341 "content": [{"id": 2,
342 "content-type": "application/pgp-encrypted",
343 "content-length": "NONZERO"},
345 "content-type": "application/octet-stream",
346 "content-length": "NONZERO"}]}]},
348 test_expect_equal_json \
351 mv "${GNUPGHOME}"{.bak,}
353 test_begin_subtest "emacs delivery of encrypted + signed message"
354 test_expect_success \
356 "test encrypted message 002" \
357 "This is another test encrypted message.\n" \
358 "(mml-secure-message-sign-encrypt)"'
360 test_begin_subtest "decryption + signature verification"
361 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 002" \
362 | notmuch_json_show_sanitize \
363 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
364 expected='[[[{"id": "XXXXX",
367 "filename": ["YYYYY"],
368 "timestamp": 946728000,
369 "date_relative": "2000-01-01",
370 "tags": ["encrypted","inbox"],
371 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "fingerprint": "'$FINGERPRINT'", "email": "'"$SELF_EMAIL"'", "userid": "'"$SELF_USERID"'"}],
373 "decrypted": {"status": "full"}},
374 "headers": {"Subject": "test encrypted message 002",
375 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
376 "To": "test_suite@notmuchmail.org",
377 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
379 "encstatus": [{"status": "good"}],
380 "sigstatus": [{"status": "good",
381 "fingerprint": "'$FINGERPRINT'",
382 "created": 946728000,
383 "email": "'"$SELF_EMAIL"'",
384 "userid": "'"$SELF_USERID"'"}],
385 "content-type": "multipart/encrypted",
386 "content": [{"id": 2,
387 "content-type": "application/pgp-encrypted",
388 "content-length": "NONZERO"},
390 "content-type": "text/plain",
391 "content": "This is another test encrypted message.\n"}]}]},
393 test_expect_equal_json \
397 test_begin_subtest "reply to encrypted message"
398 output=$(notmuch reply --decrypt=true subject:"test encrypted message 002" \
399 | notmuch_drop_mail_headers In-Reply-To References)
400 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
401 Subject: Re: test encrypted message 002
402 To: test_suite@notmuchmail.org
404 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
405 > This is another test encrypted message.'
410 test_begin_subtest "Reply within emacs to an encrypted message"
411 test_emacs "(let ((message-hidden-headers '())
412 (notmuch-crypto-process-mime 't))
413 (notmuch-show \"subject:test.encrypted.message.002\")
416 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' < OUTPUT > OUTPUT.clean
418 From: Notmuch Test Suite <test_suite@notmuchmail.org>
419 To: test_suite@notmuchmail.org
420 Subject: Re: test encrypted message 002
421 --text follows this line--
422 <#secure method=pgpmime mode=signencrypt>
423 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
425 > This is another test encrypted message.
427 test_expect_equal_file EXPECTED OUTPUT.clean
429 test_begin_subtest "signature verification with revoked key"
430 # generate revocation certificate and load it to revoke key
433 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
438 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
439 | gpg --no-tty --quiet --import
440 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
441 | notmuch_json_show_sanitize \
442 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
443 expected='[[[{"id": "XXXXX",
446 "filename": ["YYYYY"],
447 "timestamp": 946728000,
448 "date_relative": "2000-01-01",
449 "tags": ["inbox","signed"],
450 "crypto": {"signed": {"status": [{"errors": {"key-revoked": true}, "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'", "status": "error"}]}},
451 "headers": {"Subject": "test signed message 001",
452 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
453 "To": "test_suite@notmuchmail.org",
454 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
456 "sigstatus": [{"status": "error",
457 "keyid": "6D92612D94E46381",
458 "errors": {"key-revoked": true}}],
459 "content-type": "multipart/signed",
460 "content": [{"id": 2,
461 "content-type": "text/plain",
462 "content": "This is a test signed message.\n"},
464 "content-type": "application/pgp-signature",
465 "content-length": "NONZERO"}]}]},
467 test_expect_equal_json \