OUT-496: Reset trust on restart of sync process Release 1.0.200
authorThomas
Fri, 24 Aug 2018 14:36:05 +0200
changeset 234690a05e423fd3
parent 2345 af06a0b2b9da
child 2347 2842144ab3ac
child 2388 7689917159b4
OUT-496: Reset trust on restart of sync process
MsgProcessor.cs
ThisAddIn.cs
UI/KeySyncWizard.xaml.cs
     1.1 --- a/MsgProcessor.cs	Thu Aug 23 12:03:09 2018 +0200
     1.2 +++ b/MsgProcessor.cs	Fri Aug 24 14:36:05 2018 +0200
     1.3 @@ -49,11 +49,10 @@
     1.4                          (message.To[0].EqualsByAddress(message.From)) &&
     1.5                          (PEPIdentity.GetIsOwnIdentity(message.From.Address)))
     1.6                      {
     1.7 -                        Log.Verbose("CheckForSyncMessage: Sync message found.");
     1.8 +                        Log.Verbose("CheckForSyncMessage: Potential sync message found.");
     1.9  
    1.10                          if ((KeySyncWizard.Wizard?.Type != KeySyncWizard.WizardType.PGP) &&
    1.11 -                            (KeySyncWizard.Wizard?.IsVisible == false) &&
    1.12 -                            (message.Rating < pEpRating.pEpRatingTrusted))
    1.13 +                            (KeySyncWizard.Wizard?.IsVisible == false))
    1.14                          {
    1.15                              Log.Verbose("CheckForSyncMessage: Wizard not open yet.");
    1.16  
     2.1 --- a/ThisAddIn.cs	Thu Aug 23 12:03:09 2018 +0200
     2.2 +++ b/ThisAddIn.cs	Fri Aug 24 14:36:05 2018 +0200
     2.3 @@ -2717,8 +2717,9 @@
     2.4          /// Enables or disables the automatic deletion of old autoconsume messages.
     2.5          /// This gets automatically disabled again if no autoconsume messages are found in the inbox.
     2.6          /// <param name="enable">Whether to enable or disable the automatic cleaning.</param>
     2.7 +        /// <param name="runOnEnable">Whether to run the inbox cleaning once right away when it gets enabled.</param>
     2.8          /// </summary>
     2.9 -        internal void ToggleInboxCleaning(bool enable)
    2.10 +        internal void ToggleInboxCleaning(bool enable, bool runOnEnable = true)
    2.11          {
    2.12              this._Settings.IsInboxCleaningEnabled = enable;
    2.13  
    2.14 @@ -2733,8 +2734,10 @@
    2.15                  Log.Verbose("ToggleInboxCleaning: Automatic inbox cleaning enabled");
    2.16  
    2.17                  // Run it once right away
    2.18 -                this.InboxCleaner_Tick(null, null);
    2.19 -
    2.20 +                if (runOnEnable)
    2.21 +                {
    2.22 +                    this.InboxCleaner_Tick(null, null);
    2.23 +                }
    2.24              }
    2.25              else if ((enable == false) &&
    2.26                       (inboxCleaner != null))
     3.1 --- a/UI/KeySyncWizard.xaml.cs	Thu Aug 23 12:03:09 2018 +0200
     3.2 +++ b/UI/KeySyncWizard.xaml.cs	Fri Aug 24 14:36:05 2018 +0200
     3.3 @@ -67,6 +67,7 @@
     3.4          private ObservableCollection<HandshakeItem>     _Items;
     3.5          private PEPIdentity                             _Myself;
     3.6          private PEPIdentity                             _Partner;
     3.7 +        private bool                                    _PartnerIdentityReset;
     3.8          private Steps                                   _Step;
     3.9          private bool                                    _SetImportedKeyAsDefault;
    3.10          private WizardType                              _Type;
    3.11 @@ -132,12 +133,12 @@
    3.12              {
    3.13                  this.SendSyncMessage(MessageTypes.InitialMessage);
    3.14              }
    3.15 -
    3.16 +            
    3.17              // Enable fast polling and inbox cleaning in pEp mode
    3.18              if (this.Type == WizardType.pEp)
    3.19              {
    3.20                  this.ToggleFastPolling(true);
    3.21 -                Globals.ThisAddIn.ToggleInboxCleaning(true);
    3.22 +                Globals.ThisAddIn.ToggleInboxCleaning(true, false);
    3.23              }
    3.24          }
    3.25  
    3.26 @@ -215,6 +216,20 @@
    3.27          }
    3.28  
    3.29          /// <summary>
    3.30 +        /// Gets or sets whether this wizard is the one that
    3.31 +        /// initiated the Key Import process.
    3.32 +        /// </summary>
    3.33 +        public bool PartnerIdentityReset
    3.34 +        {
    3.35 +            get { return this._PartnerIdentityReset; }
    3.36 +            set
    3.37 +            {
    3.38 +                this._PartnerIdentityReset = value;
    3.39 +                this.RaisePropertyChangedEvent(nameof(this.PartnerIdentityReset));
    3.40 +            }
    3.41 +        }
    3.42 +
    3.43 +        /// <summary>
    3.44          /// Gets or sets the current wizard step.
    3.45          /// </summary>
    3.46          public Steps Step
    3.47 @@ -332,7 +347,8 @@
    3.48                          string partnerFpr = null;
    3.49  
    3.50                          // Make sure the channel is not already trusted (either attack or re-processing)
    3.51 -                        if (e.Message?.Rating >= pEpRating.pEpRatingTrusted)
    3.52 +                        if ((e.Message?.Rating >= pEpRating.pEpRatingTrusted) &&
    3.53 +                            (this.PartnerIdentityReset))
    3.54                          {
    3.55                              Log.Warning("KeySyncWizard_SyncMessageReceived: Sync message for already trusted channel received.");
    3.56                              return;
    3.57 @@ -378,6 +394,18 @@
    3.58                              // Set the partner's fingerprint
    3.59                              this.Partner.Fingerprint = partnerFpr;
    3.60  
    3.61 +                            // Reset the partner identity
    3.62 +                            try
    3.63 +                            {
    3.64 +                                pEpIdentity partner = this.Partner.ToCOMType();
    3.65 +                                ThisAddIn.PEPEngine.KeyResetTrust(partner);
    3.66 +                                this._PartnerIdentityReset = true;
    3.67 +                            }
    3.68 +                            catch (Exception ex)
    3.69 +                            {
    3.70 +                                Log.Error("InitializeWizard: Error resetting partner trust. " + ex.ToString());
    3.71 +                            }
    3.72 +
    3.73                              // Marshall to main thread
    3.74                              this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
    3.75                              {
    3.76 @@ -495,6 +523,18 @@
    3.77                      this.Myself = new PEPIdentity(ThisAddIn.PEPEngine.Myself(this.Myself.ToCOMType()));
    3.78                  }
    3.79  
    3.80 +                // Reset partner identity
    3.81 +                try
    3.82 +                {
    3.83 +                    pEpIdentity partner = this.Partner.ToCOMType();
    3.84 +                    ThisAddIn.PEPEngine.KeyResetTrust(partner);
    3.85 +                    this.PartnerIdentityReset = true;
    3.86 +                }
    3.87 +                catch (Exception ex)
    3.88 +                {
    3.89 +                    Log.Error("InitializeWizard: Error resetting partner trust. " + ex.ToString());
    3.90 +                }
    3.91 +
    3.92                  // Create handshake item
    3.93                  if (this.CreateHandshakeItem())
    3.94                  {
    3.95 @@ -1272,7 +1312,7 @@
    3.96          /// </summary>
    3.97          /// <param name="success">Whether or not the wizard has been completed successfully.</param>
    3.98          private void GoToLastStep(bool success)
    3.99 -        {
   3.100 +        {           
   3.101              // Go to last step
   3.102              this.Step = success ? Steps.Success : Steps.Error;
   3.103  
   3.104 @@ -1452,7 +1492,7 @@
   3.105                  Log.Verbose("InitializeWizard: Fingerprint for myself retrieved.");
   3.106              }
   3.107  
   3.108 -            // If we have a partner fpr, set identity and create handshake item
   3.109 +            // If we have a partner fpr, set and reset identity
   3.110              if ((this.Myself != null) &&
   3.111                  (partnerFpr != null))
   3.112              {
   3.113 @@ -1736,6 +1776,7 @@
   3.114              this._Items = new ObservableCollection<HandshakeItem>();
   3.115              this._Myself = null;
   3.116              this._Partner = null;
   3.117 +            this._PartnerIdentityReset = false;
   3.118              this._Step = Steps.Undefined;
   3.119              this._SetImportedKeyAsDefault = true;
   3.120              this._Type = WizardType.Undefined;