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",
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"}]}]},
66 test_expect_equal_json \
70 test_begin_subtest "signature verification with full owner trust"
71 # give the key full owner trust
72 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
73 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
74 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
75 | notmuch_json_show_sanitize \
76 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
77 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",
87 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
89 "sigstatus": [{"status": "good",
90 "fingerprint": "'$FINGERPRINT'",
92 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
93 "content-type": "multipart/signed",
95 "content-type": "text/plain",
96 "content": "This is a test signed message.\n"},
98 "content-type": "application/pgp-signature"}]}]},
100 test_expect_equal_json \
104 test_begin_subtest "signature verification with signer key unavailable"
105 # move the gnupghome temporarily out of the way
106 mv "${GNUPGHOME}"{,.bak}
107 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
108 | notmuch_json_show_sanitize \
109 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
110 expected='[[[{"id": "XXXXX",
114 "timestamp": 946728000,
115 "date_relative": "2000-01-01",
116 "tags": ["inbox","signed"],
117 "headers": {"Subject": "test signed message 001",
118 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
119 "To": "test_suite@notmuchmail.org",
120 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
122 "sigstatus": [{"status": "error",
123 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
125 "content-type": "multipart/signed",
126 "content": [{"id": 2,
127 "content-type": "text/plain",
128 "content": "This is a test signed message.\n"},
130 "content-type": "application/pgp-signature"}]}]},
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' \
142 'emacs_deliver_message \
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"},
201 "content-type": "multipart/mixed",
202 "content": [{"id": 4,
203 "content-type": "text/plain",
204 "content": "This is a test encrypted message.\n"},
206 "content-type": "application/octet-stream",
207 "filename": "TESTATTACHMENT"}]}]}]},
209 test_expect_equal_json \
213 test_begin_subtest "decryption, --format=json, --part=4"
214 output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
215 | notmuch_json_show_sanitize \
216 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
218 "content-type": "text/plain",
219 "content": "This is a test encrypted message.\n"}'
220 test_expect_equal_json \
224 test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
229 subject:"test encrypted message 001" >OUTPUT
230 test_expect_equal_file OUTPUT TESTATTACHMENT
232 test_begin_subtest "decryption failure with missing key"
233 mv "${GNUPGHOME}"{,.bak}
234 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
235 | notmuch_json_show_sanitize \
236 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
237 expected='[[[{"id": "XXXXX",
241 "timestamp": 946728000,
242 "date_relative": "2000-01-01",
243 "tags": ["encrypted","inbox"],
244 "headers": {"Subject": "test encrypted message 001",
245 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
246 "To": "test_suite@notmuchmail.org",
247 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
249 "encstatus": [{"status": "bad"}],
250 "content-type": "multipart/encrypted",
251 "content": [{"id": 2,
252 "content-type": "application/pgp-encrypted"},
254 "content-type": "application/octet-stream"}]}]},
256 test_expect_equal_json \
259 mv "${GNUPGHOME}"{.bak,}
261 test_expect_success 'emacs delivery of encrypted + signed message' \
262 'emacs_deliver_message \
263 "test encrypted message 002" \
264 "This is another test encrypted message.\n" \
265 "(mml-secure-message-sign-encrypt)"'
267 test_begin_subtest "decryption + signature verification"
268 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
269 | notmuch_json_show_sanitize \
270 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
271 expected='[[[{"id": "XXXXX",
275 "timestamp": 946728000,
276 "date_relative": "2000-01-01",
277 "tags": ["encrypted","inbox"],
278 "headers": {"Subject": "test encrypted message 002",
279 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
280 "To": "test_suite@notmuchmail.org",
281 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
283 "encstatus": [{"status": "good"}],
284 "sigstatus": [{"status": "good",
285 "fingerprint": "'$FINGERPRINT'",
286 "created": 946728000,
287 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
288 "content-type": "multipart/encrypted",
289 "content": [{"id": 2,
290 "content-type": "application/pgp-encrypted"},
292 "content-type": "text/plain",
293 "content": "This is another test encrypted message.\n"}]}]},
295 test_expect_equal_json \
299 test_begin_subtest "reply to encrypted message"
300 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
301 | grep -v -e '^In-Reply-To:' -e '^References:')
302 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
303 Subject: Re: test encrypted message 002
305 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
306 > This is another test encrypted message.'
311 test_begin_subtest "signature verification with revoked key"
312 # generate revocation certificate and load it to revoke key
315 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
320 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
321 | gpg --no-tty --quiet --import
322 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
323 | notmuch_json_show_sanitize \
324 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
325 expected='[[[{"id": "XXXXX",
329 "timestamp": 946728000,
330 "date_relative": "2000-01-01",
331 "tags": ["inbox","signed"],
332 "headers": {"Subject": "test signed message 001",
333 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
334 "To": "test_suite@notmuchmail.org",
335 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
337 "sigstatus": [{"status": "error",
338 "keyid": "6D92612D94E46381",
340 "content-type": "multipart/signed",
341 "content": [{"id": 2,
342 "content-type": "text/plain",
343 "content": "This is a test signed message.\n"},
345 "content-type": "application/pgp-signature"}]}]},
347 test_expect_equal_json \