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 <../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",
47 "timestamp": 946728000,
48 "date_relative": "2000-01-01",
49 "tags": ["inbox","signed"],
50 "headers": {"Subject": "test signed message 001",
51 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
52 "To": "test_suite@notmuchmail.org",
55 "Date": "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",
81 "timestamp": 946728000,
82 "date_relative": "2000-01-01",
83 "tags": ["inbox","signed"],
84 "headers": {"Subject": "test signed message 001",
85 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
86 "To": "test_suite@notmuchmail.org",
89 "Date": "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",
115 "timestamp": 946728000,
116 "date_relative": "2000-01-01",
117 "tags": ["inbox","signed"],
118 "headers": {"Subject": "test signed message 001",
119 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
120 "To": "test_suite@notmuchmail.org",
123 "Date": "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 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: 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, Content-type: application/octet-stream
172 Attachment: TESTATTACHMENT (application/octet-stream)
173 Non-text part: application/octet-stream
183 test_begin_subtest "decryption, --format=json"
184 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
185 | notmuch_json_show_sanitize \
186 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
187 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",
198 "Date": "01 Jan 2000 12:00:00 -0000"},
200 "encstatus": [{"status": "good"}],
202 "content-type": "multipart/encrypted",
203 "content": [{"id": 2,
204 "content-type": "application/pgp-encrypted"},
206 "content-type": "multipart/mixed",
207 "content": [{"id": 4,
208 "content-type": "text/plain",
209 "content": "This is a test encrypted message.\n"},
211 "content-type": "application/octet-stream",
212 "filename": "TESTATTACHMENT"}]}]}]},
218 test_begin_subtest "decryption, --format=json, --part=4"
219 output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
220 | notmuch_json_show_sanitize \
221 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
223 "content-type": "text/plain",
224 "content": "This is a test encrypted message.\n"}'
229 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
234 subject:"test encrypted message 001" >OUTPUT
235 test_expect_equal_file OUTPUT TESTATTACHMENT
237 test_begin_subtest "decryption failure with missing key"
238 mv "${GNUPGHOME}"{,.bak}
239 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
240 | notmuch_json_show_sanitize \
241 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
242 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",
253 "Date": "01 Jan 2000 12:00:00 -0000"},
255 "encstatus": [{"status": "bad"}],
256 "content-type": "multipart/encrypted",
257 "content": [{"id": 2,
258 "content-type": "application/pgp-encrypted"},
260 "content-type": "application/octet-stream"}]}]},
265 mv "${GNUPGHOME}"{.bak,}
267 test_expect_success 'emacs delivery of encrypted + signed message' \
268 'emacs_deliver_message \
269 "test encrypted message 002" \
270 "This is another test encrypted message.\n" \
271 "(mml-secure-message-sign-encrypt)"'
273 test_begin_subtest "decryption + signature verification"
274 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
275 | notmuch_json_show_sanitize \
276 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
277 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",
288 "Date": "01 Jan 2000 12:00:00 -0000"},
290 "encstatus": [{"status": "good"}],
291 "sigstatus": [{"status": "good",
292 "fingerprint": "'$FINGERPRINT'",
293 "created": 946728000,
294 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
295 "content-type": "multipart/encrypted",
296 "content": [{"id": 2,
297 "content-type": "application/pgp-encrypted"},
299 "content-type": "text/plain",
300 "content": "This is another test encrypted message.\n"}]}]},
306 test_begin_subtest "reply to encrypted message"
307 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
308 | grep -v -e '^In-Reply-To:' -e '^References:')
309 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
310 Subject: Re: test encrypted message 002
312 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
313 Non-text part: multipart/encrypted
314 Non-text part: application/pgp-encrypted
315 > This is another test encrypted message.'
320 test_begin_subtest "signature verification with revoked key"
321 # generate revokation certificate and load it to revoke key
324 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
329 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
330 | gpg --no-tty --quiet --import
331 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
332 | notmuch_json_show_sanitize \
333 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
334 expected='[[[{"id": "XXXXX",
337 "timestamp": 946728000,
338 "date_relative": "2000-01-01",
339 "tags": ["inbox","signed"],
340 "headers": {"Subject": "test signed message 001",
341 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
342 "To": "test_suite@notmuchmail.org",
345 "Date": "01 Jan 2000 12:00:00 -0000"},
347 "sigstatus": [{"status": "error",
348 "keyid": "6D92612D94E46381",
350 "content-type": "multipart/signed",
351 "content": [{"id": 2,
352 "content-type": "text/plain",
353 "content": "This is a test signed message.\n"},
355 "content-type": "application/pgp-signature"}]}]},