示例#1
0
        public void TestSecureMimeImportExport()
        {
            var self      = new MailboxAddress("MimeKit UnitTests", "*****@*****.**");
            var mailboxes = new List <MailboxAddress> ();

            // we're going to export our public certificate so that we can email it to someone
            // so that they can then encrypt their emails to us.
            mailboxes.Add(self);

            using (var ctx = CreateContext()) {
                var certsonly = ctx.Export(mailboxes);

                Assert.IsInstanceOfType(typeof(ApplicationPkcs7Mime), certsonly, "The exported mime part is not of the expected type.");

                var pkcs7mime = (ApplicationPkcs7Mime)certsonly;

                Assert.AreEqual(SecureMimeType.CertsOnly, pkcs7mime.SecureMimeType, "S/MIME type did not match.");

                using (var imported = new DummySecureMimeContext()) {
                    pkcs7mime.Import(imported);

                    Assert.AreEqual(1, imported.certificates.Count, "Unexpected number of imported certificates.");
                    Assert.IsFalse(imported.keys.Count > 0, "One or more of the certificates included the private key.");
                }
            }
        }
示例#2
0
        static SecureMimeContext CreateContext()
        {
            var    dataDir = Path.Combine("..", "..", "TestData", "smime");
            var    parser  = new X509CertificateParser();
            var    ctx     = new DummySecureMimeContext();
            string path;

            foreach (var filename in CertificateAuthorities)
            {
                path = Path.Combine(dataDir, filename);
                var certificate = parser.ReadCertificate(File.ReadAllBytes(path));
                ctx.certificates.Add(certificate);
            }

            path = Path.Combine(dataDir, "smime.p12");

            using (var file = File.OpenRead(path)) {
                ctx.ImportPkcs12(file, "no.secret");
            }

            return(ctx);
        }
示例#3
0
		public void TestSecureMimeImportExport ()
		{
			var self = new MailboxAddress ("MimeKit UnitTests", "*****@*****.**");
			var mailboxes = new List<MailboxAddress> ();

			// we're going to export our public certificate so that we can email it to someone
			// so that they can then encrypt their emails to us.
			mailboxes.Add (self);

			using (var ctx = CreateContext ()) {
				var certsonly = ctx.Export (mailboxes);

				Assert.IsInstanceOfType (typeof (ApplicationPkcs7Mime), certsonly, "The exported mime part is not of the expected type.");

				var pkcs7mime = (ApplicationPkcs7Mime) certsonly;

				Assert.AreEqual (SecureMimeType.CertsOnly, pkcs7mime.SecureMimeType, "S/MIME type did not match.");

				using (var imported = new DummySecureMimeContext ()) {
					pkcs7mime.Import (imported);

					Assert.AreEqual (1, imported.certificates.Count, "Unexpected number of imported certificates.");
					Assert.IsFalse (imported.keys.Count > 0, "One or more of the certificates included the private key.");
				}
			}
		}
示例#4
0
        static SecureMimeContext CreateContext()
        {
            var dataDir = Path.Combine ("..", "..", "TestData", "smime");
            var parser = new X509CertificateParser ();
            var ctx = new DummySecureMimeContext ();
            string path;

            foreach (var filename in CertificateAuthorities) {
                path = Path.Combine (dataDir, filename);
                var certificate = parser.ReadCertificate (File.ReadAllBytes (path));
                ctx.certificates.Add (certificate);
            }

            path = Path.Combine (dataDir, "smime.p12");

            using (var file = File.OpenRead (path)) {
                ctx.Import (file, "no.secret");
            }

            return ctx;
        }