]> git.notmuchmail.org Git - notmuch/blob - test/T355-smime.sh
tests/smime: avoid copying the key+cert.pem around
[notmuch] / test / T355-smime.sh
1 #!/usr/bin/env bash
2
3 test_description='S/MIME signature verification and decryption'
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 test_require_external_prereq openssl
7 test_require_external_prereq gpgsm
8
9 FINGERPRINT=$(openssl x509 -fingerprint -in "$NOTMUCH_SRCDIR/test/smime/key+cert.pem" -noout | sed -e 's/^.*=//' -e s/://g)
10
11 add_gpgsm_home
12
13 test_begin_subtest "emacs delivery of S/MIME signed message"
14 test_expect_success \
15      'emacs_fcc_message \
16      "test signed message 001" \
17      "This is a test signed message." \
18      "(mml-secure-message-sign \"smime\")"'
19
20 test_begin_subtest "emacs delivery of S/MIME encrypted + signed message"
21 # Hard code the MML to avoid several interactive questions
22 test_expect_success \
23 'emacs_fcc_message \
24     "test encrypted message 001" \
25     "<#secure method=smime mode=signencrypt>\nThis is a test encrypted message.\n"'
26
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
30 cat <<EOF > EXPECTED
31 Verification successful
32 EOF
33 test_expect_equal_file EXPECTED OUTPUT
34
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",
41  "match": true,
42  "excluded": false,
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"},
52  "body": [{"id": 1,
53  "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
54  "status": "good",
55  "userid": "CN=Notmuch Test Suite",
56  "expires": 424242424,
57  "created": 946728000}],
58  "content-type": "multipart/signed",
59  "content": [{"id": 2,
60  "content-type": "text/plain",
61  "content": "This is a test signed message.\n"},
62  {"id": 3,
63   "content-disposition": "attachment",
64   "content-length": "NONZERO",
65   "content-transfer-encoding": "base64",
66   "content-type": "application/pkcs7-signature",
67   "filename": "smime.p7s"}]}]},
68  []]]]'
69 test_expect_equal_json \
70     "$output" \
71     "$expected"
72
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
77 cat <<EOF > EXPECTED
78 Verification successful
79 EOF
80 test_expect_equal_file EXPECTED OUTPUT
81
82 test_begin_subtest "Decryption (notmuch CLI)"
83 test_subtest_known_broken
84 notmuch show --decrypt=true subject:"test encrypted message 001" |\
85     grep "^This is a" > OUTPUT
86 cat <<EOF > EXPECTED
87 This is a test encrypted message.
88 EOF
89 test_expect_equal_file EXPECTED OUTPUT
90
91 test_done