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