Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes #4

  • Loading branch information...
commit afe921f1fe84461a9b352edc28d2fa565f35ef4d 1 parent 0807404
@twalrant authored
View
16 ChangeLog
@@ -1,3 +1,19 @@
+2009-11-19 <changelog.tgc@walrant.net>
+
+ * OutlookGnuPG/OutlookGnuPG.cs (EncryptEmail/SignAndEncryptEmail):
+ add support for untrusted key.
+
+ * References/OpenPGP/src/GnuPG.cs (UserCmdOptions): add new
+ property for user defined gpg command options (ie: --trust-model).
+
+2009-11-15 <changelog.tgc@walrant.net>
+
+ * References/OpenPGP/src/GnuPG.cs (class GnuPG): add (global)
+ default command line options.
+
+ * References/OpenPGP/src/GnuPGKeyCollection.cs (Fill): accept
+ empty sub-keys.
+
2009-11-14 <changelog.tgc@walrant.net>
* OutlookGnuPG/OutlookGnuPG.cs (OutlookGnuPG_CloseActiveExplorer):
View
112 OutlookGnuPG/OutlookGnuPG.cs
@@ -724,26 +724,46 @@ private string EncryptEmail(string mail, string passphrase, IList<string> recipi
{
using (StreamWriter writer = new StreamWriter(inputStream))
{
- writer.Write(mail);
- writer.Flush();
- inputStream.Position = 0;
- _gnuPg.Passphrase = passphrase;
- _gnuPg.Recipients = recipients;
- _gnuPg.OutputStatus = false;
-
- try
+ // Ready for two passes encryption.
+ foreach (string option in new string[] { "", "--trust-model always" })
{
- _gnuPg.Encrypt(inputStream, outputStream);
- }
- catch (Exception ex)
- {
- MessageBox.Show(
+ _gnuPg.UserCmdOptions = option;
+
+ writer.Write(mail);
+ writer.Flush();
+ inputStream.Position = 0;
+ _gnuPg.Passphrase = passphrase;
+ _gnuPg.Recipients = recipients;
+ _gnuPg.OutputStatus = false;
+
+ try
+ {
+ _gnuPg.Encrypt(inputStream, outputStream);
+ break; // Stop two passes here on success.
+ }
+ catch (Exception ex)
+ {
+ if (string.IsNullOrEmpty(option) && ex.Message.StartsWith("gpg: C4771111"))
+ {
+ DialogResult res = MessageBox.Show(
+ ex.Message + "\r\n\r\nEncrypt mail anyway?",
+ "GnuPG Warning",
+ MessageBoxButtons.OKCancel,
+ MessageBoxIcon.Exclamation);
+ if (res == DialogResult.Cancel)
+ return _gnuPgErrorString;
+ }
+ else
+ {
+ MessageBox.Show(
ex.Message,
- "GnuPG Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error);
+ "GnuPG Error",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
- return _gnuPgErrorString;
+ return _gnuPgErrorString;
+ }
+ }
}
}
@@ -764,27 +784,47 @@ private string SignAndEncryptEmail(string mail, string key, string passphrase, I
{
using (StreamWriter writer = new StreamWriter(inputStream))
{
- writer.Write(mail);
- writer.Flush();
- inputStream.Position = 0;
- _gnuPg.Passphrase = passphrase;
- _gnuPg.Recipients = recipients;
- _gnuPg.Sender = key;
- _gnuPg.OutputStatus = false;
-
- try
- {
- _gnuPg.SignAndEncrypt(inputStream, outputStream);
- }
- catch (Exception ex)
+ // Ready for two passes sign/encryption.
+ foreach (string option in new string[] { "", "--trust-model always" })
{
- MessageBox.Show(
- ex.Message,
- "GnuPG Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error);
+ _gnuPg.UserCmdOptions = option;
- return _gnuPgErrorString;
+ writer.Write(mail);
+ writer.Flush();
+ inputStream.Position = 0;
+ _gnuPg.Passphrase = passphrase;
+ _gnuPg.Recipients = recipients;
+ _gnuPg.Sender = key;
+ _gnuPg.OutputStatus = false;
+
+ try
+ {
+ _gnuPg.SignAndEncrypt(inputStream, outputStream);
+ break; // Stop two passes here on success.
+ }
+ catch (Exception ex)
+ {
+ if (string.IsNullOrEmpty(option) && ex.Message.StartsWith("gpg: C4771111"))
+ {
+ DialogResult res = MessageBox.Show(
+ ex.Message + "\r\n\r\nSign and Encrypt the mail anyway?",
+ "GnuPG Warning",
+ MessageBoxButtons.OKCancel,
+ MessageBoxIcon.Exclamation);
+ if (res == DialogResult.Cancel)
+ return _gnuPgErrorString;
+ }
+ else
+ {
+ MessageBox.Show(
+ ex.Message,
+ "GnuPG Error",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+
+ return _gnuPgErrorString;
+ }
+ }
}
}
View
13 References/OpenPGP/src/GnuPG.cs
@@ -127,6 +127,7 @@ public class GnuPG : IDisposable
private Process _proc;
private bool _outputStatus;
private bool _outputDataClosed;
+ private string _userCmdOptions = "";
private Stream _outputStream;
private Stream _errorStream;
@@ -209,6 +210,12 @@ public bool OutputStatus
set { _outputStatus = value; }
}
+ public string UserCmdOptions
+ {
+ get { return _userCmdOptions; }
+ set { _userCmdOptions = value; }
+ }
+
/// <summary>
/// Get or set the timeout value for the GnuPG operations in milliseconds.
/// </summary>
@@ -510,10 +517,16 @@ private string GetCmdLineSwitches(ActionTypes action)
// always use the trusted model so we don't get an interactive session with gpg.exe
//options.Append("--trust-model always ");
+ // Note: better be provided by the user in the UserCmdOptions property.
+
+ // Apply user defined command options.
+ if (string.IsNullOrEmpty(_userCmdOptions) != true)
+ options.Append(_userCmdOptions + " ");
if (_outputStatus)
options.Append("--status-fd 1 ");
+
// handle the action
switch (action)
{
Please sign in to comment.
Something went wrong with that request. Please try again.