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 mkdir -m 0700 "$GNUPGHOME"
15 gpg --no-tty --import <$TEST_DIRECTORY/gnupg-secret-key.asc >"$GNUPGHOME"/import.log 2>&1
16 test_debug "cat $GNUPGHOME/import.log"
17 if (gpg --quick-random --version >/dev/null 2>&1) ; then
18 echo quick-random >> "$GNUPGHOME"/gpg.conf
19 elif (gpg --debug-quick-random --version >/dev/null 2>&1) ; then
20 echo debug-quick-random >> "$GNUPGHOME"/gpg.conf
22 echo no-emit-version >> "$GNUPGHOME"/gpg.conf
25 ##################################################
28 # Change this if we ship a new test key
29 FINGERPRINT="5AEAB11F5E33DCE875DDB75B6D92612D94E46381"
31 test_expect_success 'emacs delivery of signed message' \
33 "test signed message 001" \
34 "This is a test signed message." \
35 "(mml-secure-message-sign)"'
37 test_begin_subtest "signature verification"
38 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
39 | notmuch_json_show_sanitize \
40 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
41 expected='[[[{"id": "XXXXX",
45 "timestamp": 946728000,
46 "date_relative": "2000-01-01",
47 "tags": ["inbox","signed"],
48 "headers": {"Subject": "test signed message 001",
49 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
50 "To": "test_suite@notmuchmail.org",
51 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
53 "sigstatus": [{"status": "good",
54 "fingerprint": "'$FINGERPRINT'",
55 "created": 946728000}],
56 "content-type": "multipart/signed",
58 "content-type": "text/plain",
59 "content": "This is a test signed message.\n"},
61 "content-type": "application/pgp-signature",
62 "content-length": "NONZERO"}]}]},
64 test_expect_equal_json \
68 test_begin_subtest "signature verification with full owner trust"
69 # give the key full owner trust
70 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
71 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
72 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
73 | notmuch_json_show_sanitize \
74 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
75 expected='[[[{"id": "XXXXX",
79 "timestamp": 946728000,
80 "date_relative": "2000-01-01",
81 "tags": ["inbox","signed"],
82 "headers": {"Subject": "test 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": "good",
88 "fingerprint": "'$FINGERPRINT'",
90 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
91 "content-type": "multipart/signed",
93 "content-type": "text/plain",
94 "content": "This is a test signed message.\n"},
96 "content-type": "application/pgp-signature",
97 "content-length": "NONZERO"}]}]},
99 test_expect_equal_json \
103 test_begin_subtest "signature verification with signer key unavailable"
104 # move the gnupghome temporarily out of the way
105 mv "${GNUPGHOME}"{,.bak}
106 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
107 | notmuch_json_show_sanitize \
108 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
109 expected='[[[{"id": "XXXXX",
113 "timestamp": 946728000,
114 "date_relative": "2000-01-01",
115 "tags": ["inbox","signed"],
116 "headers": {"Subject": "test signed message 001",
117 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
118 "To": "test_suite@notmuchmail.org",
119 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
121 "sigstatus": [{"status": "error",
122 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
124 "content-type": "multipart/signed",
125 "content": [{"id": 2,
126 "content-type": "text/plain",
127 "content": "This is a test signed message.\n"},
129 "content-type": "application/pgp-signature",
130 "content-length": "NONZERO"}]}]},
132 test_expect_equal_json \
135 mv "${GNUPGHOME}"{.bak,}
137 # create a test encrypted message with attachment
138 cat <<EOF >TESTATTACHMENT
141 test_expect_success 'emacs delivery of encrypted message with attachment' \
143 "test encrypted message 001" \
144 "This is a test encrypted message.\n" \
145 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
147 test_begin_subtest "decryption, --format=text"
148 output=$(notmuch show --format=text --decrypt subject:"test encrypted message 001" \
149 | notmuch_show_sanitize_all \
150 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
151 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
153 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
154 Subject: test encrypted message 001
155 From: Notmuch Test Suite <test_suite@notmuchmail.org>
156 To: test_suite@notmuchmail.org
157 Date: Sat, 01 Jan 2000 12:00:00 +0000
160 \fpart{ ID: 1, Content-type: multipart/encrypted
161 \fpart{ ID: 2, Content-type: application/pgp-encrypted
162 Non-text part: application/pgp-encrypted
164 \fpart{ ID: 3, Content-type: multipart/mixed
165 \fpart{ ID: 4, Content-type: text/plain
166 This is a test encrypted message.
168 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
169 Non-text part: application/octet-stream
179 test_begin_subtest "decryption, --format=json"
180 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
181 | notmuch_json_show_sanitize \
182 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
183 expected='[[[{"id": "XXXXX",
187 "timestamp": 946728000,
188 "date_relative": "2000-01-01",
189 "tags": ["encrypted","inbox"],
190 "headers": {"Subject": "test encrypted message 001",
191 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
192 "To": "test_suite@notmuchmail.org",
193 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
195 "encstatus": [{"status": "good"}],
197 "content-type": "multipart/encrypted",
198 "content": [{"id": 2,
199 "content-type": "application/pgp-encrypted",
200 "content-length": "NONZERO"},
202 "content-type": "multipart/mixed",
203 "content": [{"id": 4,
204 "content-type": "text/plain",
205 "content": "This is a test encrypted message.\n"},
207 "content-type": "application/octet-stream",
208 "content-length": "NONZERO",
209 "content-transfer-encoding": "base64",
210 "filename": "TESTATTACHMENT"}]}]}]},
212 test_expect_equal_json \
216 test_begin_subtest "decryption, --format=json, --part=4"
217 output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
218 | notmuch_json_show_sanitize \
219 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
221 "content-type": "text/plain",
222 "content": "This is a test encrypted message.\n"}'
223 test_expect_equal_json \
227 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
232 subject:"test encrypted message 001" >OUTPUT
233 test_expect_equal_file OUTPUT TESTATTACHMENT
235 test_begin_subtest "decryption failure with missing key"
236 mv "${GNUPGHOME}"{,.bak}
237 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
238 | notmuch_json_show_sanitize \
239 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
240 expected='[[[{"id": "XXXXX",
244 "timestamp": 946728000,
245 "date_relative": "2000-01-01",
246 "tags": ["encrypted","inbox"],
247 "headers": {"Subject": "test encrypted message 001",
248 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
249 "To": "test_suite@notmuchmail.org",
250 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
252 "encstatus": [{"status": "bad"}],
253 "content-type": "multipart/encrypted",
254 "content": [{"id": 2,
255 "content-type": "application/pgp-encrypted",
256 "content-length": "NONZERO"},
258 "content-type": "application/octet-stream",
259 "content-length": "NONZERO"}]}]},
261 test_expect_equal_json \
264 mv "${GNUPGHOME}"{.bak,}
266 test_expect_success 'emacs delivery of encrypted + signed message' \
268 "test encrypted message 002" \
269 "This is another test encrypted message.\n" \
270 "(mml-secure-message-sign-encrypt)"'
272 test_begin_subtest "decryption + signature verification"
273 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
274 | notmuch_json_show_sanitize \
275 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
276 expected='[[[{"id": "XXXXX",
280 "timestamp": 946728000,
281 "date_relative": "2000-01-01",
282 "tags": ["encrypted","inbox"],
283 "headers": {"Subject": "test encrypted message 002",
284 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
285 "To": "test_suite@notmuchmail.org",
286 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
288 "encstatus": [{"status": "good"}],
289 "sigstatus": [{"status": "good",
290 "fingerprint": "'$FINGERPRINT'",
291 "created": 946728000,
292 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
293 "content-type": "multipart/encrypted",
294 "content": [{"id": 2,
295 "content-type": "application/pgp-encrypted",
296 "content-length": "NONZERO"},
298 "content-type": "text/plain",
299 "content": "This is another test encrypted message.\n"}]}]},
301 test_expect_equal_json \
305 test_begin_subtest "reply to encrypted message"
306 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
307 | grep -v -e '^In-Reply-To:' -e '^References:')
308 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
309 Subject: Re: test encrypted message 002
311 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
312 > This is another test encrypted message.'
317 test_begin_subtest "Reply within emacs to an encrypted message"
318 test_emacs "(let ((message-hidden-headers '())
319 (notmuch-crypto-process-mime 't))
320 (notmuch-show \"subject:test.encrypted.message.002\")
323 # the empty To: is probably a bug, but it's not to do with encryption
324 grep -v -e '^In-Reply-To:' -e '^References:' -e '^Fcc:' -e 'To:' < OUTPUT > OUTPUT.clean
326 From: Notmuch Test Suite <test_suite@notmuchmail.org>
327 Subject: Re: test encrypted message 002
328 --text follows this line--
329 <#secure method=pgpmime mode=signencrypt>
330 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
332 > This is another test encrypted message.
334 test_expect_equal_file EXPECTED OUTPUT.clean
336 test_begin_subtest "signature verification with revoked key"
337 # generate revocation certificate and load it to revoke key
340 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
345 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
346 | gpg --no-tty --quiet --import
347 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
348 | notmuch_json_show_sanitize \
349 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
350 expected='[[[{"id": "XXXXX",
354 "timestamp": 946728000,
355 "date_relative": "2000-01-01",
356 "tags": ["inbox","signed"],
357 "headers": {"Subject": "test signed message 001",
358 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
359 "To": "test_suite@notmuchmail.org",
360 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
362 "sigstatus": [{"status": "error",
363 "keyid": "6D92612D94E46381",
365 "content-type": "multipart/signed",
366 "content": [{"id": 2,
367 "content-type": "text/plain",
368 "content": "This is a test signed message.\n"},
370 "content-type": "application/pgp-signature",
371 "content-length": "NONZERO"}]}]},
373 test_expect_equal_json \