]> git.notmuchmail.org Git - notmuch/blob - test/T355-smime.sh
tests/smime: consistently quote $GNUPGHOME
[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 cp $NOTMUCH_SRCDIR/test/smime/key+cert.pem test_suite.pem
10
11 FINGERPRINT=$(openssl x509 -fingerprint -in test_suite.pem -noout | sed -e 's/^.*=//' -e s/://g)
12
13 add_gpgsm_home
14
15 test_begin_subtest "emacs delivery of S/MIME signed message"
16 test_expect_success \
17      'emacs_fcc_message \
18      "test signed message 001" \
19      "This is a test signed message." \
20      "(mml-secure-message-sign \"smime\")"'
21
22 test_begin_subtest "emacs delivery of S/MIME encrypted + signed message"
23 # Hard code the MML to avoid several interactive questions
24 test_expect_success \
25 'emacs_fcc_message \
26     "test encrypted message 001" \
27     "<#secure method=smime mode=signencrypt keyfile=\\\"test_suite.pem\\\" certfile=\\\"test_suite.pem\\\">\nThis is a test encrypted message.\n"'
28
29 test_begin_subtest "Signature verification (openssl)"
30 notmuch show --format=raw subject:"test signed message 001" |\
31     openssl smime -verify -CAfile $NOTMUCH_SRCDIR/test/smime/test.crt 2>OUTPUT
32 cat <<EOF > EXPECTED
33 Verification successful
34 EOF
35 test_expect_equal_file EXPECTED OUTPUT
36
37 test_begin_subtest "signature verification (notmuch CLI)"
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|g' \
41           -e 's|"expires": [-1234567890]*|"expires": 424242424|g' )
42 expected='[[[{"id": "XXXXX",
43  "match": true,
44  "excluded": false,
45  "filename": ["YYYYY"],
46  "timestamp": 946728000,
47  "date_relative": "2000-01-01",
48  "tags": ["inbox","signed"],
49  "crypto": {"signed": {"status": [{"fingerprint": "'$FINGERPRINT'", "status": "good","userid": "CN=Notmuch Test Suite","expires": 424242424, "created": 946728000}]}},
50  "headers": {"Subject": "test signed message 001",
51  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
52  "To": "test_suite@notmuchmail.org",
53  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
54  "body": [{"id": 1,
55  "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
56  "status": "good",
57  "userid": "CN=Notmuch Test Suite",
58  "expires": 424242424,
59  "created": 946728000}],
60  "content-type": "multipart/signed",
61  "content": [{"id": 2,
62  "content-type": "text/plain",
63  "content": "This is a test signed message.\n"},
64  {"id": 3,
65   "content-disposition": "attachment",
66   "content-length": "NONZERO",
67   "content-transfer-encoding": "base64",
68   "content-type": "application/x-pkcs7-signature",
69   "filename": "smime.p7s"}]}]},
70  []]]]'
71 test_expect_equal_json \
72     "$output" \
73     "$expected"
74
75 test_begin_subtest "Decryption and signature verification (openssl)"
76 notmuch show --format=raw subject:"test encrypted message 001" |\
77     openssl smime -decrypt -recip test_suite.pem |\
78     openssl smime -verify -CAfile $NOTMUCH_SRCDIR/test/smime/test.crt 2>OUTPUT
79 cat <<EOF > EXPECTED
80 Verification successful
81 EOF
82 test_expect_equal_file EXPECTED OUTPUT
83
84 test_begin_subtest "Decryption (notmuch CLI)"
85 test_subtest_known_broken
86 notmuch show --decrypt=true subject:"test encrypted message 001" |\
87     grep "^This is a" > OUTPUT
88 cat <<EOF > EXPECTED
89 This is a test encrypted message.
90 EOF
91 test_expect_equal_file EXPECTED OUTPUT
92
93 test_done