3 test_description='S/MIME signature verification and decryption'
4 . $(dirname "$0")/test-lib.sh || exit 1
6 test_require_external_prereq openssl
7 test_require_external_prereq gpgsm
9 FINGERPRINT=$(openssl x509 -sha1 -fingerprint -in "$NOTMUCH_SRCDIR/test/smime/key+cert.pem" -noout | sed -e 's/^.*=//' -e s/://g)
13 test_begin_subtest "emacs delivery of S/MIME signed message"
16 "test signed message 001" \
17 "This is a test signed message." \
18 "(mml-secure-message-sign \"smime\")"'
20 test_begin_subtest "emacs delivery of S/MIME encrypted + signed message"
21 # Hard code the MML to avoid several interactive questions
24 "test encrypted message 001" \
25 "<#secure method=smime mode=signencrypt>\nThis is a test encrypted message.\n"'
27 test_begin_subtest "Signature verification (openssl)"
28 notmuch show --format=raw subject:"test signed message 001" |\
29 openssl smime -verify -CAfile $NOTMUCH_SRCDIR/test/smime/test.crt 2>OUTPUT
31 Verification successful
33 test_expect_equal_file EXPECTED OUTPUT
35 test_begin_subtest "signature verification (notmuch CLI)"
36 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
37 | notmuch_json_show_sanitize \
38 | sed -e 's|"created": [-1234567890]*|"created": 946728000|g' \
39 -e 's|"expires": [-1234567890]*|"expires": 424242424|g' )
40 expected='[[[{"id": "XXXXX",
43 "filename": ["YYYYY"],
44 "timestamp": 946728000,
45 "date_relative": "2000-01-01",
46 "tags": ["inbox","signed"],
47 "crypto": {"signed": {"status": [{"fingerprint": "'$FINGERPRINT'", "status": "good","userid": "CN=Notmuch Test Suite","expires": 424242424, "created": 946728000}]}},
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": [{"fingerprint": "'$FINGERPRINT'",
55 "userid": "CN=Notmuch Test Suite",
57 "created": 946728000}],
58 "content-type": "multipart/signed",
60 "content-type": "text/plain",
61 "content": "This is a test signed message.\n"},
63 "content-disposition": "attachment",
64 "content-length": "NONZERO",
65 "content-transfer-encoding": "base64",
66 "content-type": "application/pkcs7-signature",
67 "filename": "smime.p7s"}]}]},
69 test_expect_equal_json \
73 test_begin_subtest "Decryption and signature verification (openssl)"
74 notmuch show --format=raw subject:"test encrypted message 001" |\
75 openssl smime -decrypt -recip $NOTMUCH_SRCDIR/test/smime/key+cert.pem |\
76 openssl smime -verify -CAfile $NOTMUCH_SRCDIR/test/smime/test.crt 2>OUTPUT
78 Verification successful
80 test_expect_equal_file EXPECTED OUTPUT
82 test_begin_subtest "Decryption (notmuch CLI)"
83 notmuch show --decrypt=true subject:"test encrypted message 001" |\
84 grep "^This is a" > OUTPUT
86 This is a test encrypted message.
88 test_expect_equal_file EXPECTED OUTPUT
90 test_begin_subtest "Cryptographic message status (encrypted+signed)"
91 output=$(notmuch show --format=json --decrypt=true subject:"test encrypted message 001")
92 test_json_nodes <<<"$output" \
93 'crypto_encrypted:[0][0][0]["crypto"]["decrypted"]["status"]="full"' \
94 'crypto_sigok:[0][0][0]["crypto"]["signed"]["status"][0]["status"]="good"' \
95 'crypto_fpr:[0][0][0]["crypto"]["signed"]["status"][0]["fingerprint"]="616F46CD73834C63847756AF0DFB64A6E0972A47"' \
96 'crypto_uid:[0][0][0]["crypto"]["signed"]["status"][0]["userid"]="CN=Notmuch Test Suite"'
98 test_begin_subtest "encrypted+signed message is known to be encrypted, but signature is unknown"
99 output=$(notmuch search subject:"test encrypted message 001")
100 test_expect_equal "$output" "thread:0000000000000002 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox)"
102 test_begin_subtest "Encrypted body is not indexed"
103 output=$(notmuch search 'this is a test encrypted message')
104 test_expect_equal "$output" ""
106 test_begin_subtest "Reindex cleartext"
107 test_expect_success "notmuch reindex --decrypt=true subject:'test encrypted message 001'"
109 test_begin_subtest "signature is now known"
110 output=$(notmuch search subject:"test encrypted message 001")
111 test_expect_equal "$output" "thread:0000000000000002 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox signed)"
113 test_begin_subtest "Encrypted body is indexed"
114 output=$(notmuch search 'this is a test encrypted message')
115 test_expect_equal "$output" "thread:0000000000000002 2000-01-01 [1/1] Notmuch Test Suite; test encrypted message 001 (encrypted inbox signed)"
117 add_email_corpus pkcs7
119 test_begin_subtest "index PKCS#7 SignedData message"
120 output=$(notmuch search --output=messages Thanks)
121 expected=id:smime-onepart-signed@protected-headers.example
122 test_expect_equal "$expected" "$output"
124 test_begin_subtest "do not index embedded certificates from PKCS#7 SignedData"
125 output=$(notmuch search --output=messages 'LAMPS Certificate')
127 test_expect_equal "$expected" "$output"
129 test_begin_subtest "know the MIME type of the embedded part in PKCS#7 SignedData"
130 output=$(notmuch search --output=messages 'mimetype:text/plain')
131 expected=id:smime-onepart-signed@protected-headers.example
132 test_expect_equal "$expected" "$output"
134 test_begin_subtest "PKCS#7 SignedData message is tagged 'signed'"
135 output=$(notmuch dump id:smime-onepart-signed@protected-headers.example)
136 expected='#notmuch-dump batch-tag:3 config,properties,tags
137 +inbox +signed +unread -- id:smime-onepart-signed@protected-headers.example'
138 test_expect_equal "$expected" "$output"
140 test_begin_subtest "show contents of PKCS#7 SignedData message"
141 output=$(notmuch show --format=raw --part=2 id:smime-onepart-signed@protected-headers.example)
143 expected="Bob, we need to cancel this contract.
145 Please start the necessary processes to make that happen today.
151 OpenPGP Example Corp"
152 test_expect_equal "$expected" "$output"
154 test_begin_subtest "reply to PKCS#7 SignedData message with proper quoting and attribution"
155 output=$(notmuch reply id:smime-onepart-signed@protected-headers.example)
156 expected="From: Notmuch Test Suite <test_suite@notmuchmail.org>
157 Subject: Re: The FooCorp contract
158 To: Alice Lovelace <alice@smime.example>, Bob Babbage <bob@smime.example>
159 In-Reply-To: <smime-onepart-signed@protected-headers.example>
160 References: <smime-onepart-signed@protected-headers.example>
162 On Tue, 26 Nov 2019 20:11:29 -0400, Alice Lovelace <alice@smime.example> wrote:
163 > Bob, we need to cancel this contract.
165 > Please start the necessary processes to make that happen today.
171 > OpenPGP Example Corp"
172 test_expect_equal "$expected" "$output"
174 test_begin_subtest "show PKCS#7 SignedData outputs valid JSON"
175 output=$(notmuch show --format=json id:smime-onepart-signed@protected-headers.example)
176 test_valid_json "$output"
178 test_begin_subtest "Verify signature on PKCS#7 SignedData message"
179 if [ $NOTMUCH_HAVE_64BIT_TIME_T -ne 1 ]; then
180 test_subtest_known_broken
182 output=$(notmuch show --format=json id:smime-onepart-signed@protected-headers.example)
184 test_json_nodes <<<"$output" \
185 'created:[0][0][0]["crypto"]["signed"]["status"][0]["created"]=1574813489' \
186 'expires:[0][0][0]["crypto"]["signed"]["status"][0]["expires"]=2611032858' \
187 'fingerprint:[0][0][0]["crypto"]["signed"]["status"][0]["fingerprint"]="702BA4B157F1E2B7D16B0C6A5FFC8A7DE2057DEB"' \
188 'status:[0][0][0]["crypto"]["signed"]["status"][0]["status"]="good"'
190 test_begin_subtest "Verify signature on PKCS#7 SignedData message signer User ID"
191 if [ $NOTMUCH_GMIME_X509_CERT_VALIDITY -ne 1 ]; then
192 test_subtest_known_broken
194 test_json_nodes <<<"$output" \
195 'userid:[0][0][0]["crypto"]["signed"]["status"][0]["userid"]="CN=Alice Lovelace"'