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'
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
24 ##################################################
28 FINGERPRINT=$(gpg --no-tty --list-secret-keys --with-colons --fingerprint | grep '^fpr:' | cut -d: -f10)
30 # for some reason this is needed for emacs_deliver_message to work,
31 # although I can't figure out why
34 test_expect_success 'emacs delivery of signed message' \
35 'emacs_deliver_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",
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",
55 01 Jan 2000 12:00:00 +0000"},
57 "sigstatus": [{"status": "good",
58 "fingerprint": "'$FINGERPRINT'",
59 "created": 946728000}],
60 "content-type": "multipart/signed",
62 "content-type": "text/plain",
63 "content": "This is a test signed message.\n"},
65 "content-type": "application/pgp-signature"}]}]},
71 test_begin_subtest "signature verification with full owner trust"
72 # give the key full owner trust
73 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
74 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
75 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
76 | notmuch_json_show_sanitize \
77 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
78 expected='[[[{"id": "XXXXX",
82 "timestamp": 946728000,
83 "date_relative": "2000-01-01",
84 "tags": ["inbox","signed"],
85 "headers": {"Subject": "test signed message 001",
86 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
87 "To": "test_suite@notmuchmail.org",
89 01 Jan 2000 12:00:00 +0000"},
91 "sigstatus": [{"status": "good",
92 "fingerprint": "'$FINGERPRINT'",
94 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
95 "content-type": "multipart/signed",
97 "content-type": "text/plain",
98 "content": "This is a test signed message.\n"},
100 "content-type": "application/pgp-signature"}]}]},
106 test_begin_subtest "signature verification with signer key unavailable"
107 # move the gnupghome temporarily out of the way
108 mv "${GNUPGHOME}"{,.bak}
109 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
110 | notmuch_json_show_sanitize \
111 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
112 expected='[[[{"id": "XXXXX",
116 "timestamp": 946728000,
117 "date_relative": "2000-01-01",
118 "tags": ["inbox","signed"],
119 "headers": {"Subject": "test signed message 001",
120 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
121 "To": "test_suite@notmuchmail.org",
123 01 Jan 2000 12:00:00 +0000"},
125 "sigstatus": [{"status": "error",
126 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
128 "content-type": "multipart/signed",
129 "content": [{"id": 2,
130 "content-type": "text/plain",
131 "content": "This is a test signed message.\n"},
133 "content-type": "application/pgp-signature"}]}]},
138 mv "${GNUPGHOME}"{.bak,}
140 # create a test encrypted message with attachment
141 cat <<EOF >TESTATTACHMENT
144 test_expect_success 'emacs delivery of encrypted message with attachment' \
145 'emacs_deliver_message \
146 "test encrypted message 001" \
147 "This is a test encrypted message.\n" \
148 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
150 test_begin_subtest "decryption, --format=text"
151 output=$(notmuch show --format=text --decrypt subject:"test encrypted message 001" \
152 | notmuch_show_sanitize_all \
153 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
154 expected='
\fmessage{ id:XXXXX depth:0 match:1 excluded:0 filename:XXXXX
156 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
157 Subject: test encrypted message 001
158 From: Notmuch Test Suite <test_suite@notmuchmail.org>
159 To: test_suite@notmuchmail.org
160 Date: Sat, 01 Jan 2000 12:00:00 +0000
163 \fpart{ ID: 1, Content-type: multipart/encrypted
164 \fpart{ ID: 2, Content-type: application/pgp-encrypted
165 Non-text part: application/pgp-encrypted
167 \fpart{ ID: 3, Content-type: multipart/mixed
168 \fpart{ ID: 4, Content-type: text/plain
169 This is a test encrypted message.
171 \fattachment{ ID: 5, Filename: TESTATTACHMENT, Content-type: application/octet-stream
172 Non-text part: application/octet-stream
182 test_begin_subtest "decryption, --format=json"
183 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
184 | notmuch_json_show_sanitize \
185 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
186 expected='[[[{"id": "XXXXX",
190 "timestamp": 946728000,
191 "date_relative": "2000-01-01",
192 "tags": ["encrypted","inbox"],
193 "headers": {"Subject": "test encrypted message 001",
194 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
195 "To": "test_suite@notmuchmail.org",
197 01 Jan 2000 12:00:00 +0000"},
199 "encstatus": [{"status": "good"}],
201 "content-type": "multipart/encrypted",
202 "content": [{"id": 2,
203 "content-type": "application/pgp-encrypted"},
205 "content-type": "multipart/mixed",
206 "content": [{"id": 4,
207 "content-type": "text/plain",
208 "content": "This is a test encrypted message.\n"},
210 "content-type": "application/octet-stream",
211 "filename": "TESTATTACHMENT"}]}]}]},
217 test_begin_subtest "decryption, --format=json, --part=4"
218 output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
219 | notmuch_json_show_sanitize \
220 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
222 "content-type": "text/plain",
223 "content": "This is a test encrypted message.\n"}'
228 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
233 subject:"test encrypted message 001" >OUTPUT
234 test_expect_equal_file OUTPUT TESTATTACHMENT
236 test_begin_subtest "decryption failure with missing key"
237 mv "${GNUPGHOME}"{,.bak}
238 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
239 | notmuch_json_show_sanitize \
240 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
241 expected='[[[{"id": "XXXXX",
245 "timestamp": 946728000,
246 "date_relative": "2000-01-01",
247 "tags": ["encrypted","inbox"],
248 "headers": {"Subject": "test encrypted message 001",
249 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
250 "To": "test_suite@notmuchmail.org",
252 01 Jan 2000 12:00:00 +0000"},
254 "encstatus": [{"status": "bad"}],
255 "content-type": "multipart/encrypted",
256 "content": [{"id": 2,
257 "content-type": "application/pgp-encrypted"},
259 "content-type": "application/octet-stream"}]}]},
264 mv "${GNUPGHOME}"{.bak,}
266 test_expect_success 'emacs delivery of encrypted + signed message' \
267 'emacs_deliver_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",
287 01 Jan 2000 12:00:00 +0000"},
289 "encstatus": [{"status": "good"}],
290 "sigstatus": [{"status": "good",
291 "fingerprint": "'$FINGERPRINT'",
292 "created": 946728000,
293 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
294 "content-type": "multipart/encrypted",
295 "content": [{"id": 2,
296 "content-type": "application/pgp-encrypted"},
298 "content-type": "text/plain",
299 "content": "This is another test encrypted message.\n"}]}]},
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 "signature verification with revoked key"
318 # generate revocation certificate and load it to revoke key
321 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
326 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
327 | gpg --no-tty --quiet --import
328 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
329 | notmuch_json_show_sanitize \
330 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
331 expected='[[[{"id": "XXXXX",
335 "timestamp": 946728000,
336 "date_relative": "2000-01-01",
337 "tags": ["inbox","signed"],
338 "headers": {"Subject": "test signed message 001",
339 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
340 "To": "test_suite@notmuchmail.org",
342 01 Jan 2000 12:00:00 +0000"},
344 "sigstatus": [{"status": "error",
345 "keyid": "6D92612D94E46381",
347 "content-type": "multipart/signed",
348 "content": [{"id": 2,
349 "content-type": "text/plain",
350 "content": "This is a test signed message.\n"},
352 "content-type": "application/pgp-signature"}]}]},