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/mixed
164 \fpart{ ID: 2, Content-type: text/plain
165 This is a test encrypted message.
167 \fattachment{ ID: 3, Content-type: application/octet-stream
168 Attachment: TESTATTACHMENT (application/octet-stream)
169 Non-text part: application/octet-stream
178 test_begin_subtest "decryption, --format=json"
179 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
180 | notmuch_json_show_sanitize \
181 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
182 expected='[[[{"id": "XXXXX",
185 "timestamp": 946728000,
186 "date_relative": "2000-01-01",
187 "tags": ["encrypted","inbox"],
188 "headers": {"Subject": "test encrypted message 001",
189 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
190 "To": "test_suite@notmuchmail.org",
193 "Date": "01 Jan 2000 12:00:00 -0000"},
195 "encstatus": [{"status": "good"}],
197 "content-type": "multipart/mixed",
198 "content": [{"id": 2,
199 "content-type": "text/plain",
200 "content": "This is a test encrypted message.\n"},
202 "content-type": "application/octet-stream",
203 "filename": "TESTATTACHMENT"}]}]},
209 test_begin_subtest "decryption, --format=json, --part=2"
210 output=$(notmuch show --format=json --part=2 --decrypt subject:"test encrypted message 001" \
211 | notmuch_json_show_sanitize \
212 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
214 "content-type": "text/plain",
215 "content": "This is a test encrypted message.\n"}'
220 test_begin_subtest "decrypt attachment (--part=3 --format=raw)"
225 subject:"test encrypted message 001" >OUTPUT
226 test_expect_equal_file OUTPUT TESTATTACHMENT
228 test_begin_subtest "decryption failure with missing key"
229 mv "${GNUPGHOME}"{,.bak}
230 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
231 | notmuch_json_show_sanitize \
232 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
233 expected='[[[{"id": "XXXXX",
236 "timestamp": 946728000,
237 "date_relative": "2000-01-01",
238 "tags": ["encrypted","inbox"],
239 "headers": {"Subject": "test encrypted message 001",
240 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
241 "To": "test_suite@notmuchmail.org",
244 "Date": "01 Jan 2000 12:00:00 -0000"},
246 "encstatus": [{"status": "bad"}],
247 "content-type": "multipart/encrypted",
248 "content": [{"id": 2,
249 "content-type": "application/pgp-encrypted"},
251 "content-type": "application/octet-stream"}]}]},
256 mv "${GNUPGHOME}"{.bak,}
258 test_expect_success 'emacs delivery of encrypted + signed message' \
259 'emacs_deliver_message \
260 "test encrypted message 002" \
261 "This is another test encrypted message.\n" \
262 "(mml-secure-message-sign-encrypt)"'
264 test_begin_subtest "decryption + signature verification"
265 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
266 | notmuch_json_show_sanitize \
267 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
268 expected='[[[{"id": "XXXXX",
271 "timestamp": 946728000,
272 "date_relative": "2000-01-01",
273 "tags": ["encrypted","inbox"],
274 "headers": {"Subject": "test encrypted message 002",
275 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
276 "To": "test_suite@notmuchmail.org",
279 "Date": "01 Jan 2000 12:00:00 -0000"},
281 "encstatus": [{"status": "good"}],
282 "sigstatus": [{"status": "good",
283 "fingerprint": "'$FINGERPRINT'",
284 "created": 946728000,
285 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
286 "content-type": "text/plain",
287 "content": "This is another test encrypted message.\n"}]},
293 test_begin_subtest "reply to encrypted message"
294 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
295 | grep -v -e '^In-Reply-To:' -e '^References:')
296 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
297 Subject: Re: test encrypted message 002
299 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
300 > This is another test encrypted message.'
305 test_begin_subtest "signature verification with revoked key"
306 # generate revokation certificate and load it to revoke key
309 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
314 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
315 | gpg --no-tty --quiet --import
316 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
317 | notmuch_json_show_sanitize \
318 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
319 expected='[[[{"id": "XXXXX",
322 "timestamp": 946728000,
323 "date_relative": "2000-01-01",
324 "tags": ["inbox","signed"],
325 "headers": {"Subject": "test signed message 001",
326 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
327 "To": "test_suite@notmuchmail.org",
330 "Date": "01 Jan 2000 12:00:00 -0000"},
332 "sigstatus": [{"status": "error",
333 "keyid": "6D92612D94E46381",
335 "content-type": "multipart/signed",
336 "content": [{"id": 2,
337 "content-type": "text/plain",
338 "content": "This is a test signed message.\n"},
340 "content-type": "application/pgp-signature"}]}]},