コード例 #1
0
        /// <summary>
        /// This constructor accepts Signed XrML Publish License as a parameter.
        /// It decrypts and parses parses the XrRML document and initializes class based on that.
        /// </summary>
        internal UnsignedPublishLicense(SafeRightsManagementHandle boundLicenseHandle, string publishLicenseTemplate)
            : this()
        {
            Invariant.Assert(!boundLicenseHandle.IsInvalid);
            Invariant.Assert(publishLicenseTemplate != null);

            using (IssuanceLicense issuanceLicense = new IssuanceLicense(
                       DateTime.MinValue,      // validFrom, - default
                       DateTime.MaxValue,      // validUntil, - default
                       null,                   // referralInfoName,
                       null,                   //  referralInfoUrl,
                       null,                   // owner,
                       publishLicenseTemplate,
                       boundLicenseHandle,     // boundLicenseHandle,
                       _contentId,             //  contentId,
                       null,                   //  grantCollection
                       null,                   //  Localized Name Description pairs collection
                       null,                   //  Application Specific Data Dictionary
                       0,                      // validity interval days
                       null))                  // revocation point info
            {
                // update our instance data based on the parsed information
                issuanceLicense.UpdateUnsignedPublishLicense(this);
            }
        }
コード例 #2
0
 public MessageItem ConvertRpmsgToMsg(MessageItem rightsProtectedMessage, SafeRightsManagementHandle decryptorHandle, string useLicense)
 {
     ExTraceGlobals.RightsManagementTracer.TraceDebug((long)this.GetHashCode(), "RpMsgToMsgConverter::ConvertRpmsgToMsg");
     if (string.IsNullOrEmpty(useLicense))
     {
         throw new ArgumentNullException("useLicense");
     }
     this.DecryptMsg(rightsProtectedMessage, useLicense, decryptorHandle);
     if (this.decryptedItem == null)
     {
         throw new RightsManagementPermanentException(RightsManagementFailureCode.UnknownFailure, ServerStrings.GenericFailureRMDecryption);
     }
     return(this.decryptedItem);
 }
コード例 #3
0
        public MessageItem ConvertRpmsgToMsg(MessageItem rightsProtectedMessage, string useLicense, SafeRightsManagementHandle enablingPrincipalRac)
        {
            ExTraceGlobals.RightsManagementTracer.TraceDebug((long)this.GetHashCode(), "RpMsgToMsgConverter::ConvertRpmsgToMsg");
            if (string.IsNullOrEmpty(useLicense))
            {
                throw new ArgumentNullException("useLicense");
            }
            if (enablingPrincipalRac == null)
            {
                throw new ArgumentNullException("enablingPrincipalRac");
            }
            if (enablingPrincipalRac.IsInvalid)
            {
                throw new ArgumentException("enablingPrincipalRac");
            }
            SafeRightsManagementHandle safeRightsManagementHandle = null;

            try
            {
                RmsClientManager.BindUseLicenseForDecryption(enablingPrincipalRac, useLicense, this.drmMsgContainer.PublishLicense, out safeRightsManagementHandle);
                this.DecryptMsg(rightsProtectedMessage, useLicense, safeRightsManagementHandle);
            }
            finally
            {
                if (safeRightsManagementHandle != null)
                {
                    safeRightsManagementHandle.Close();
                    safeRightsManagementHandle = null;
                }
            }
            if (this.decryptedItem == null)
            {
                throw new RightsManagementPermanentException(RightsManagementFailureCode.UnknownFailure, ServerStrings.GenericFailureRMDecryption);
            }
            return(this.decryptedItem);
        }
