--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 20DDB6DE1617\r
+ for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 05:39:15 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.315\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.315 tagged_above=-999 required=5 tests=[AWL=0.236,\r
+ RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 04ClzJ5-R_4j for <notmuch@notmuchmail.org>;\r
+ Mon, 14 Dec 2015 05:39:13 -0800 (PST)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 565B16DE02CE\r
+ for <notmuch@notmuchmail.org>; Mon, 14 Dec 2015 05:39:12 -0800 (PST)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1a8TLH-0008F3-Ii; Mon, 14 Dec 2015 08:39:07 -0500\r
+Received: (nullmailer pid 31800 invoked by uid 1000);\r
+ Mon, 14 Dec 2015 13:39:05 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v3 4/8] test: initial tests for S/MIME and notmuch-emacs\r
+Date: Mon, 14 Dec 2015 09:38:53 -0400\r
+Message-Id: <1450100337-31655-5-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.6.2\r
+In-Reply-To: <1450100337-31655-1-git-send-email-david@tethera.net>\r
+References: <1450100337-31655-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 14 Dec 2015 13:39:15 -0000\r
+\r
+Test the ability of notmuch-mua-mail to send S/MIME signed (and\r
+encrypted) messages; this really relies on existing functionality in\r
+message-mode.\r
+\r
+The generated keys and messages will later be useful for testing the\r
+notmuch CLI.\r
+---\r
+ test/T355-smime.sh | 42 +++++++++++++++++++++++++++++++++++++\r
+ test/smime/README | 7 +++++++\r
+ test/smime/key+cert.pem | 56 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+ test/smime/test.crt | 19 +++++++++++++++++\r
+ test/test-lib.el | 10 +++++++++\r
+ test/test-lib.sh | 1 +\r
+ 6 files changed, 135 insertions(+)\r
+ create mode 100755 test/T355-smime.sh\r
+ create mode 100644 test/smime/README\r
+ create mode 100644 test/smime/key+cert.pem\r
+ create mode 100644 test/smime/test.crt\r
+\r
+diff --git a/test/T355-smime.sh b/test/T355-smime.sh\r
+new file mode 100755\r
+index 0000000..e3419d6\r
+--- /dev/null\r
++++ b/test/T355-smime.sh\r
+@@ -0,0 +1,42 @@\r
++#!/usr/bin/env bash\r
++\r
++test_description='S/MIME signature verification and decryption'\r
++. ./test-lib.sh\r
++\r
++test_require_external_prereq openssl\r
++test_require_external_prereq gpgsm\r
++\r
++cp $TEST_DIRECTORY/smime/key+cert.pem test_suite.pem\r
++\r
++FINGERPRINT=$(openssl x509 -fingerprint -in test_suite.pem -noout | sed -e 's/^.*=//' -e s/://g)\r
++\r
++test_expect_success 'emacs delivery of S/MIME signed message' \\r
++ 'emacs_fcc_message \\r
++ "test signed message 001" \\r
++ "This is a test signed message." \\r
++ "(mml-secure-message-sign \"smime\")"'\r
++\r
++# Hard code the MML to avoid several interactive questions\r
++test_expect_success 'emacs delivery of S/MIME encrypted + signed message' \\r
++'emacs_fcc_message \\r
++ "test encrypted message 001" \\r
++ "<#secure method=smime mode=signencrypt keyfile=\\\"test_suite.pem\\\" certfile=\\\"test_suite.pem\\\">\nThis is a test encrypted message.\n"'\r
++\r
++test_begin_subtest "Signature verification (openssl)"\r
++notmuch show --format=raw subject:"test signed message 001" |\\r
++ openssl smime -verify -CAfile $TEST_DIRECTORY/smime/test.crt 2>OUTPUT\r
++cat <<EOF > EXPECTED\r
++Verification successful\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "Decryption and signature verification (openssl)"\r
++notmuch show --format=raw subject:"test encrypted message 001" |\\r
++ openssl smime -decrypt -recip test_suite.pem |\\r
++ openssl smime -verify -CAfile $TEST_DIRECTORY/smime/test.crt 2>OUTPUT\r
++cat <<EOF > EXPECTED\r
++Verification successful\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_done\r
+diff --git a/test/smime/README b/test/smime/README\r
+new file mode 100644\r
+index 0000000..92803c7\r
+--- /dev/null\r
++++ b/test/smime/README\r
+@@ -0,0 +1,7 @@\r
++test.crt: self signed certificated\r
++ % gpgsm --gen-key # needs gpgsm 2.1\r
++\r
++key+cert.pem: cert + unencryped private\r
++ % gpsm --import test.crt\r
++ % gpgsm --export-private-key-p12 -out foo.p12 (no passphrase)\r
++ % openssl pkcs12 -in ns.p12 -clcerts -nodes > key+cert.pem\r
+diff --git a/test/smime/key+cert.pem b/test/smime/key+cert.pem\r
+new file mode 100644\r
+index 0000000..6ee30cf\r
+--- /dev/null\r
++++ b/test/smime/key+cert.pem\r
+@@ -0,0 +1,56 @@\r
++Bag Attributes\r
++ friendlyName: GnuPG exported certificate e0972a47\r
++ localKeyID: 61 6F 46 CD 73 83 4C 63 84 77 56 AF 0D FB 64 A6 E0 97 2A 47 \r
++subject=/CN=Notmuch Test Suite\r
++issuer=/CN=Notmuch Test Suite\r
++-----BEGIN CERTIFICATE-----\r
++MIIDCzCCAfOgAwIBAgIIb3SMlL0MZ6kwDQYJKoZIhvcNAQELBQAwHTEbMBkGA1UE\r
++AxMSTm90bXVjaCBUZXN0IFN1aXRlMCAXDTE1MTIxNDAyMDgxMFoYDzIwNjMwNDA1\r
++MTcwMDAwWjAdMRswGQYDVQQDExJOb3RtdWNoIFRlc3QgU3VpdGUwggEiMA0GCSqG\r
++SIb3DQEBAQUAA4IBDwAwggEKAoIBAQC7vH1/lkENTAJRbyq2036K7Pw+imSIhB5T\r
++U0WnAgVGWOemY1Eppi9Dk6rjDxuuUKOCQ5el2wmFZN57Fi/4leBH7x217BnnqWNU\r
++QV88DxEfV+sk8dSb4a5FOOyfhFJmZso/0lK8x0fBcCNjmRFIjB1afSSXWnCvRpAR\r
++v+O9trLJuIjbbmXg1gltjuB5yDw8/OLEI7G7YSIop9FxopWJL5rW/o2WEfRPGpYe\r
++HNRLObCRIvbyDd6XjaCrKBuIrhN7R7mmIa9PUyl8TiY+pCMWs9dHmOsiC73/+P6E\r
++AhsTOY1bfbGQXBAGZ/FL+SgC5wEcPr2u3+y8y5gw2bpaVhQnu6YLAgMBAAGjTTBL\r
++MCUGA1UdEQQeMByBGnRlc3Rfc3VpdGVAbm90bXVjaG1haWwub3JnMBEGCisGAQQB\r
++2kcCAgEEAwEB/zAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBb\r
++XP5OnRVplrEdlnivx3CbCLWO13fcMWXfvKxLGsKFwKuxtpvINFUKM+jDr0kVdQ3d\r
++u3DJe2hNFQMILK/KrGyN5qEz2YBdHNvdkkvWA+3WHr/tiNr6Rly6QuxBzouxzmRu\r
++MmnUhsOzZaHT3GmLSVJlwie8KqSfKVGwyBmCyHbUQkMrSEV6QDESN6KyWt85gokB\r
++56Bc/wVq073xS1nFbfF1M3Z5q5BlLZK4IOerKTQx/oSfR4EX6B7rW2pttWsUCyEj\r
++LljaA8ehxR9B29m08IGGl43pHEpC1WnOHvsEGs99mPpjWbUgVv5KY7OuS/8iVw6v\r
++/Yy5Z+JBwlMzTBaUXXl3\r
++-----END CERTIFICATE-----\r
++Bag Attributes\r
++ friendlyName: GnuPG exported certificate e0972a47\r
++ localKeyID: 61 6F 46 CD 73 83 4C 63 84 77 56 AF 0D FB 64 A6 E0 97 2A 47 \r
++Key Attributes: <No Attributes>\r
++-----BEGIN PRIVATE KEY-----\r
++MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7vH1/lkENTAJR\r
++byq2036K7Pw+imSIhB5TU0WnAgVGWOemY1Eppi9Dk6rjDxuuUKOCQ5el2wmFZN57\r
++Fi/4leBH7x217BnnqWNUQV88DxEfV+sk8dSb4a5FOOyfhFJmZso/0lK8x0fBcCNj\r
++mRFIjB1afSSXWnCvRpARv+O9trLJuIjbbmXg1gltjuB5yDw8/OLEI7G7YSIop9Fx\r
++opWJL5rW/o2WEfRPGpYeHNRLObCRIvbyDd6XjaCrKBuIrhN7R7mmIa9PUyl8TiY+\r
++pCMWs9dHmOsiC73/+P6EAhsTOY1bfbGQXBAGZ/FL+SgC5wEcPr2u3+y8y5gw2bpa\r
++VhQnu6YLAgMBAAECggEAVhtHCHz3C01Ahu9RDRgGI1w8+cZqA/9tFVTNTqNrne9r\r
++GHLXKB4z8W/KYmhsjtAnnri31neXb1prfNMZX5AGlZfD7cwDubCEgYGWV6qldNXT\r
++YVeV54VkdBV+2k9Lp/Ifc5RZJILWk4+Ge8kaF0dEs1tQrCbsJkhcDfgQUdR5PnGe\r
++6cKv/8HJo0ep6u5cJloIluit8yF3z4+aHixMQBvQKm/8tug+EsrQZ3I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END PRIVATE KEY-----\r
+diff --git a/test/smime/test.crt b/test/smime/test.crt\r
+new file mode 100644\r
+index 0000000..e5d1e82\r
+--- /dev/null\r
++++ b/test/smime/test.crt\r
+@@ -0,0 +1,19 @@\r
++-----BEGIN CERTIFICATE-----\r
++MIIDCzCCAfOgAwIBAgIIb3SMlL0MZ6kwDQYJKoZIhvcNAQELBQAwHTEbMBkGA1UE\r
++AxMSTm90bXVjaCBUZXN0IFN1aXRlMCAXDTE1MTIxNDAyMDgxMFoYDzIwNjMwNDA1\r
++MTcwMDAwWjAdMRswGQYDVQQDExJOb3RtdWNoIFRlc3QgU3VpdGUwggEiMA0GCSqG\r
++SIb3DQEBAQUAA4IBDwAwggEKAoIBAQC7vH1/lkENTAJRbyq2036K7Pw+imSIhB5T\r
++U0WnAgVGWOemY1Eppi9Dk6rjDxuuUKOCQ5el2wmFZN57Fi/4leBH7x217BnnqWNU\r
++QV88DxEfV+sk8dSb4a5FOOyfhFJmZso/0lK8x0fBcCNjmRFIjB1afSSXWnCvRpAR\r
++v+O9trLJuIjbbmXg1gltjuB5yDw8/OLEI7G7YSIop9FxopWJL5rW/o2WEfRPGpYe\r
++HNRLObCRIvbyDd6XjaCrKBuIrhN7R7mmIa9PUyl8TiY+pCMWs9dHmOsiC73/+P6E\r
++AhsTOY1bfbGQXBAGZ/FL+SgC5wEcPr2u3+y8y5gw2bpaVhQnu6YLAgMBAAGjTTBL\r
++MCUGA1UdEQQeMByBGnRlc3Rfc3VpdGVAbm90bXVjaG1haWwub3JnMBEGCisGAQQB\r
++2kcCAgEEAwEB/zAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBb\r
++XP5OnRVplrEdlnivx3CbCLWO13fcMWXfvKxLGsKFwKuxtpvINFUKM+jDr0kVdQ3d\r
++u3DJe2hNFQMILK/KrGyN5qEz2YBdHNvdkkvWA+3WHr/tiNr6Rly6QuxBzouxzmRu\r
++MmnUhsOzZaHT3GmLSVJlwie8KqSfKVGwyBmCyHbUQkMrSEV6QDESN6KyWt85gokB\r
++56Bc/wVq073xS1nFbfF1M3Z5q5BlLZK4IOerKTQx/oSfR4EX6B7rW2pttWsUCyEj\r
++LljaA8ehxR9B29m08IGGl43pHEpC1WnOHvsEGs99mPpjWbUgVv5KY7OuS/8iVw6v\r
++/Yy5Z+JBwlMzTBaUXXl3\r
++-----END CERTIFICATE-----\r
+diff --git a/test/test-lib.el b/test/test-lib.el\r
+index 04c8d63..596a705 100644\r
+--- a/test/test-lib.el\r
++++ b/test/test-lib.el\r
+@@ -188,3 +188,13 @@ nothing."\r
+ ;; environments\r
+ \r
+ (setq mm-text-html-renderer 'html2text)\r
++\r
++;; Set some variables for S/MIME tests.\r
++\r
++(setq smime-keys '(("" "test_suite.pem" nil)))\r
++\r
++(setq mml-smime-use 'openssl)\r
++\r
++;; all test keys are without passphrase\r
++(eval-after-load 'smime\r
++ '(defun smime-ask-passphrase (cache) nil))\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 126911f..2e9a499 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -1325,4 +1325,5 @@ test_declare_external_prereq emacs\r
+ test_declare_external_prereq ${TEST_EMACSCLIENT}\r
+ test_declare_external_prereq gdb\r
+ test_declare_external_prereq gpg\r
++test_declare_external_prereq openssl\r
+ test_declare_external_prereq ${NOTMUCH_PYTHON}\r
+-- \r
+2.6.2\r
+\r