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