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