]> git.notmuchmail.org Git - notmuch/blob - test/T355-smime.sh
test: add broken S/MIME signature verification test for notmuch CLI
[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 test_subtest_known_broken
48 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
49     | notmuch_json_show_sanitize \
50     | sed -e 's|"created": [-1234567890]*|"created": 946728000|' \
51           -e 's|"expires": [-1234567890]*|"expires": 424242424|' )
52 expected='[[[{"id": "XXXXX",
53  "match": true,
54  "excluded": false,
55  "filename": "YYYYY",
56  "timestamp": 946728000,
57  "date_relative": "2000-01-01",
58  "tags": ["inbox","signed"],
59  "headers": {"Subject": "test signed message 001",
60  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
61  "To": "test_suite@notmuchmail.org",
62  "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
63  "body": [{"id": 1,
64  "sigstatus": [{"status": "good",
65  "fingerprint": "'$FINGERPRINT'",
66  "expires": 424242424,
67  "created": 946728000}],
68  "content-type": "multipart/signed",
69  "content": [{"id": 2,
70  "content-type": "text/plain",
71  "content": "This is a test signed message.\n"},
72  {"id": 3,
73   "content-length": 1922,
74   "content-transfer-encoding": "base64",
75   "content-type": "application/x-pkcs7-signature",
76   "filename": "smime.p7s"}]}]},
77  []]]]'
78 test_expect_equal_json \
79     "$output" \
80     "$expected"
81
82 test_begin_subtest "Decryption and signature verification (openssl)"
83 notmuch show --format=raw subject:"test encrypted message 001" |\
84     openssl smime -decrypt -recip test_suite.pem |\
85     openssl smime -verify -CAfile $TEST_DIRECTORY/smime/test.crt 2>OUTPUT
86 cat <<EOF > EXPECTED
87 Verification successful
88 EOF
89 test_expect_equal_file EXPECTED OUTPUT
90
91 test_done