Add sensitive data logging
authorThomas
Tue, 30 Jan 2018 09:59:14 +0100
changeset 1979cf610012e16d
parent 1978 83e729180a78
child 1980 c725c47cc8dc
Add sensitive data logging
AdapterCallbacks.cs
CryptableMailItem.cs
Log.cs
MsgProcessor.cs
PEPSettings.cs
UI/HandshakeDialog.xaml.cs
     1.1 --- a/AdapterCallbacks.cs	Tue Jan 30 08:53:32 2018 +0100
     1.2 +++ b/AdapterCallbacks.cs	Tue Jan 30 09:59:14 2018 +0100
     1.3 @@ -213,11 +213,10 @@
     1.4          {
     1.5              PEPMessage newMessage;
     1.6  
     1.7 -            //Log.Verbose("MessageToSend: Started");
     1.8 -#warning Remove subject logging for release versions
     1.9 +            Log.Verbose("MessageToSend: Started");
    1.10              try
    1.11              {
    1.12 -                Log.Verbose("MessageToSend: Started sending message with subject " + msg.ShortMsg);
    1.13 +                Log.SensitiveData("MessageToSend: Started sending message with subject " + msg.ShortMsg);
    1.14              }
    1.15              catch { }         
    1.16  
     2.1 --- a/CryptableMailItem.cs	Tue Jan 30 08:53:32 2018 +0100
     2.2 +++ b/CryptableMailItem.cs	Tue Jan 30 09:59:14 2018 +0100
     2.3 @@ -1463,10 +1463,9 @@
     2.4                          if (decryptionFlags.HasFlag(pEpDecryptFlags.pEpDecryptFlagConsume))
     2.5                          {
     2.6                              // Delete the mail item from Outlook
     2.7 -#warning Delete subject logging in release versions
     2.8                              try
     2.9                              {
    2.10 -                                Log.Verbose("ProcessAndGetRating: Processed msg with subject " + this.internalMailItem.Subject + " received on " + this.internalMailItem.ReceivedTime.ToString());
    2.11 +                                Log.SensitiveData("ProcessAndGetRating: Processed msg with subject " + this.internalMailItem.Subject + " received on " + this.internalMailItem.ReceivedTime.ToString());
    2.12                              }
    2.13                              catch { }
    2.14                              this.internalMailItem.PermanentlyDelete();
    2.15 @@ -1476,10 +1475,9 @@
    2.16                          }
    2.17                          else if (decryptionFlags.HasFlag(pEpDecryptFlags.pEpDecryptFlagIgnore))
    2.18                          {
    2.19 -#warning Delete subject logging in release versions
    2.20                              try
    2.21                              {
    2.22 -                                Log.Verbose("ProcessAndGetRating: Processed msg with subject " + this.internalMailItem.Subject + " received on " + this.internalMailItem.ReceivedTime.ToString());
    2.23 +                                Log.SensitiveData("ProcessAndGetRating: Processed msg with subject " + this.internalMailItem.Subject + " received on " + this.internalMailItem.ReceivedTime.ToString());
    2.24                              }
    2.25                              catch { }
    2.26                              Log.Verbose("ProcessAndGetRating: Processed message ignored.");
     3.1 --- a/Log.cs	Tue Jan 30 08:53:32 2018 +0100
     3.2 +++ b/Log.cs	Tue Jan 30 09:59:14 2018 +0100
     3.3 @@ -61,6 +61,22 @@
     3.4          }
     3.5  
     3.6          /// <summary>
     3.7 +        /// Adds the given sensitive text to the pEp for Outlook log only
     3.8 +        /// when sensitive data logging is enabled.
     3.9 +        /// </summary>
    3.10 +        /// <param name="text">The sensitive text to add to the log.</param>
    3.11 +        public static void SensitiveData(string text)
    3.12 +        {
    3.13 +            if ((text != null) &&
    3.14 +                (Globals.ThisAddIn != null) &&
    3.15 +                (Globals.ThisAddIn.Settings.IsSensitiveDataLoggingEnabled))
    3.16 +            {
    3.17 +                Log.Write(DateTime.Now.ToString("HH:mm:ss.fff") + " |S| " + text);
    3.18 +            }
    3.19 +            return;
    3.20 +        }
    3.21 +
    3.22 +        /// <summary>
    3.23          /// Adds the given warning text to the pEp for Outlook log.
    3.24          /// </summary>
    3.25          /// <param name="text">The warning text to add to the log.</param>
     4.1 --- a/MsgProcessor.cs	Tue Jan 30 08:53:32 2018 +0100
     4.2 +++ b/MsgProcessor.cs	Tue Jan 30 09:59:14 2018 +0100
     4.3 @@ -991,8 +991,8 @@
     4.4              Globals.ReturnStatus sts;
     4.5              flags = pEpDecryptFlags.pEpDecryptFlagsNone;
     4.6  
     4.7 -#warning Remove Id logging for release version
     4.8 -            Log.Verbose("Decrypt: Started. " + sourceMessage?.Id);
     4.9 +            Log.Verbose("Decrypt started.");
    4.10 +            Log.SensitiveData("Decrypt: Decrypting " + sourceMessage?.Id);
    4.11  
    4.12              if (sourceMessage != null)
    4.13              {
     5.1 --- a/PEPSettings.cs	Tue Jan 30 08:53:32 2018 +0100
     5.2 +++ b/PEPSettings.cs	Tue Jan 30 09:59:14 2018 +0100
     5.3 @@ -51,6 +51,7 @@
     5.4          public const string REG_NAME_IS_PEP_FOLDER_VISIBLE                      = "IsPEPFolderVisible";
     5.5          public const string REG_NAME_IS_READER_SPLASH_ENABLED                   = "IsReaderSplashEnabled";
     5.6          public const string REG_NAME_IS_SECURITY_LOSS_WARNING_ENABLED           = "IsSecurityLossWarningEnabled";
     5.7 +        public const string REG_NAME_IS_SENSITIVE_DATA_LOGGING_ENABLED          = "IsSensitiveDataLoggingEnabled";
     5.8          public const string REG_NAME_IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS           = "IsSyncEnabledForAllAccounts";
     5.9          public const string REG_NAME_IS_TNEF_DISABLED                           = "DisableTNEF"; // Name defined by Microsoft
    5.10          public const string REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED             = "IsUnencryptedSubjectEnabled";
    5.11 @@ -84,6 +85,7 @@
    5.12  #else
    5.13          public const bool                  IS_SECURITY_LOSS_WARNING_ENABLED_DEFAULT           = false;
    5.14  #endif
    5.15 +        public const bool                  IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT          = false;
    5.16          public const bool                  IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS_DEFAULT           = true;
    5.17          public const bool                  IS_TNEF_DISABLED_DEFAULT                           = false;
    5.18          public const bool                  IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT             = true;
    5.19 @@ -106,6 +108,7 @@
    5.20          private bool                                     _IsPEPFolderVisible;
    5.21          private bool                                     _IsReaderSplashEnabled;
    5.22          private bool                                     _IsSecurityLossWarningEnabled;
    5.23 +        private bool                                     _IsSensitiveDataLoggingEnabled;
    5.24          private bool                                     _IsSyncEnabledForAllAccounts;
    5.25          private bool                                     _IsTNEFDisabled;
    5.26          private bool                                     _IsUnencryptedSubjectEnabled;
    5.27 @@ -361,6 +364,22 @@
    5.28          }
    5.29  
    5.30          /// <summary>
    5.31 +        /// Gets or sets whether sensitive data logging is enabled.
    5.32 +        /// </summary>
    5.33 +        public bool IsSensitiveDataLoggingEnabled
    5.34 +        {
    5.35 +            get { return (this._IsSensitiveDataLoggingEnabled); }
    5.36 +            set
    5.37 +            {
    5.38 +                if (object.Equals(this._IsSensitiveDataLoggingEnabled, value) == false)
    5.39 +                {
    5.40 +                    this._IsSensitiveDataLoggingEnabled = value;
    5.41 +                    this.RaisePropertyChangedEvent(nameof(this.IsSensitiveDataLoggingEnabled));
    5.42 +                }
    5.43 +            }
    5.44 +        }
    5.45 +
    5.46 +        /// <summary>
    5.47          /// Gets or sets whether key sync is disabled for all accounts.
    5.48          /// </summary>
    5.49          public bool IsSyncEnabledForAllAccounts
    5.50 @@ -484,6 +503,7 @@
    5.51              this._IsPEPFolderVisible = PEPSettings.IS_PEP_FOLDER_VISIBLE_DEFAULT;
    5.52              this._IsReaderSplashEnabled = PEPSettings.IS_READER_SPLASH_ENABLED_DEFAULT;
    5.53              this._IsSecurityLossWarningEnabled = PEPSettings.IS_SECURITY_LOSS_WARNING_ENABLED_DEFAULT;
    5.54 +            this._IsSensitiveDataLoggingEnabled = PEPSettings.IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT;
    5.55              this._IsSyncEnabledForAllAccounts = PEPSettings.IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS_DEFAULT;
    5.56              this._IsTNEFDisabled = PEPSettings.IS_TNEF_DISABLED_DEFAULT;
    5.57              this._IsUnencryptedSubjectEnabled = PEPSettings.IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT;
    5.58 @@ -510,6 +530,7 @@
    5.59              this.RaisePropertyChangedEvent(nameof(this.IsPEPFolderVisible));
    5.60              this.RaisePropertyChangedEvent(nameof(this.IsReaderSplashEnabled));
    5.61              this.RaisePropertyChangedEvent(nameof(this.IsSecurityLossWarningEnabled));
    5.62 +            this.RaisePropertyChangedEvent(nameof(this.IsSensitiveDataLoggingEnabled));
    5.63              this.RaisePropertyChangedEvent(nameof(this.IsSyncEnabledForAllAccounts));
    5.64              this.RaisePropertyChangedEvent(nameof(this.IsTNEFDisabled));
    5.65              this.RaisePropertyChangedEvent(nameof(this.IsUnencryptedSubjectEnabled));
    5.66 @@ -624,6 +645,7 @@
    5.67                  Comparisons.Equals(this.IsPEPFolderVisible, obj.IsPEPFolderVisible) &&
    5.68                  Comparisons.Equals(this.IsReaderSplashEnabled, obj.IsReaderSplashEnabled) &&
    5.69                  Comparisons.Equals(this.IsSecurityLossWarningEnabled, obj.IsSecurityLossWarningEnabled) &&
    5.70 +                Comparisons.Equals(this.IsSensitiveDataLoggingEnabled, obj.IsSensitiveDataLoggingEnabled) &&
    5.71                  Comparisons.Equals(this.IsSyncEnabledForAllAccounts, obj.IsSyncEnabledForAllAccounts) &&
    5.72                  Comparisons.Equals(this.IsTNEFDisabled, obj.IsTNEFDisabled) &&
    5.73                  Comparisons.Equals(this.IsUnencryptedSubjectEnabled, obj.IsUnencryptedSubjectEnabled) &&
    5.74 @@ -665,6 +687,7 @@
    5.75               *   • ExtraKeys
    5.76               *   • IsCrashReportVisible
    5.77               *   • IsDeveloperModeEnabled
    5.78 +             *   • IsSensitiveDataLoggingEnabled
    5.79               *   • IsDisableProtectionForContactsEnabled
    5.80               *   • IsPassiveModeEnabled
    5.81               *   • IsTNEFDisabled
    5.82 @@ -1487,6 +1510,33 @@
    5.83                              this.RaisePropertyChangedEvent(nameof(this.IsSecurityLossWarningEnabled));
    5.84                          }
    5.85  
    5.86 +                        // Attempt to get IsSensitiveDataLoggingEnabled value
    5.87 +                        isPropertySet = false;
    5.88 +                        try
    5.89 +                        {
    5.90 +                            keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_SENSITIVE_DATA_LOGGING_ENABLED, PEPSettings.IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT).ToString();
    5.91 +                            isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
    5.92 +
    5.93 +                            if (isSuccessful)
    5.94 +                            {
    5.95 +                                this._IsSensitiveDataLoggingEnabled = parsedBoolValue;
    5.96 +                                isPropertySet = true;
    5.97 +                            }
    5.98 +                        }
    5.99 +                        catch
   5.100 +                        {
   5.101 +                            Log.Warning("LoadFromRegistry: Unable to read IsSensitiveDataLoggingEnabled");
   5.102 +                        }
   5.103 +                        finally
   5.104 +                        {
   5.105 +                            if (isPropertySet == false)
   5.106 +                            {
   5.107 +                                this._IsSensitiveDataLoggingEnabled = PEPSettings.IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT;
   5.108 +                            }
   5.109 +
   5.110 +                            this.RaisePropertyChangedEvent(nameof(this.IsSensitiveDataLoggingEnabled));
   5.111 +                        }
   5.112 +
   5.113                          // Attempt to get IsSyncEnabledForAllAccounts value
   5.114                          isPropertySet = false;
   5.115                          try
     6.1 --- a/UI/HandshakeDialog.xaml.cs	Tue Jan 30 08:53:32 2018 +0100
     6.2 +++ b/UI/HandshakeDialog.xaml.cs	Tue Jan 30 09:59:14 2018 +0100
     6.3 @@ -672,8 +672,7 @@
     6.4                              try
     6.5                              {
     6.6                                  identity.Rating = ThisAddIn.PEPEngine.IdentityRating(identity.ToCOMType());
     6.7 -#warning Remove mail address logging for release versions
     6.8 -                                Log.Verbose("BuildDialog: " + identity.Address + ". Rating: " + Enum.GetName(typeof(pEpRating), identity.Rating) + ". Communication type is " + Enum.GetName(typeof(pEpComType), identity.CommunicationType));
     6.9 +                                Log.SensitiveData("BuildDialog: " + identity.Address + ". Rating: " + Enum.GetName(typeof(pEpRating), identity.Rating) + ". Communication type is " + Enum.GetName(typeof(pEpComType), identity.CommunicationType));
    6.10                              }
    6.11                              catch (COMException ex)
    6.12                              {