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",
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": "text/plain",
61 "content": "This is a test signed message.\n"}]},
67 test_begin_subtest "signature verification with full owner trust"
68 # give the key full owner trust
69 echo "${FINGERPRINT}:6:" | gpg --no-tty --import-ownertrust >>"$GNUPGHOME"/trust.log 2>&1
70 gpg --no-tty --check-trustdb >>"$GNUPGHOME"/trust.log 2>&1
71 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
72 | notmuch_json_show_sanitize \
73 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
74 expected='[[[{"id": "XXXXX",
77 "timestamp": 946728000,
78 "date_relative": "2000-01-01",
80 "headers": {"Subject": "test signed message 001",
81 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
82 "To": "test_suite@notmuchmail.org",
85 "Date": "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": "text/plain",
92 "content": "This is a test signed message.\n"}]},
98 test_begin_subtest "signature verification with signer key unavailable"
99 # move the gnupghome temporarily out of the way
100 mv "${GNUPGHOME}"{,.bak}
101 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
102 | notmuch_json_show_sanitize \
103 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
104 expected='[[[{"id": "XXXXX",
107 "timestamp": 946728000,
108 "date_relative": "2000-01-01",
110 "headers": {"Subject": "test signed message 001",
111 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
112 "To": "test_suite@notmuchmail.org",
115 "Date": "01 Jan 2000 12:00:00 -0000"},
117 "sigstatus": [{"status": "error",
118 "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'",
120 "content-type": "text/plain",
121 "content": "This is a test signed message.\n"}]},
126 mv "${GNUPGHOME}"{.bak,}
128 # create a test encrypted message with attachment
129 cat <<EOF >TESTATTACHMENT
132 test_expect_success 'emacs delivery of encrypted message with attachment' \
133 'emacs_deliver_message \
134 "test encrypted message 001" \
135 "This is a test encrypted message.\n" \
136 "(mml-attach-file \"TESTATTACHMENT\") (mml-secure-message-encrypt)"'
138 test_begin_subtest "decryption, --format=text"
139 output=$(notmuch show --format=text --decrypt subject:"test encrypted message 001" \
140 | notmuch_show_sanitize_all \
141 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
142 expected='
\fmessage{ id:XXXXX depth:0 match:1 filename:XXXXX
144 Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (inbox)
145 Subject: test encrypted message 001
146 From: Notmuch Test Suite <test_suite@notmuchmail.org>
147 To: test_suite@notmuchmail.org
148 Date: 01 Jan 2000 12:00:00 -0000
151 \fpart{ ID: 1, Content-type: multipart/mixed
152 \fpart{ ID: 2, Content-type: text/plain
153 This is a test encrypted message.
155 \fattachment{ ID: 3, Content-type: application/octet-stream
156 Attachment: TESTATTACHMENT (application/octet-stream)
157 Non-text part: application/octet-stream
166 test_begin_subtest "decryption, --format=json"
167 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
168 | notmuch_json_show_sanitize \
169 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
170 expected='[[[{"id": "XXXXX",
173 "timestamp": 946728000,
174 "date_relative": "2000-01-01",
176 "headers": {"Subject": "test encrypted message 001",
177 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
178 "To": "test_suite@notmuchmail.org",
181 "Date": "01 Jan 2000 12:00:00 -0000"},
183 "encstatus": [{"status": "good"}],
185 "content-type": "multipart/mixed",
186 "content": [{"id": 2,
187 "content-type": "text/plain",
188 "content": "This is a test encrypted message.\n"},
190 "content-type": "application/octet-stream",
191 "filename": "TESTATTACHMENT"}]}]},
197 test_begin_subtest "decryption, --format=json, --part=2"
198 output=$(notmuch show --format=json --part=2 --decrypt subject:"test encrypted message 001" \
199 | notmuch_json_show_sanitize \
200 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
202 "content-type": "text/plain",
203 "content": "This is a test encrypted message.\n"}'
208 test_begin_subtest "decrypt attachment (--part=3 --format=raw)"
213 subject:"test encrypted message 001" >OUTPUT
214 test_expect_equal_file OUTPUT TESTATTACHMENT
216 test_begin_subtest "decryption failure with missing key"
217 mv "${GNUPGHOME}"{,.bak}
218 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 001" \
219 | notmuch_json_show_sanitize \
220 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
221 expected='[[[{"id": "XXXXX",
224 "timestamp": 946728000,
225 "date_relative": "2000-01-01",
227 "headers": {"Subject": "test encrypted message 001",
228 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
229 "To": "test_suite@notmuchmail.org",
232 "Date": "01 Jan 2000 12:00:00 -0000"},
234 "encstatus": [{"status": "bad"}],
235 "content-type": "multipart/encrypted",
236 "content": [{"id": 2,
237 "content-type": "application/pgp-encrypted"},
239 "content-type": "application/octet-stream"}]}]},
244 mv "${GNUPGHOME}"{.bak,}
246 test_expect_success 'emacs delivery of encrypted + signed message' \
247 'emacs_deliver_message \
248 "test encrypted message 002" \
249 "This is another test encrypted message.\n" \
250 "(mml-secure-message-sign-encrypt)"'
252 test_begin_subtest "decryption + signature verification"
253 output=$(notmuch show --format=json --decrypt subject:"test encrypted message 002" \
254 | notmuch_json_show_sanitize \
255 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
256 expected='[[[{"id": "XXXXX",
259 "timestamp": 946728000,
260 "date_relative": "2000-01-01",
262 "headers": {"Subject": "test encrypted message 002",
263 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
264 "To": "test_suite@notmuchmail.org",
267 "Date": "01 Jan 2000 12:00:00 -0000"},
269 "encstatus": [{"status": "good"}],
270 "sigstatus": [{"status": "good",
271 "fingerprint": "'$FINGERPRINT'",
272 "created": 946728000,
273 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
274 "content-type": "text/plain",
275 "content": "This is another test encrypted message.\n"}]},
281 test_begin_subtest "reply to encrypted message"
282 output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
283 | grep -v -e '^In-Reply-To:' -e '^References:')
284 expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
285 Subject: Re: test encrypted message 002
287 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
288 > This is another test encrypted message.'
293 test_begin_subtest "signature verification with revoked key"
294 # generate revokation certificate and load it to revoke key
297 Notmuch Test Suite key revocation (automated) $(date '+%F_%T%z')
302 | gpg --no-tty --quiet --command-fd 0 --armor --gen-revoke "0x${FINGERPRINT}!" 2>/dev/null \
303 | gpg --no-tty --quiet --import
304 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
305 | notmuch_json_show_sanitize \
306 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
307 expected='[[[{"id": "XXXXX",
310 "timestamp": 946728000,
311 "date_relative": "2000-01-01",
313 "headers": {"Subject": "test signed message 001",
314 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
315 "To": "test_suite@notmuchmail.org",
318 "Date": "01 Jan 2000 12:00:00 -0000"},
320 "sigstatus": [{"status": "error",
321 "keyid": "6D92612D94E46381",
323 "content-type": "text/plain",
324 "content": "This is a test signed message.\n"}]},