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 test_subtest_broken_gmime_2
140 # give the key full owner trust
141 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
142 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
143 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
144 | notmuch_json_show_sanitize \
145 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
146 expected='[[[{"id": "XXXXX",
149 "filename": ["YYYYY"],
150 "timestamp": 946728000,
151 "date_relative": "2000-01-01",
152 "tags": ["inbox","signed"],
153 "headers": {"Subject": "test signed message 001",
154 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
155 "To": "test_suite@notmuchmail.org",
156 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
158 "sigstatus": [{"status": "good",
159 "fingerprint": "'$FINGERPRINT'",
160 "created": 946728000,
161 "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
162 "content-type": "multipart/signed",
163 "content": [{"id": 2,
164 "content-type": "text/plain",
165 "content": "This is a test signed message.\n"},
167 "content-type": "application/pgp-signature",
168 "content-length": "NONZERO"}]}]},
170 test_expect_equal_json \
174 test_begin_subtest "signature verification with signer key unavailable"
175 # move the gnupghome temporarily out of the way
176 mv "${GNUPGHOME}"{,.bak}
177 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
178 | notmuch_json_show_sanitize \
179 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
180 expected='[[[{"id": "XXXXX",
183 "filename": ["YYYYY"],
184 "timestamp": 946728000,
185 "date_relative": "2000-01-01",
186 "tags": ["inbox","signed"],
187 "headers": {"Subject": "test signed message 001",
188 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
189 "To": "test_suite@notmuchmail.org",
190 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
192 "sigstatus": [{"status": "error",
193 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
194 "errors": {"key-missing": true}}],
195 "content-type": "multipart/signed",
196 "content": [{"id": 2,
197 "content-type": "text/plain",
198 "content": "This is a test signed message.\n"},
200 "content-type": "application/pgp-signature",
201 "content-length": "NONZERO"}]}]},
203 test_expect_equal_json \
206 mv "${GNUPGHOME}"{.bak,}
208 test_begin_subtest "emacs delivery of encrypted message with attachment"
209 # create a test encrypted message with attachment
210 cat <<EOF >TESTATTACHMENT
213 test_expect_success \
215 "test encrypted message 001" \
216 "This is a test encrypted message.\n" \
217 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
219 test_begin_subtest "encrypted part content-type indexing"
220 output=$(notmuch search mimetype:multipart/encrypted and mimetype:application/pgp-encrypted and mimetype:application/octet-stream | notmuch_search_sanitize)
221 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
223 test_begin_subtest "decryption, --format=text"
224 output=$(notmuch show --format=text --decrypt=true subject:"test encrypted message 001" \
225 | notmuch_show_sanitize_all \
226 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
227 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
229 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
230 Subject: test encrypted message 001
231 From: Notmuch Test Suite <test_suite@notmuchmail.org>
232 To: test_suite@notmuchmail.org
233 Date: Sat, 01 Jan 2000 12:00:00 +0000
236 \fpart{ ID: 1, Content-type: multipart/encrypted
237 \fpart{ ID: 2, Content-type: application/pgp-encrypted
238 Non-text part: application/pgp-encrypted
240 \fpart{ ID: 3, Content-type: multipart/mixed
241 \fpart{ ID: 4, Content-type: text/plain
242 This is a test encrypted message.
244 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
245 Non-text part: application/octet-stream
255 test_begin_subtest "decryption, --format=json"
256 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
257 | notmuch_json_show_sanitize \
258 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
259 expected='[[[{"id": "XXXXX",
262 "filename": ["YYYYY"],
263 "timestamp": 946728000,
264 "date_relative": "2000-01-01",
265 "tags": ["encrypted","inbox"],
266 "headers": {"Subject": "test encrypted message 001",
267 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
268 "To": "test_suite@notmuchmail.org",
269 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
271 "encstatus": [{"status": "good"}],
272 "content-type": "multipart/encrypted",
273 "content": [{"id": 2,
274 "content-type": "application/pgp-encrypted",
275 "content-length": "NONZERO"},
277 "content-type": "multipart/mixed",
278 "content": [{"id": 4,
279 "content-type": "text/plain",
280 "content": "This is a test encrypted message.\n"},
282 "content-type": "application/octet-stream",
283 "content-disposition": "attachment",
284 "content-length": "NONZERO",
285 "content-transfer-encoding": "base64",
286 "filename": "TESTATTACHMENT"}]}]}]},
288 test_expect_equal_json \
292 test_begin_subtest "decryption, --format=json, --part=4"
293 output=$(notmuch show --format=json --part=4 --decrypt=true subject:"test encrypted message 001" \
294 | notmuch_json_show_sanitize \
295 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
297 "content-type": "text/plain",
298 "content": "This is a test encrypted message.\n"}'
299 test_expect_equal_json \
303 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
308 subject:"test encrypted message 001" >OUTPUT
309 test_expect_equal_file TESTATTACHMENT OUTPUT
311 test_begin_subtest "decryption failure with missing key"
312 mv "${GNUPGHOME}"{,.bak}
313 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
314 | notmuch_json_show_sanitize \
315 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
316 expected='[[[{"id": "XXXXX",
319 "filename": ["YYYYY"],
320 "timestamp": 946728000,
321 "date_relative": "2000-01-01",
322 "tags": ["encrypted","inbox"],
323 "headers": {"Subject": "test encrypted message 001",
324 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
325 "To": "test_suite@notmuchmail.org",
326 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
328 "encstatus": [{"status": "bad"}],
329 "content-type": "multipart/encrypted",
330 "content": [{"id": 2,
331 "content-type": "application/pgp-encrypted",
332 "content-length": "NONZERO"},
334 "content-type": "application/octet-stream",
335 "content-length": "NONZERO"}]}]},
337 test_expect_equal_json \
340 mv "${GNUPGHOME}"{.bak,}
342 test_begin_subtest "emacs delivery of encrypted + signed message"
343 test_expect_success \
345 "test encrypted message 002" \
346 "This is another test encrypted message.\n" \
347 "(mml-secure-message-sign-encrypt)"'
349 test_begin_subtest "decryption + signature verification"
350 test_subtest_broken_gmime_2
351 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 002" \
352 | notmuch_json_show_sanitize \
353 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
354 expected='[[[{"id": "XXXXX",
357 "filename": ["YYYYY"],
358 "timestamp": 946728000,
359 "date_relative": "2000-01-01",
360 "tags": ["encrypted","inbox"],
361 "headers": {"Subject": "test encrypted message 002",
362 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
363 "To": "test_suite@notmuchmail.org",
364 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
366 "encstatus": [{"status": "good"}],
367 "sigstatus": [{"status": "good",
368 "fingerprint": "'$FINGERPRINT'",
369 "created": 946728000,
370 "userid": "Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
371 "content-type": "multipart/encrypted",
372 "content": [{"id": 2,
373 "content-type": "application/pgp-encrypted",
374 "content-length": "NONZERO"},
376 "content-type": "text/plain",
377 "content": "This is another test encrypted message.\n"}]}]},
379 test_expect_equal_json \
383 test_begin_subtest "reply to encrypted message"
384 output=$(notmuch reply --decrypt=true subject:"test encrypted message 002" \
385 | notmuch_drop_mail_headers In-Reply-To References)
386 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
387 Subject: Re: test encrypted message 002
388 To: test_suite@notmuchmail.org
390 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
391 > This is another test encrypted message.'
396 test_begin_subtest "Reply within emacs to an encrypted message"
397 test_emacs "(let ((message-hidden-headers '())
398 (notmuch-crypto-process-mime 't))
399 (notmuch-show \"subject:test.encrypted.message.002\")
402 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' < OUTPUT > OUTPUT.clean
404 From: Notmuch Test Suite <test_suite@notmuchmail.org>
405 To: test_suite@notmuchmail.org
406 Subject: Re: test encrypted message 002
407 --text follows this line--
408 <#secure method=pgpmime mode=signencrypt>
409 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
411 > This is another test encrypted message.
413 test_expect_equal_file EXPECTED OUTPUT.clean
415 test_begin_subtest "signature verification with revoked key"
416 # generate revocation certificate and load it to revoke key
419 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
424 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
425 | gpg --no-tty --quiet --import
426 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
427 | notmuch_json_show_sanitize \
428 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
429 expected='[[[{"id": "XXXXX",
432 "filename": ["YYYYY"],
433 "timestamp": 946728000,
434 "date_relative": "2000-01-01",
435 "tags": ["inbox","signed"],
436 "headers": {"Subject": "test signed message 001",
437 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
438 "To": "test_suite@notmuchmail.org",
439 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
441 "sigstatus": [{"status": "error",
442 "keyid": "6D92612D94E46381",
443 "errors": {"key-revoked": true}}],
444 "content-type": "multipart/signed",
445 "content": [{"id": 2,
446 "content-type": "text/plain",
447 "content": "This is a test signed message.\n"},
449 "content-type": "application/pgp-signature",
450 "content-length": "NONZERO"}]}]},
452 test_expect_equal_json \