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 . ./test-lib.sh || exit 1
13 [ -d ${GNUPGHOME} ] && return
14 _gnupg_exit () { gpgconf --kill all 2>/dev/null || true; }
15 at_exit_function _gnupg_exit
16 mkdir -m 0700 "$GNUPGHOME"
17 gpg --no-tty --import <$TEST_DIRECTORY/gnupg-secret-key.asc >"$GNUPGHOME"/import.log 2>&1
18 test_debug "cat $GNUPGHOME/import.log"
19 if (gpg --quick-random --version >/dev/null 2>&1) ; then
20 echo quick-random >> "$GNUPGHOME"/gpg.conf
21 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
22 echo debug-quick-random >> "$GNUPGHOME"/gpg.conf
24 echo no-emit-version >> "$GNUPGHOME"/gpg.conf
27 ##################################################
30 # Change this if we ship a new test key
31 FINGERPRINT="5AEAB11F5E33DCE875DDB75B6D92612D94E46381"
33 test_begin_subtest "emacs delivery of signed message"
36 "test signed message 001" \
37 "This is a test signed message." \
38 "(mml-secure-message-sign)"'
40 test_begin_subtest "signature verification"
41 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
42 | notmuch_json_show_sanitize \
43 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
44 expected='[[[{"id": "XXXXX",
47 "filename": ["YYYYY"],
48 "timestamp": 946728000,
49 "date_relative": "2000-01-01",
50 "tags": ["inbox","signed"],
51 "headers": {"Subject": "test signed message 001",
52 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
53 "To": "test_suite@notmuchmail.org",
54 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
56 "sigstatus": [{"status": "good",
57 "fingerprint": "'$FINGERPRINT'",
58 "created": 946728000}],
59 "content-type": "multipart/signed",
61 "content-type": "text/plain",
62 "content": "This is a test signed message.\n"},
64 "content-type": "application/pgp-signature",
65 "content-length": "NONZERO"}]}]},
67 test_expect_equal_json \
71 test_begin_subtest "detection of modified signed contents"
73 "bad signed message 001" \
74 "Incriminating stuff. This is a test signed message." \
75 "(mml-secure-message-sign)"
77 file=$(notmuch search --output=files subject:"bad signed message 001")
79 sed -i 's/Incriminating stuff. //' ${file}
81 output=$(notmuch show --format=json --verify subject:"bad signed message 001" \
82 | notmuch_json_show_sanitize \
83 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
84 expected='[[[{"id": "XXXXX",
87 "filename": ["YYYYY"],
88 "timestamp": 946728000,
89 "date_relative": "2000-01-01",
90 "tags": ["inbox","signed"],
91 "headers": {"Subject": "bad signed message 001",
92 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
93 "To": "test_suite@notmuchmail.org",
94 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
96 "sigstatus": [{"status": "bad",
97 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'"}],
98 "content-type": "multipart/signed",
100 "content-type": "text/plain",
101 "content": "This is a test signed message.\n"},
103 "content-type": "application/pgp-signature",
104 "content-length": "NONZERO"}]}]},
106 test_expect_equal_json \
110 test_begin_subtest "signature verification with full owner trust"
111 # give the key full owner trust
112 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
113 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
114 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
115 | notmuch_json_show_sanitize \
116 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
117 expected='[[[{"id": "XXXXX",
120 "filename": ["YYYYY"],
121 "timestamp": 946728000,
122 "date_relative": "2000-01-01",
123 "tags": ["inbox","signed"],
124 "headers": {"Subject": "test signed message 001",
125 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
126 "To": "test_suite@notmuchmail.org",
127 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
129 "sigstatus": [{"status": "good",
130 "fingerprint": "'$FINGERPRINT'",
131 "created": 946728000,
132 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
133 "content-type": "multipart/signed",
134 "content": [{"id": 2,
135 "content-type": "text/plain",
136 "content": "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 with signer key unavailable"
146 # move the gnupghome temporarily out of the way
147 mv "${GNUPGHOME}"{,.bak}
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|')
151 expected='[[[{"id": "XXXXX",
154 "filename": ["YYYYY"],
155 "timestamp": 946728000,
156 "date_relative": "2000-01-01",
157 "tags": ["inbox","signed"],
158 "headers": {"Subject": "test signed message 001",
159 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
160 "To": "test_suite@notmuchmail.org",
161 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
163 "sigstatus": [{"status": "error",
164 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
165 "errors": {"key-missing": true}}],
166 "content-type": "multipart/signed",
167 "content": [{"id": 2,
168 "content-type": "text/plain",
169 "content": "This is a test signed message.\n"},
171 "content-type": "application/pgp-signature",
172 "content-length": "NONZERO"}]}]},
174 test_expect_equal_json \
177 mv "${GNUPGHOME}"{.bak,}
179 test_begin_subtest "emacs delivery of encrypted message with attachment"
180 # create a test encrypted message with attachment
181 cat <<EOF >TESTATTACHMENT
184 test_expect_success \
186 "test encrypted message 001" \
187 "This is a test encrypted message.\n" \
188 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
190 test_begin_subtest "decryption, --format=text"
191 output=$(notmuch show --format=text --decrypt subject:"test encrypted message 001" \
192 | notmuch_show_sanitize_all \
193 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
194 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
196 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
197 Subject: test encrypted message 001
198 From: Notmuch Test Suite <test_suite@notmuchmail.org>
199 To: test_suite@notmuchmail.org
200 Date: Sat, 01 Jan 2000 12:00:00 +0000
203 \fpart{ ID: 1, Content-type: multipart/encrypted
204 \fpart{ ID: 2, Content-type: application/pgp-encrypted
205 Non-text part: application/pgp-encrypted
207 \fpart{ ID: 3, Content-type: multipart/mixed
208 \fpart{ ID: 4, Content-type: text/plain
209 This is a test encrypted message.
211 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
212 Non-text part: application/octet-stream
222 test_begin_subtest "decryption, --format=json"
223 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
224 | notmuch_json_show_sanitize \
225 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
226 expected='[[[{"id": "XXXXX",
229 "filename": ["YYYYY"],
230 "timestamp": 946728000,
231 "date_relative": "2000-01-01",
232 "tags": ["encrypted","inbox"],
233 "headers": {"Subject": "test encrypted message 001",
234 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
235 "To": "test_suite@notmuchmail.org",
236 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
238 "encstatus": [{"status": "good"}],
240 "content-type": "multipart/encrypted",
241 "content": [{"id": 2,
242 "content-type": "application/pgp-encrypted",
243 "content-length": "NONZERO"},
245 "content-type": "multipart/mixed",
246 "content": [{"id": 4,
247 "content-type": "text/plain",
248 "content": "This is a test encrypted message.\n"},
250 "content-type": "application/octet-stream",
251 "content-disposition": "attachment",
252 "content-length": "NONZERO",
253 "content-transfer-encoding": "base64",
254 "filename": "TESTATTACHMENT"}]}]}]},
256 test_expect_equal_json \
260 test_begin_subtest "decryption, --format=json, --part=4"
261 output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
262 | notmuch_json_show_sanitize \
263 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
265 "content-type": "text/plain",
266 "content": "This is a test encrypted message.\n"}'
267 test_expect_equal_json \
271 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
276 subject:"test encrypted message 001" >OUTPUT
277 test_expect_equal_file TESTATTACHMENT OUTPUT
279 test_begin_subtest "decryption failure with missing key"
280 mv "${GNUPGHOME}"{,.bak}
281 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
282 | notmuch_json_show_sanitize \
283 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
284 expected='[[[{"id": "XXXXX",
287 "filename": ["YYYYY"],
288 "timestamp": 946728000,
289 "date_relative": "2000-01-01",
290 "tags": ["encrypted","inbox"],
291 "headers": {"Subject": "test encrypted message 001",
292 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
293 "To": "test_suite@notmuchmail.org",
294 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
296 "encstatus": [{"status": "bad"}],
297 "content-type": "multipart/encrypted",
298 "content": [{"id": 2,
299 "content-type": "application/pgp-encrypted",
300 "content-length": "NONZERO"},
302 "content-type": "application/octet-stream",
303 "content-length": "NONZERO"}]}]},
305 test_expect_equal_json \
308 mv "${GNUPGHOME}"{.bak,}
310 test_begin_subtest "emacs delivery of encrypted + signed message"
311 test_expect_success \
313 "test encrypted message 002" \
314 "This is another test encrypted message.\n" \
315 "(mml-secure-message-sign-encrypt)"'
317 test_begin_subtest "decryption + signature verification"
318 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
319 | notmuch_json_show_sanitize \
320 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
321 expected='[[[{"id": "XXXXX",
324 "filename": ["YYYYY"],
325 "timestamp": 946728000,
326 "date_relative": "2000-01-01",
327 "tags": ["encrypted","inbox"],
328 "headers": {"Subject": "test encrypted message 002",
329 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
330 "To": "test_suite@notmuchmail.org",
331 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
333 "encstatus": [{"status": "good"}],
334 "sigstatus": [{"status": "good",
335 "fingerprint": "'$FINGERPRINT'",
336 "created": 946728000,
337 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
338 "content-type": "multipart/encrypted",
339 "content": [{"id": 2,
340 "content-type": "application/pgp-encrypted",
341 "content-length": "NONZERO"},
343 "content-type": "text/plain",
344 "content": "This is another test encrypted message.\n"}]}]},
346 test_expect_equal_json \
350 test_begin_subtest "reply to encrypted message"
351 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
352 | grep -v -e '^In-Reply-To:' -e '^References:')
353 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
354 Subject: Re: test encrypted message 002
356 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
357 > This is another test encrypted message.'
362 test_begin_subtest "Reply within emacs to an encrypted message"
363 test_emacs "(let ((message-hidden-headers '())
364 (notmuch-crypto-process-mime 't))
365 (notmuch-show \"subject:test.encrypted.message.002\")
368 # the empty To: is probably a bug, but it's not to do with encryption
369 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' -e 'To:' < OUTPUT > OUTPUT.clean
371 From: Notmuch Test Suite <test_suite@notmuchmail.org>
372 Subject: Re: test encrypted message 002
373 --text follows this line--
374 <#secure method=pgpmime mode=signencrypt>
375 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
377 > This is another test encrypted message.
379 test_expect_equal_file EXPECTED OUTPUT.clean
381 test_begin_subtest "signature verification with revoked key"
382 # generate revocation certificate and load it to revoke key
385 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
390 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
391 | gpg --no-tty --quiet --import
392 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
393 | notmuch_json_show_sanitize \
394 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
395 expected='[[[{"id": "XXXXX",
398 "filename": ["YYYYY"],
399 "timestamp": 946728000,
400 "date_relative": "2000-01-01",
401 "tags": ["inbox","signed"],
402 "headers": {"Subject": "test signed message 001",
403 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
404 "To": "test_suite@notmuchmail.org",
405 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
407 "sigstatus": [{"status": "error",
408 "keyid": "6D92612D94E46381",
409 "errors": {"key-revoked": true}}],
410 "content-type": "multipart/signed",
411 "content": [{"id": 2,
412 "content-type": "text/plain",
413 "content": "This is a test signed message.\n"},
415 "content-type": "application/pgp-signature",
416 "content-length": "NONZERO"}]}]},
418 test_expect_equal_json \