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 . $(dirname "$0")/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, "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 "userid": "'"$SELF_USERID"'"}],
48 "content-type": "multipart/signed",
50 "content-type": "text/plain",
51 "content": "This is a test signed message.\n"},
53 "content-type": "application/pgp-signature",
54 "content-length": "NONZERO"}]}]},
56 test_expect_equal_json \
60 test_begin_subtest "detection of modified signed contents"
62 "bad signed message 001" \
63 "Incriminating stuff. This is a test signed message." \
64 "(mml-secure-message-sign)"
66 file=$(notmuch search --output=files subject:"bad signed message 001")
68 sed -i 's/Incriminating stuff. //' ${file}
70 output=$(notmuch show --format=json --verify subject:"bad signed message 001" \
71 | notmuch_json_show_sanitize \
72 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
73 expected='[[[{"id": "XXXXX",
76 "filename": ["YYYYY"],
77 "timestamp": 946728000,
78 "date_relative": "2000-01-01",
79 "tags": ["inbox","signed"],
80 "crypto": {"signed": {"status": [{ "status": "bad", "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}]}},
81 "headers": {"Subject": "bad signed message 001",
82 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
83 "To": "test_suite@notmuchmail.org",
84 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
86 "sigstatus": [{"status": "bad",
87 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}],
88 "content-type": "multipart/signed",
90 "content-type": "text/plain",
91 "content": "This is a test signed message.\n"},
93 "content-type": "application/pgp-signature",
94 "content-length": "NONZERO"}]}]},
96 test_expect_equal_json \
100 test_begin_subtest "corrupted pgp/mime signature"
102 "bad signed message 002" \
103 "Incriminating stuff. This is a test signed message." \
104 "(mml-secure-message-sign)"
106 file=$(notmuch search --output=files subject:"bad signed message 002")
108 awk '/-----BEGIN PGP SIGNATURE-----/{flag=1;print;next} \
109 /-----END PGP SIGNATURE-----/{flag=0;print;next} \
110 flag{gsub(/[A-Za-z]/,"0");print}!flag{print}' $file > $file.new
115 output=$(notmuch show --format=json --verify subject:"bad signed message 002" \
116 | notmuch_json_show_sanitize \
117 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
118 expected='[[[{"id": "XXXXX",
122 "filename": ["YYYYY"],
123 "timestamp": 946728000,
124 "date_relative": "2000-01-01",
125 "tags": ["inbox","signed"],
126 "headers": {"Subject": "bad signed message 002",
127 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
128 "To": "test_suite@notmuchmail.org",
129 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
132 "content-type": "multipart/signed",
133 "content": [{"id": 2,
134 "content-type": "text/plain",
135 "content": "Incriminating stuff. This is a test signed message.\n"},
137 "content-type": "application/pgp-signature",
138 "content-length": "NONZERO"}]}]},
140 test_expect_equal_json \
144 test_begin_subtest "signature verification without full user ID validity"
145 # give the key no owner trust, removes validity on all user IDs of the
146 # certificate in the absence of other trusted certifiers:
147 gpg --quiet --batch --no-tty --export-ownertrust > "$GNUPGHOME/ownertrust.bak"
148 echo "${FINGERPRINT}:3:" | gpg --quiet --batch --no-tty --import-ownertrust
149 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
150 | notmuch_json_show_sanitize \
151 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
152 expected='[[[{"id": "XXXXX",
155 "filename": ["YYYYY"],
156 "timestamp": 946728000,
157 "date_relative": "2000-01-01",
158 "tags": ["inbox","signed"],
159 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "fingerprint": "'$FINGERPRINT'"}]}},
160 "headers": {"Subject": "test signed message 001",
161 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
162 "To": "test_suite@notmuchmail.org",
163 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
165 "sigstatus": [{"status": "good",
166 "fingerprint": "'$FINGERPRINT'",
167 "created": 946728000}],
168 "content-type": "multipart/signed",
169 "content": [{"id": 2,
170 "content-type": "text/plain",
171 "content": "This is a test signed message.\n"},
173 "content-type": "application/pgp-signature",
174 "content-length": "NONZERO"}]}]},
176 test_expect_equal_json \
179 gpg --quiet --batch --no-tty --import-ownertrust < "$GNUPGHOME/ownertrust.bak"
181 test_begin_subtest "signature verification with signer key unavailable"
182 # move the gnupghome temporarily out of the way
183 mv "${GNUPGHOME}"{,.bak}
184 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
185 | notmuch_json_show_sanitize \
186 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
187 expected='[[[{"id": "XXXXX",
190 "filename": ["YYYYY"],
191 "timestamp": 946728000,
192 "date_relative": "2000-01-01",
193 "tags": ["inbox","signed"],
194 "crypto": {"signed": {"status": [{"errors": {"key-missing": true}, "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'", "status": "error"}]}},
195 "headers": {"Subject": "test signed message 001",
196 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
197 "To": "test_suite@notmuchmail.org",
198 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
200 "sigstatus": [{"status": "error",
201 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
202 "errors": {"key-missing": true}}],
203 "content-type": "multipart/signed",
204 "content": [{"id": 2,
205 "content-type": "text/plain",
206 "content": "This is a test signed message.\n"},
208 "content-type": "application/pgp-signature",
209 "content-length": "NONZERO"}]}]},
211 test_expect_equal_json \
214 mv "${GNUPGHOME}"{.bak,}
216 test_begin_subtest "emacs delivery of encrypted message with attachment"
217 # create a test encrypted message with attachment
218 cat <<EOF >TESTATTACHMENT
221 test_expect_success \
223 "test encrypted message 001" \
224 "This is a test encrypted message.\n" \
225 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
227 test_begin_subtest "encrypted part content-type indexing"
228 output=$(notmuch search mimetype:multipart/encrypted and mimetype:application/pgp-encrypted and mimetype:application/octet-stream | notmuch_search_sanitize)
229 test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
231 test_begin_subtest "decryption, --format=text"
232 output=$(notmuch show --format=text --decrypt=true subject:"test encrypted message 001" \
233 | notmuch_show_sanitize_all \
234 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
235 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
237 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
238 Subject: test encrypted message 001
239 From: Notmuch Test Suite <test_suite@notmuchmail.org>
240 To: test_suite@notmuchmail.org
241 Date: Sat, 01 Jan 2000 12:00:00 +0000
244 \fpart{ ID: 1, Content-type: multipart/encrypted
245 \fpart{ ID: 2, Content-type: application/pgp-encrypted
246 Non-text part: application/pgp-encrypted
248 \fpart{ ID: 3, Content-type: multipart/mixed
249 \fpart{ ID: 4, Content-type: text/plain
250 This is a test encrypted message.
252 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
253 Non-text part: application/octet-stream
263 test_begin_subtest "decryption, --format=json"
264 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
265 | notmuch_json_show_sanitize \
266 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
267 expected='[[[{"id": "XXXXX",
270 "filename": ["YYYYY"],
271 "timestamp": 946728000,
272 "date_relative": "2000-01-01",
273 "tags": ["encrypted","inbox"],
274 "crypto": {"decrypted": {"status": "full"}},
275 "headers": {"Subject": "test encrypted message 001",
276 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
277 "To": "test_suite@notmuchmail.org",
278 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
280 "encstatus": [{"status": "good"}],
281 "content-type": "multipart/encrypted",
282 "content": [{"id": 2,
283 "content-type": "application/pgp-encrypted",
284 "content-length": "NONZERO"},
286 "content-type": "multipart/mixed",
287 "content": [{"id": 4,
288 "content-type": "text/plain",
289 "content": "This is a test encrypted message.\n"},
291 "content-type": "application/octet-stream",
292 "content-disposition": "attachment",
293 "content-length": "NONZERO",
294 "content-transfer-encoding": "base64",
295 "filename": "TESTATTACHMENT"}]}]}]},
297 test_expect_equal_json \
301 test_begin_subtest "decryption, --format=json, --part=4"
302 output=$(notmuch show --format=json --part=4 --decrypt=true subject:"test encrypted message 001" \
303 | notmuch_json_show_sanitize \
304 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
306 "content-type": "text/plain",
307 "content": "This is a test encrypted message.\n"}'
308 test_expect_equal_json \
312 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
317 subject:"test encrypted message 001" >OUTPUT
318 test_expect_equal_file TESTATTACHMENT OUTPUT
320 test_begin_subtest "decryption failure with missing key"
321 mv "${GNUPGHOME}"{,.bak}
322 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001" \
323 | notmuch_json_show_sanitize \
324 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
325 expected='[[[{"id": "XXXXX",
329 "filename": ["YYYYY"],
330 "timestamp": 946728000,
331 "date_relative": "2000-01-01",
332 "tags": ["encrypted","inbox"],
333 "headers": {"Subject": "test encrypted message 001",
334 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
335 "To": "test_suite@notmuchmail.org",
336 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
338 "encstatus": [{"status": "bad"}],
339 "content-type": "multipart/encrypted",
340 "content": [{"id": 2,
341 "content-type": "application/pgp-encrypted",
342 "content-length": "NONZERO"},
344 "content-type": "application/octet-stream",
345 "content-length": "NONZERO"}]}]},
347 test_expect_equal_json \
350 mv "${GNUPGHOME}"{.bak,}
352 test_begin_subtest "emacs delivery of encrypted + signed message"
353 test_expect_success \
355 "test encrypted message 002" \
356 "This is another test encrypted message.\n" \
357 "(mml-secure-message-sign-encrypt)"'
359 test_begin_subtest "decryption + signature verification"
360 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 002" \
361 | notmuch_json_show_sanitize \
362 | sed -e 's|"created": [1234567890]*|"created": 946728000|g')
363 expected='[[[{"id": "XXXXX",
366 "filename": ["YYYYY"],
367 "timestamp": 946728000,
368 "date_relative": "2000-01-01",
369 "tags": ["encrypted","inbox"],
370 "crypto": {"signed": {"status": [{ "status": "good", "created": 946728000, "fingerprint": "'$FINGERPRINT'", "userid": "'"$SELF_USERID"'"}],
372 "decrypted": {"status": "full"}},
373 "headers": {"Subject": "test encrypted message 002",
374 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
375 "To": "test_suite@notmuchmail.org",
376 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
378 "encstatus": [{"status": "good"}],
379 "sigstatus": [{"status": "good",
380 "fingerprint": "'$FINGERPRINT'",
381 "created": 946728000,
382 "userid": "'"$SELF_USERID"'"}],
383 "content-type": "multipart/encrypted",
384 "content": [{"id": 2,
385 "content-type": "application/pgp-encrypted",
386 "content-length": "NONZERO"},
388 "content-type": "text/plain",
389 "content": "This is another test encrypted message.\n"}]}]},
391 test_expect_equal_json \
395 test_begin_subtest "reply to encrypted message"
396 output=$(notmuch reply --decrypt=true subject:"test encrypted message 002" \
397 | notmuch_drop_mail_headers In-Reply-To References)
398 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
399 Subject: Re: test encrypted message 002
400 To: test_suite@notmuchmail.org
402 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
403 > This is another test encrypted message.'
408 test_begin_subtest "Reply within emacs to an encrypted message"
409 test_emacs "(let ((message-hidden-headers '())
410 (notmuch-crypto-process-mime 't))
411 (notmuch-show \"subject:test.encrypted.message.002\")
414 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' < OUTPUT > OUTPUT.clean
416 From: Notmuch Test Suite <test_suite@notmuchmail.org>
417 To: test_suite@notmuchmail.org
418 Subject: Re: test encrypted message 002
419 --text follows this line--
420 <#secure method=pgpmime mode=signencrypt>
421 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
423 > This is another test encrypted message.
425 test_expect_equal_file EXPECTED OUTPUT.clean
427 test_begin_subtest "signature verification with revoked key"
428 # generate revocation certificate and load it to revoke key
431 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
436 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
437 | gpg --no-tty --quiet --import
438 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
439 | notmuch_json_show_sanitize \
440 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
441 expected='[[[{"id": "XXXXX",
444 "filename": ["YYYYY"],
445 "timestamp": 946728000,
446 "date_relative": "2000-01-01",
447 "tags": ["inbox","signed"],
448 "crypto": {"signed": {"status": [{"errors": {"key-revoked": true}, "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'", "status": "error"}]}},
449 "headers": {"Subject": "test signed message 001",
450 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
451 "To": "test_suite@notmuchmail.org",
452 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
454 "sigstatus": [{"status": "error",
455 "keyid": "6D92612D94E46381",
456 "errors": {"key-revoked": true}}],
457 "content-type": "multipart/signed",
458 "content": [{"id": 2,
459 "content-type": "text/plain",
460 "content": "This is a test signed message.\n"},
462 "content-type": "application/pgp-signature",
463 "content-length": "NONZERO"}]}]},
465 test_expect_equal_json \