コード例 #4
0
 private void AcquireUseLicenseAndUsageRightsCallback(IAsyncResult asyncResult)
 {
     if (asyncResult == null)
     {
         throw new ArgumentNullException("asyncResult");
     }
     if (asyncResult.AsyncState == null)
     {
         IrmLicensingManager.Tracer.TraceError((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: asyncResult.AsyncState is null.");
         throw new InvalidOperationException("asyncResult.AsyncState must NOT be null.");
     }
     IrmLicensingManager.AsyncState asyncState = (IrmLicensingManager.AsyncState)asyncResult.AsyncState;
     try
     {
         IrmLicensingManager.Tracer.TraceDebug <OwaStoreObjectId>((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: calling EndAcquireUseLicenseAndUsageRights to get results for message {0}", asyncState.MessageId);
         UseLicenseAndUsageRights useLicenseAndUsageRights = RmsClientManager.EndAcquireUseLicenseAndUsageRights(asyncResult);
         if (string.IsNullOrEmpty(useLicenseAndUsageRights.UseLicense))
         {
             IrmLicensingManager.Tracer.TraceError((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: Use license is null/empty");
             throw new InvalidOperationException("Use license must NOT be null/empty");
         }
         if (this.userContext.State != UserContextState.Active)
         {
             IrmLicensingManager.Tracer.TraceDebug((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: User context is no longer active.  Bailing out.");
         }
         else
         {
             SafeRightsManagementHandle safeRightsManagementHandle = null;
             try
             {
                 RmsClientManager.BindUseLicenseForDecryption(new RmsClientManagerContext(useLicenseAndUsageRights.OrganizationId, RmsClientManagerContext.ContextId.MessageId, asyncState.MessageId.ToString(), null), useLicenseAndUsageRights.LicensingUri, useLicenseAndUsageRights.UseLicense, useLicenseAndUsageRights.PublishingLicense, out safeRightsManagementHandle);
             }
             finally
             {
                 if (safeRightsManagementHandle != null)
                 {
                     safeRightsManagementHandle.Close();
                 }
             }
             bool flag = false;
             try
             {
                 this.userContext.Lock();
                 flag = true;
                 using (Item item = Item.Bind(asyncState.MessageId.GetSession(this.userContext), asyncState.MessageId.StoreObjectId, ItemBindOption.None))
                 {
                     MessageItem messageItem = item as MessageItem;
                     if (messageItem == null)
                     {
                         IrmLicensingManager.Tracer.TraceError((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: bound item is not a message.  Ignoring it.");
                     }
                     else
                     {
                         messageItem.OpenAsReadWrite();
                         messageItem[MessageItemSchema.DRMRights]     = useLicenseAndUsageRights.UsageRights;
                         messageItem[MessageItemSchema.DRMExpiryTime] = useLicenseAndUsageRights.ExpiryTime;
                         if (!DrmClientUtils.IsCachingOfLicenseDisabled(useLicenseAndUsageRights.UseLicense))
                         {
                             using (Stream stream = messageItem.OpenPropertyStream(MessageItemSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create))
                             {
                                 DrmEmailCompression.CompressUseLicense(useLicenseAndUsageRights.UseLicense, stream);
                             }
                         }
                         messageItem[MessageItemSchema.DRMPropsSignature] = useLicenseAndUsageRights.DRMPropsSignature;
                         RightsManagedMessageItem rightsManagedMessageItem = messageItem as RightsManagedMessageItem;
                         if (rightsManagedMessageItem != null && rightsManagedMessageItem.IsRestricted && !rightsManagedMessageItem.TryDecode(Utilities.CreateOutboundConversionOptions(this.userContext), false).Failed)
                         {
                             bool flag2 = false;
                             foreach (AttachmentHandle attachmentHandle in rightsManagedMessageItem.ProtectedAttachmentCollection)
                             {
                                 if (!attachmentHandle.IsInline)
                                 {
                                     flag2 = true;
                                     break;
                                 }
                             }
                             messageItem[MessageItemSchema.AllAttachmentsHidden] = !flag2;
                             rightsManagedMessageItem.AbandonChangesOnProtectedData();
                         }
                         messageItem.Save(SaveMode.ResolveConflicts);
                         if (DrmClientUtils.IsCachingOfLicenseDisabled(useLicenseAndUsageRights.UseLicense))
                         {
                             this.EnqueueLicensingError(asyncState.MessageId, SanitizedHtmlString.FromStringId(-1616549110, this.userCulture), asyncState.RequestCorrelator);
                         }
                         else
                         {
                             this.EnqueueLicenseAcquired(asyncState.MessageId, asyncState.RequestCorrelator);
                         }
                     }
                 }
             }
             finally
             {
                 if (this.userContext.LockedByCurrentThread() && flag)
                 {
                     this.userContext.Unlock();
                 }
             }
         }
     }
     catch (OwaLockTimeoutException arg)
     {
         IrmLicensingManager.Tracer.TraceError <OwaLockTimeoutException>((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: timed-out at acquiring user context lock.  Exception: {0}", arg);
         this.EnqueueLicensingError(asyncState.MessageId, new SanitizedHtmlString(LocalizedStrings.GetNonEncoded(858913858)), asyncState.RequestCorrelator);
     }
     catch (ExchangeConfigurationException arg2)
     {
         IrmLicensingManager.Tracer.TraceError <ExchangeConfigurationException>((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: caught exception.  Exception: {0}", arg2);
         this.HandleExchangeConfigurationException(asyncState.MessageId, asyncState.RequestCorrelator);
     }
     catch (RightsManagementException ex)
     {
         IrmLicensingManager.Tracer.TraceError <RightsManagementException>((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: caught exception.  Exception: {0}", ex);
         this.HandleRightsManagementException(ex, asyncState.MessageId, asyncState.RequestCorrelator);
     }
     catch (StoragePermanentException ex2)
     {
         IrmLicensingManager.Tracer.TraceError <StoragePermanentException>((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: caught exception.  Exception: {0}", ex2);
         this.EnqueueLicensingError(asyncState.MessageId, SanitizedHtmlString.Format(LocalizedStrings.GetHtmlEncoded(994351595, this.userCulture), new object[]
         {
             ex2.Message
         }), asyncState.RequestCorrelator);
     }
     catch (TransientException arg3)
     {
         IrmLicensingManager.Tracer.TraceError <TransientException>((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: caught exception.  Exception: {0}", arg3);
         this.EnqueueLicensingError(asyncState.MessageId, new SanitizedHtmlString(LocalizedStrings.GetNonEncoded(858913858)), asyncState.RequestCorrelator);
     }
     catch (Exception ex3)
     {
         IrmLicensingManager.Tracer.TraceError <Exception>((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: caught exception.  Exception: {0}", ex3);
         if (Globals.SendWatsonReports)
         {
             IrmLicensingManager.Tracer.TraceError((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: sending watson report...");
             string data = string.Format("OWA version: {0}; Message Id: {1}", Globals.ApplicationVersion, asyncState.MessageId.ToBase64String());
             ExWatson.AddExtraData(data);
             ExWatson.SendReport(ex3, ReportOptions.None, null);
             IrmLicensingManager.Tracer.TraceError((long)this.GetHashCode(), "AcquireLicenseAndRightsCB: watson report has been sent.");
         }
     }
 }
コード例 #5
0
        private void DecryptMsg(MessageItem rightsProtectedMessage, string useLicense, SafeRightsManagementHandle decryptorHandle)
        {
            if (decryptorHandle == null)
            {
                throw new ArgumentNullException("decryptorHandle");
            }
            if (decryptorHandle.IsInvalid)
            {
                throw new ArgumentException("decryptorHandle");
            }
            this.originalItem = rightsProtectedMessage;
            DrmEmailMessage drmEmailMessage = null;
            bool            flag            = false;

            try
            {
                ExTraceGlobals.RightsManagementTracer.TraceDebug((long)this.GetHashCode(), "Found a use license for server. Decrypting message");
                DrmEmailMessageBinding messageBinding = new DrmEmailMessageBinding(this.drmMsgContainer.PublishLicense, decryptorHandle);
                this.drmMsgContainer.Bind(messageBinding, new CreateStreamCallbackDelegate(this.BodyStreamCallback), new CreateStreamCallbackDelegate(this.AttachmentsStreamCallback));
                drmEmailMessage = this.drmMsgContainer.EmailMessage;
                this.SaveAndCloseCurrentAttachment();
                this.decryptedItem.SafeSetProperty(InternalSchema.DRMServerLicense, useLicense);
                this.decryptedItem.SafeSetProperty(InternalSchema.DrmPublishLicense, this.drmMsgContainer.PublishLicense);
                if (drmEmailMessage.Attachments.Count > 0)
                {
                    ExTraceGlobals.RightsManagementTracer.TraceDebug <int>((long)this.GetHashCode(), "Number of attachments in the rights protected message : {0}", drmEmailMessage.Attachments.Count);
                    int num = 0;
                    foreach (DrmEmailAttachment drmEmailAttachment in drmEmailMessage.Attachments)
                    {
                        using (Attachment attachment = this.decryptedItem.AttachmentCollection.Open(this.messageAttachmentIds[num++], null))
                        {
                            attachment.FileName = drmEmailAttachment.FileName;
                            attachment[InternalSchema.DisplayName] = drmEmailAttachment.DisplayName;
                            attachment.ContentId = drmEmailAttachment.ContentId;
                            attachment[InternalSchema.AttachContentLocation] = drmEmailAttachment.ContentLocation;
                            attachment[InternalSchema.AttachMhtmlFlags]      = drmEmailAttachment.AttachFlags;
                            attachment[InternalSchema.AttachCalendarHidden]  = drmEmailAttachment.AttachHidden;
                            if (drmEmailAttachment.AttachHidden)
                            {
                                attachment.IsInline = true;
                            }
                            if (drmEmailMessage.BodyFormat == BodyFormat.Rtf)
                            {
                                attachment.RenderingPosition = (int)drmEmailAttachment.CharacterPosition;
                                if (attachment.AttachmentType == AttachmentType.EmbeddedMessage || attachment.AttachmentType == AttachmentType.Stream)
                                {
                                    attachment[InternalSchema.AttachRendering] = drmEmailAttachment.AttachRendering;
                                }
                            }
                            if (this.decryptAttachments)
                            {
                                Stream           stream           = null;
                                StreamAttachment streamAttachment = attachment as StreamAttachment;
                                if (streamAttachment != null && StreamAttachment.TryOpenRestrictedContent(streamAttachment, this.orgId, out stream))
                                {
                                    using (stream)
                                    {
                                        using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create))
                                        {
                                            Util.StreamHandler.CopyStreamData(stream, contentStream);
                                        }
                                    }
                                }
                            }
                            attachment.Save();
                        }
                    }
                }
                drmEmailMessage.Close();
                drmEmailMessage = null;
                if (this.originalItem != null)
                {
                    PersistablePropertyBag.CopyProperty(this.originalItem.PropertyBag, InternalSchema.TransportMessageHeaders, this.decryptedItem.PropertyBag);
                    this.decryptedItem.Recipients.CopyRecipientsFrom(this.originalItem.Recipients);
                }
                this.decryptedItem.Save(SaveMode.NoConflictResolution);
                this.decryptedItem.Load(InternalSchema.ContentConversionProperties);
                flag = true;
            }
            finally
            {
                if (drmEmailMessage != null)
                {
                    drmEmailMessage.Close();
                    drmEmailMessage = null;
                }
                if (!flag && this.decryptedItem != null)
                {
                    this.decryptedItem.Dispose();
                    this.decryptedItem = null;
                }
            }
        }