Add key-import header OUT-428
authorThomas
Wed, 11 Apr 2018 15:10:34 +0200
branchOUT-428
changeset 21067ee0a280030d
parent 2105 ecd44ebb48e0
child 2107 a5d7688eb17c
Add key-import header
Extensions/MailItemExtensions.cs
PEPMessage.cs
     1.1 --- a/Extensions/MailItemExtensions.cs	Tue Apr 10 11:47:55 2018 +0200
     1.2 +++ b/Extensions/MailItemExtensions.cs	Wed Apr 11 15:10:34 2018 +0200
     1.3 @@ -34,7 +34,8 @@
     1.4              PEPProtocolVersion,
     1.5              Rating,
     1.6              EnableProtection,
     1.7 -            ForceProtection
     1.8 +            ForceProtection,
     1.9 +            KeyImport
    1.10          }
    1.11  
    1.12          /**************************************************************
    1.13 @@ -2402,6 +2403,44 @@
    1.14                                  success = true;
    1.15                                  break;
    1.16                              }
    1.17 +                        // Key import fpr MAPI property
    1.18 +                        case PEPProperty.KeyImport:
    1.19 +                            {
    1.20 +                                /* Note that KeyImport is defined as:
    1.21 +                                 *   ON : KeyImport property exists with a value of a key fingerprint
    1.22 +                                 *  OFF : KeyImport property does not exist or has a value of null
    1.23 +                                 */
    1.24 +                                outValue = MailItemExtensions.GetPEPPropertyDefault(property);
    1.25 +                                propertyValue = MapiHelper.GetProperty(omi, PEPMessage.PidNamePEPKeyImport, null);
    1.26 +
    1.27 +                                if (propertyValue != null)
    1.28 +                                {
    1.29 +                                    outValue = propertyValue as string;
    1.30 +                                }
    1.31 +                                else
    1.32 +                                {
    1.33 +                                    // As a backup search the original internet message headers
    1.34 +                                    if (messageHeaders == null)
    1.35 +                                    {
    1.36 +                                        messageHeaders = omi.GetParsedTransportMessageHeaders();
    1.37 +                                    }
    1.38 +                                    if (messageHeaders != null)
    1.39 +                                    {
    1.40 +                                        foreach (Header header in messageHeaders)
    1.41 +                                        {
    1.42 +                                            if ((header.Field != null) &&
    1.43 +                                                (header.Value != null) &&
    1.44 +                                                (string.Equals(header.Field.Trim(), PEPMessage.PR_PEP_KEY_IMPORT_NAME, StringComparison.OrdinalIgnoreCase)))
    1.45 +                                            {
    1.46 +                                                outValue = header.Value.ToString();
    1.47 +                                            }
    1.48 +                                        }
    1.49 +                                    }
    1.50 +                                }
    1.51 +
    1.52 +                                success = true;
    1.53 +                                break;
    1.54 +                            }
    1.55                          // Key list MAPI property
    1.56                          case PEPProperty.KeyList:
    1.57                              {
    1.58 @@ -2625,6 +2664,22 @@
    1.59  
    1.60                                  break;
    1.61                              }
    1.62 +                        // Key import fpr MAPI property
    1.63 +                        case PEPProperty.KeyImport:
    1.64 +                            {
    1.65 +                                // Note: cannot set the property value to null in PropertyAccessor.SetProperty()
    1.66 +                                if (value != null)
    1.67 +                                {
    1.68 +                                    MapiHelper.SetProperty(omi, PEPMessage.PidNamePEPKeyImport, value.ToString());
    1.69 +                                }
    1.70 +                                else
    1.71 +                                {
    1.72 +                                    MapiHelper.DeleteProperty(omi, PEPMessage.PidNamePEPKeyImport);
    1.73 +                                }
    1.74 +
    1.75 +                                success = true;
    1.76 +                                break;
    1.77 +                            }
    1.78                          // Key list MAPI property
    1.79                          case PEPProperty.KeyList:
    1.80                              {
     2.1 --- a/PEPMessage.cs	Tue Apr 10 11:47:55 2018 +0200
     2.2 +++ b/PEPMessage.cs	Wed Apr 11 15:10:34 2018 +0200
     2.3 @@ -24,21 +24,23 @@
     2.4          public event PropertyChangedEventHandler PropertyChanged;
     2.5  
     2.6          // pEp named MAPI properties
     2.7 -        public const string PR_ENC_STATUS_NAME           = "X-EncStatus";
     2.8 -        public const string PR_KEY_LIST_NAME             = "X-KeyList";
     2.9 -        public const string PR_PEP_AUTO_CONSUME_NAME     = "pEp-auto-consume";
    2.10 -        public const string PR_PEP_FORCE_PROTECTION_NAME = "X-pEp-force-protection";
    2.11 -        public const string PR_PEP_NEVER_UNSECURE_NAME   = "X-pEp-Never-Unsecure";
    2.12 -        public const string PR_PEP_PROTOCOL_VERSION_NAME = "X-pEp-Version";
    2.13 -
    2.14 -        public const string PR_PEP_NEVER_UNSECURE_VALUE  = "yes";
    2.15 -
    2.16 -        public static readonly MapiProperty.MapiProp PidNameEncStatus          = new MapiProperty.MapiProp(PR_ENC_STATUS_NAME,           MapiProperty.PS_INTERNET_HEADERS);
    2.17 -        public static readonly MapiProperty.MapiProp PidNameKeyList            = new MapiProperty.MapiProp(PR_KEY_LIST_NAME,             MapiProperty.PS_INTERNET_HEADERS);
    2.18 -        public static readonly MapiProperty.MapiProp PidNamePEPAutoConsume     = new MapiProperty.MapiProp(PR_PEP_AUTO_CONSUME_NAME,     MapiProperty.PS_INTERNET_HEADERS);
    2.19 -        public static readonly MapiProperty.MapiProp PidNamePEPForceProtection = new MapiProperty.MapiProp(PR_PEP_FORCE_PROTECTION_NAME, MapiProperty.PS_INTERNET_HEADERS);
    2.20 -        public static readonly MapiProperty.MapiProp PidNamePEPNeverUnsecure   = new MapiProperty.MapiProp(PR_PEP_NEVER_UNSECURE_NAME,   MapiProperty.PS_INTERNET_HEADERS);
    2.21 -        public static readonly MapiProperty.MapiProp PidNamePEPProtocolVersion = new MapiProperty.MapiProp(PR_PEP_PROTOCOL_VERSION_NAME, MapiProperty.PS_INTERNET_HEADERS);
    2.22 +        public const string PR_ENC_STATUS_NAME              = "X-EncStatus";
    2.23 +        public const string PR_KEY_LIST_NAME                = "X-KeyList";
    2.24 +        public const string PR_PEP_AUTO_CONSUME_NAME        = "pEp-auto-consume";
    2.25 +        public const string PR_PEP_KEY_IMPORT_NAME          = "pEp-key-import";
    2.26 +        public const string PR_PEP_FORCE_PROTECTION_NAME    = "X-pEp-force-protection";
    2.27 +        public const string PR_PEP_NEVER_UNSECURE_NAME      = "X-pEp-Never-Unsecure";
    2.28 +        public const string PR_PEP_PROTOCOL_VERSION_NAME    = "X-pEp-Version";
    2.29 +
    2.30 +        public const string PR_PEP_NEVER_UNSECURE_VALUE     = "yes";
    2.31 +
    2.32 +        public static readonly MapiProperty.MapiProp PidNameEncStatus          = new MapiProperty.MapiProp(PR_ENC_STATUS_NAME,              MapiProperty.PS_INTERNET_HEADERS);
    2.33 +        public static readonly MapiProperty.MapiProp PidNameKeyList            = new MapiProperty.MapiProp(PR_KEY_LIST_NAME,                MapiProperty.PS_INTERNET_HEADERS);
    2.34 +        public static readonly MapiProperty.MapiProp PidNamePEPAutoConsume     = new MapiProperty.MapiProp(PR_PEP_AUTO_CONSUME_NAME,        MapiProperty.PS_INTERNET_HEADERS);
    2.35 +        public static readonly MapiProperty.MapiProp PidNamePEPForceProtection = new MapiProperty.MapiProp(PR_PEP_FORCE_PROTECTION_NAME,    MapiProperty.PS_INTERNET_HEADERS);
    2.36 +        public static readonly MapiProperty.MapiProp PidNamePEPNeverUnsecure   = new MapiProperty.MapiProp(PR_PEP_NEVER_UNSECURE_NAME,      MapiProperty.PS_INTERNET_HEADERS);
    2.37 +        public static readonly MapiProperty.MapiProp PidNamePEPProtocolVersion = new MapiProperty.MapiProp(PR_PEP_PROTOCOL_VERSION_NAME,    MapiProperty.PS_INTERNET_HEADERS);
    2.38 +        public static readonly MapiProperty.MapiProp PidNamePEPKeyImport       = new MapiProperty.MapiProp(PR_PEP_KEY_IMPORT_NAME,          MapiProperty.PS_INTERNET_HEADERS);
    2.39  
    2.40          private static object                     mutexMirror           = new object();
    2.41          private static Dictionary<string, string> mirrorCache           = new Dictionary<string, string>();
    2.42 @@ -56,6 +58,7 @@
    2.43          private bool                _ForceUnencrypted;
    2.44          private PEPIdentity         _From;
    2.45          private string              _Id;
    2.46 +        private string              _KeyImport;
    2.47          private string              _KeyList;
    2.48          private List<string>        _Keywords;
    2.49          private string              _LongMsg;
    2.50 @@ -329,6 +332,19 @@
    2.51          }
    2.52  
    2.53          /// <summary>
    2.54 +        /// Gets or sets the partner fingerprint of a key import message.
    2.55 +        /// </summary>
    2.56 +        public string KeyImport
    2.57 +        {
    2.58 +            get { return (this._KeyImport); }
    2.59 +            set
    2.60 +            {
    2.61 +                this._KeyImport = value;
    2.62 +                this.RaisePropertyChangedEvent(nameof(this.KeyImport));
    2.63 +            }
    2.64 +        }
    2.65 +
    2.66 +        /// <summary>
    2.67          /// Gets or sets the list of keys associated with this message.
    2.68          /// Commonly this contains the list of decryption keys.
    2.69          /// Warning: Since this is stored as a header field, care must be taken not to apply this to a MailItem on an 
    2.70 @@ -694,6 +710,15 @@
    2.71              }
    2.72  
    2.73              if ((alwaysAddOptFields) ||
    2.74 +                (string.IsNullOrEmpty(this._KeyImport) == false))
    2.75 +            {
    2.76 +                field = new StringPair();
    2.77 +                field.Name = PEPMessage.PR_PEP_KEY_IMPORT_NAME;
    2.78 +                field.Value = this._KeyImport;
    2.79 +                optionalFields.Add(field);
    2.80 +            }
    2.81 +
    2.82 +            if ((alwaysAddOptFields) ||
    2.83                  (string.IsNullOrEmpty(this._KeyList) == false))
    2.84              {
    2.85                  field = new StringPair();
    2.86 @@ -777,6 +802,7 @@
    2.87               *   • Rating
    2.88               *   • ForceProtection
    2.89               *   • NeverUnsecure
    2.90 +             *   • KeyImportFpr
    2.91               *   • KeyList
    2.92               *   • PEPProtocolVersion
    2.93               * 
    2.94 @@ -957,6 +983,20 @@
    2.95                  }
    2.96              }
    2.97  
    2.98 +            if (string.IsNullOrEmpty(pEpMessage.KeyImport) == false)
    2.99 +            {
   2.100 +                try
   2.101 +                {
   2.102 +                    Header header = new Header(Encoding.Unicode, PEPMessage.PR_PEP_KEY_IMPORT_NAME, pEpMessage.KeyImport);
   2.103 +                    message.Headers.Add(header);
   2.104 +                }
   2.105 +                catch (Exception ex)
   2.106 +                {
   2.107 +                    status = Globals.ReturnStatus.Failure;
   2.108 +                    Log.Error("ToMIMEMessage: Error adding KeyImportFpr header. " + ex.ToString());
   2.109 +                }
   2.110 +            }
   2.111 +
   2.112              if (string.IsNullOrEmpty(pEpMessage.KeyList) == false)
   2.113              {
   2.114                  try
   2.115 @@ -1086,6 +1126,7 @@
   2.116                  Comparisons.Equals(this.ForceUnencrypted, obj.ForceUnencrypted) &&
   2.117                  Comparisons.Equals(this.From, obj.From) &&
   2.118                  Comparisons.Equals(this.Id, obj.Id) &&
   2.119 +                Comparisons.Equals(this.KeyImport, obj.KeyImport) &&
   2.120                  Comparisons.Equals(this.KeyList, obj.KeyList) &&
   2.121                  Comparisons.Equals(this.Keywords, obj.Keywords) &&
   2.122                  Comparisons.Equals(this.LongMsg, obj.LongMsg) &&
   2.123 @@ -1186,6 +1227,7 @@
   2.124              copy.ForceUnencrypted = this._ForceUnencrypted;
   2.125              copy.From = (this._From == null ? null : this._From.Copy());
   2.126              copy.Id = (this._Id == null ? null : string.Copy(this._Id));
   2.127 +            copy.KeyImport = (this._KeyImport == null ? null : string.Copy(this._KeyImport));
   2.128              copy.KeyList = (this._KeyList == null ? null : string.Copy(this._KeyList));
   2.129  
   2.130              // Keywords
   2.131 @@ -1263,6 +1305,7 @@
   2.132              this._ForceUnencrypted = false;
   2.133              this._From = null;
   2.134              this._Id = null;
   2.135 +            this._KeyImport = null;
   2.136              this._KeyList = null;
   2.137              this._Keywords = new List<string>();
   2.138              this._LongMsg = null;
   2.139 @@ -1289,6 +1332,7 @@
   2.140              this.RaisePropertyChangedEvent(nameof(this.ForceUnencrypted));
   2.141              this.RaisePropertyChangedEvent(nameof(this.From));
   2.142              this.RaisePropertyChangedEvent(nameof(this.Id));
   2.143 +            this.RaisePropertyChangedEvent(nameof(this.KeyImport));
   2.144              this.RaisePropertyChangedEvent(nameof(this.KeyList));
   2.145              this.RaisePropertyChangedEvent(nameof(this.Keywords));
   2.146              this.RaisePropertyChangedEvent(nameof(this.LongMsg));
   2.147 @@ -1301,8 +1345,6 @@
   2.148              this.RaisePropertyChangedEvent(nameof(this.SentOn));
   2.149              this.RaisePropertyChangedEvent(nameof(this.ShortMsg));
   2.150              this.RaisePropertyChangedEvent(nameof(this.To));
   2.151 -
   2.152 -            return;
   2.153          }
   2.154  
   2.155          /// <summary>
   2.156 @@ -1383,6 +1425,10 @@
   2.157              omi.GetPEPProperty(MailItemExtensions.PEPProperty.Rating, out propValue);
   2.158              this.Rating = (pEpRating)propValue;
   2.159  
   2.160 +            // KeyImportFpr
   2.161 +            omi.GetPEPProperty(MailItemExtensions.PEPProperty.KeyImport, out propValue);
   2.162 +            this.KeyImport = propValue as string;
   2.163 +
   2.164              // KeyList
   2.165              omi.GetPEPProperty(MailItemExtensions.PEPProperty.KeyList, out propValue);
   2.166              this.KeyList = propValue as string;
   2.167 @@ -1927,6 +1973,7 @@
   2.168                  }
   2.169  
   2.170                  // Note: ignore return status
   2.171 +                omi.SetPEPProperty(MailItemExtensions.PEPProperty.KeyImport, this._KeyImport);
   2.172                  omi.SetPEPProperty(MailItemExtensions.PEPProperty.AutoConsume, this._AutoConsume);
   2.173                  omi.SetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, this._ForceProtectionId);
   2.174                  omi.SetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, this._NeverUnsecure);
   2.175 @@ -2307,6 +2354,11 @@
   2.176                                          newMessage.ForceProtectionId = optField.Value;
   2.177                                          break;
   2.178                                      }
   2.179 +                                case PEPMessage.PR_PEP_KEY_IMPORT_NAME:
   2.180 +                                    {
   2.181 +                                        newMessage.KeyImport = optField.Value;
   2.182 +                                        break;
   2.183 +                                    }
   2.184                                  case PEPMessage.PR_KEY_LIST_NAME:
   2.185                                      {
   2.186                                          newMessage.KeyList = optField.Value;
   2.187 @@ -2841,6 +2893,10 @@
   2.188                              {
   2.189                                  pEpMessage.KeyList = header.Value;
   2.190                              }
   2.191 +                            else if (string.Equals(header.Field.Trim(), PEPMessage.PR_PEP_KEY_IMPORT_NAME, StringComparison.OrdinalIgnoreCase))
   2.192 +                            {
   2.193 +                                pEpMessage.KeyImport = header.Value;
   2.194 +                            }
   2.195                              else if (string.Equals(header.Field.Trim(), PEPMessage.PR_PEP_AUTO_CONSUME_NAME, StringComparison.OrdinalIgnoreCase))
   2.196                              {
   2.197                                  pEpMessage.AutoConsume = header.Value;