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 ##################################################
29 FINGERPRINT=$(gpg --no-tty --list-secret-keys --with-colons --fingerprint | grep '^fpr:' | cut -d: -f10)
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": 280}]}]},
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": 280}]}]},
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": 280}]}]},
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": 11},
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": 28,
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 # The length of the encrypted attachment varies so must be normalized.
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 | sed -e 's|"content-length": 6[1234567890]*|"content-length": 652|')
242 expected='[[[{"id": "XXXXX",
246 "timestamp": 946728000,
247 "date_relative": "2000-01-01",
248 "tags": ["encrypted","inbox"],
249 "headers": {"Subject": "test encrypted message 001",
250 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
251 "To": "test_suite@notmuchmail.org",
252 "Date": "Sat, 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",
258 "content-length": 11},
260 "content-type": "application/octet-stream",
261 "content-length": 652}]}]},
263 test_expect_equal_json \
266 mv "${GNUPGHOME}"{.bak,}
268 test_expect_success 'emacs delivery of encrypted + signed message' \
270 "test encrypted message 002" \
271 "This is another test encrypted message.\n" \
272 "(mml-secure-message-sign-encrypt)"'
274 test_begin_subtest "decryption + signature verification"
275 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
276 | notmuch_json_show_sanitize \
277 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
278 expected='[[[{"id": "XXXXX",
282 "timestamp": 946728000,
283 "date_relative": "2000-01-01",
284 "tags": ["encrypted","inbox"],
285 "headers": {"Subject": "test encrypted message 002",
286 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
287 "To": "test_suite@notmuchmail.org",
288 "Date": "Sat, 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",
298 "content-length": 11},
300 "content-type": "text/plain",
301 "content": "This is another test encrypted message.\n"}]}]},
303 test_expect_equal_json \
307 test_begin_subtest "reply to encrypted message"
308 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
309 | grep -v -e '^In-Reply-To:' -e '^References:')
310 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
311 Subject: Re: test encrypted message 002
313 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
314 > This is another test encrypted message.'
319 test_begin_subtest "signature verification with revoked key"
320 # generate revocation certificate and load it to revoke key
323 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
328 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
329 | gpg --no-tty --quiet --import
330 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
331 | notmuch_json_show_sanitize \
332 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
333 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",
343 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
345 "sigstatus": [{"status": "error",
346 "keyid": "6D92612D94E46381",
348 "content-type": "multipart/signed",
349 "content": [{"id": 2,
350 "content-type": "text/plain",
351 "content": "This is a test signed message.\n"},
353 "content-type": "application/pgp-signature",
354 "content-length": 280}]}]},
356 test_expect_equal_json \