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."); } } }
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); }
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."); } } }
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; }