3 test_description='S/MIME signature verification and decryption'
4 . $(dirname "$0")/test-lib.sh || exit 1
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 < $NOTMUCH_SRCDIR/test/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"
19 test_require_external_prereq openssl
20 test_require_external_prereq gpgsm
22 cp $NOTMUCH_SRCDIR/test/smime/key+cert.pem test_suite.pem
24 FINGERPRINT=$(openssl x509 -fingerprint -in test_suite.pem -noout | sed -e 's/^.*=//' -e s/://g)
28 test_begin_subtest "emacs delivery of S/MIME signed message"
31 "test signed message 001" \
32 "This is a test signed message." \
33 "(mml-secure-message-sign \"smime\")"'
35 test_begin_subtest "emacs delivery of S/MIME encrypted + signed message"
36 # Hard code the MML to avoid several interactive questions
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"'
42 test_begin_subtest "Signature verification (openssl)"
43 notmuch show --format=raw subject:"test signed message 001" |\
44 openssl smime -verify -CAfile $NOTMUCH_SRCDIR/test/smime/test.crt 2>OUTPUT
46 Verification successful
48 test_expect_equal_file EXPECTED OUTPUT
50 test_begin_subtest "signature verification (notmuch CLI)"
51 if [ "${NOTMUCH_GMIME_MAJOR}" -lt 3 ]; then
52 # gmime 2 can't report User IDs properly for S/MIME
55 USERID='"userid": "CN=Notmuch Test Suite",'
57 output=$(notmuch show --format=json --verify subject:"test signed message 001" \
58 | notmuch_json_show_sanitize \
59 | sed -e 's|"created": [-1234567890]*|"created": 946728000|' \
60 -e 's|"expires": [-1234567890]*|"expires": 424242424|' )
61 expected='[[[{"id": "XXXXX",
64 "filename": ["YYYYY"],
65 "timestamp": 946728000,
66 "date_relative": "2000-01-01",
67 "tags": ["inbox","signed"],
68 "headers": {"Subject": "test signed message 001",
69 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
70 "To": "test_suite@notmuchmail.org",
71 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
73 "sigstatus": [{"fingerprint": "'$FINGERPRINT'",
74 "status": "good",'$USERID'
76 "created": 946728000}],
77 "content-type": "multipart/signed",
79 "content-type": "text/plain",
80 "content": "This is a test signed message.\n"},
82 "content-disposition": "attachment",
83 "content-length": "NONZERO",
84 "content-transfer-encoding": "base64",
85 "content-type": "application/x-pkcs7-signature",
86 "filename": "smime.p7s"}]}]},
88 test_expect_equal_json \
92 test_begin_subtest "Decryption and signature verification (openssl)"
93 notmuch show --format=raw subject:"test encrypted message 001" |\
94 openssl smime -decrypt -recip test_suite.pem |\
95 openssl smime -verify -CAfile $NOTMUCH_SRCDIR/test/smime/test.crt 2>OUTPUT
97 Verification successful
99 test_expect_equal_file EXPECTED OUTPUT