public void OnAttachPublicKeyButton(Office.IRibbonControl control)
        {
            Outlook.MailItem mailItem = ((Outlook.Inspector)control.Context).CurrentItem as Outlook.MailItem;
            if (mailItem == null)
            {
                // TODO - Generate a log message
                MessageBox.Show("Error, mailItem was null.");
                return;
            }

            var smtp = Globals.OutlookPrivacyPlugin.GetSMTPAddress(mailItem);

            var crypto = new Deja.Crypto.BcPgp.PgpCrypto(new Deja.Crypto.BcPgp.CryptoContext());

            var headers = new Dictionary <string, string>();

            headers["Version"] = "Outlook Privacy Plugin";

            var publicKey = crypto.PublicKey(smtp, headers);

            if (publicKey == null)
            {
                // TODO - Generate log message
                MessageBox.Show("Error, unable to find public key to attach.");
                return;
            }

            var tempFile = Path.Combine(Path.GetTempPath(), "public_key.asc");

            File.WriteAllText(tempFile, publicKey);

            try
            {
                mailItem.Attachments.Add(
                    tempFile,
                    Outlook.OlAttachmentType.olByValue,
                    1,
                    "public_key.asc");

                mailItem.Save();
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
Example #2
0
		public void ExportPublicKey()
		{
			var expectedOutput = @"-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBFY1R3kBCADPO0yyqcHmBt7tXs28sjiXW+xnSoqgD7x63f5ePUsJ2emDff/Z
FwvmW+EAlgQ17AYBetz8uuFHgo41uNfOEVDphzBVOuZ9r/wtNOzhaT2fXyo4HTA0
6K5/c5/WcyXg/AnvM2SHQ1WfqV4MZ3l/umrKawFLZVuRKmQQmcuMvPJTq5lI6nDz
L98b62DUXb/3pZCVFuJNjdoxAy2KsTKl5g0rxDM/I6V7t4t4udWZ08Gk0iuOSRON
aG91C/H63KIOEwHtxpjQmS7QCb6H9BUKsO0JwvQYvfUYFQxPjL1GU7Wpg9xY6mT3
qJJLQ4XTlwcUENbeOzgnyqUnlGNibxmB1JFrABEBAAG0F1JzYSBKaWxsIDxyc2FA
amlsbC5jb20+iQE4BBMBAgAiBQJWNUd5AhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIe
AQIX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jmp9VHU/FdQtfVd9+3TprboR9JVl
qVpBT5OoBs9xe9FVirifzbAZ4JCrWcAJ1eKwAgAD
=uWzT
-----END PGP PUBLIC KEY BLOCK-----
";

			var context = new CryptoContext(
				GetPasswordCallback,
				@"C:\projects\OutlookPrivacyPlugin\Deja.Crypto.Test\pubring.gpg",
				@"C:\projects\OutlookPrivacyPlugin\Deja.Crypto.Test\secring.gpg",
				"rsa", "sha-1");
			var crypto = new PgpCrypto(context);

			var key = crypto.PublicKey("*****@*****.**", new Dictionary<string,string>());

			Assert.AreEqual(expectedOutput, key);
		}
Example #3
0
        public void OnAttachPublicKeyButton(Office.IRibbonControl control)
        {
            Outlook.MailItem mailItem = ((Outlook.Inspector)control.Context).CurrentItem as Outlook.MailItem;
            if (mailItem == null)
            {
                // TODO - Generate a log message
                MessageBox.Show("Error, mailItem was null.");
                return;
            }

            var smtp = Globals.OutlookPrivacyPlugin.GetSMTPAddress(mailItem);

            var crypto = new Deja.Crypto.BcPgp.PgpCrypto(new Deja.Crypto.BcPgp.CryptoContext());
            var publicKey = crypto.PublicKey(smtp, new Dictionary<string, string>());

            if(publicKey == null)
            {
                // TODO - Generate log message
                MessageBox.Show("Error, unable to find public key to attach.");
                return;
            }

            var tempFile = Path.Combine(Path.GetTempPath(), "public_key.gpg");
            File.WriteAllText(tempFile, publicKey);

            try
            {
                mailItem.Attachments.Add(
                    tempFile,
                    Outlook.OlAttachmentType.olByValue,
                    1,
                    "public_key.gpg");

                mailItem.Save();
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
Example #4
0
		public void OnAttachPublicKeyButton(Office.IRibbonControl control)
		{
			var mailItem = ((Outlook.Inspector)control.Context).CurrentItem as Outlook.MailItem;
			if (mailItem == null)
			{
				// TODO - Generate a log message
				MessageBox.Show("Error, mailItem was null.");
				return;
			}
			
			var smtp = Globals.OutlookPrivacyPlugin.GetSMTPAddress(mailItem);
			
			var crypto = new PgpCrypto(new CryptoContext());
			
			var headers = new Dictionary<string, string>();
			headers["Version"] = "Outlook Privacy Plugin";

			var publicKey = crypto.PublicKey(smtp, headers);

			if(publicKey == null)
			{
				// TODO - Generate log message
				MessageBox.Show("Error, unable to find public KeyItem to attach.");
				return;
			}

			var attachName = smtp.Replace("@", "_at_") + ".asc";
			attachName = Regex.Replace(attachName, @"[:\\/=+!@#$%^&*(){}[\]|<>,'"";~`]", "_");

			var tempFile = Path.Combine(Path.GetTempPath(), attachName);
			File.WriteAllText(tempFile, publicKey);

			try
			{
				mailItem.Attachments.Add(
					tempFile, 
					Outlook.OlAttachmentType.olByValue, 
					1,
					attachName);
				
				mailItem.Save();
			}
			finally
			{
				File.Delete(tempFile);
			}
		}