public void PrepareAcquiredLicensesBeforeSave() { this.CheckDisposed("PrepareAcquiredLicensesBeforeSave"); if (this.licenseAcquired) { this[MessageItemSchema.DRMRights] = this.useLicenseValue.UsageRights; this[MessageItemSchema.DRMExpiryTime] = this.useLicenseValue.ExpiryTime; if (!DrmClientUtils.IsCachingOfLicenseDisabled(this.useLicenseValue.UseLicense)) { using (Stream stream = base.OpenPropertyStream(MessageItemSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create)) { DrmEmailCompression.CompressUseLicense(this.useLicenseValue.UseLicense, stream); } } this[MessageItemSchema.DRMPropsSignature] = this.useLicenseValue.DRMPropsSignature; } }
protected override void OnBeforeSave() { if (this.decodedItem == null && !base.AttachmentCollection.IsDirty && base.IsRestricted && (base.Recipients.IsDirty || base.IsPropertyDirty(ItemSchema.Sender))) { this.EnsureIsDecoded(); } if (this.decodedItem != null) { string contentClass = base.TryGetProperty(InternalSchema.ContentClass) as string; if (this.rmsTemplate == null) { this.UnprotectAllAttachments(); RightsManagedMessageItem.CopyProtectableData(this.decodedItem, this); if (ObjectClass.IsRightsManagedContentClass(contentClass)) { base.Delete(StoreObjectSchema.ContentClass); } } else { this.charsetDetectionStringForProtectedData = new StringBuilder((int)Math.Min(this.ProtectedBody.Size, 2147483647L)); this.GetCharsetDetectionStringFromProtectedData(this.charsetDetectionStringForProtectedData); if (!ObjectClass.IsRightsManagedContentClass(contentClass)) { this[StoreObjectSchema.ContentClass] = "rpmsg.message"; } if (this.isSending) { byte[][] valueOrDefault = base.GetValueOrDefault <byte[][]>(InternalSchema.DRMLicense); if (valueOrDefault != null && valueOrDefault.Length == RightsManagedMessageItem.EmptyDrmLicense.Length && valueOrDefault[0].Length == RightsManagedMessageItem.EmptyDrmLicense[0].Length) { base.DeleteProperties(new PropertyDefinition[] { InternalSchema.DRMLicense }); } } else if (base.IsDraft && base.GetValueOrDefault <byte[][]>(InternalSchema.DRMLicense) == null) { this[InternalSchema.DRMLicense] = RightsManagedMessageItem.EmptyDrmLicense; } base.AttachmentCollection.RemoveAll(); using (StreamAttachment streamAttachment = base.AttachmentCollection.Create(AttachmentType.Stream) as StreamAttachment) { streamAttachment.FileName = "message.rpmsg"; streamAttachment.ContentType = "application/x-microsoft-rpmsg-message"; using (Stream stream = new PooledMemoryStream(131072)) { if (this.serverUseLicense == null || ((this.UsageRights & ContentRight.Owner) == ContentRight.Owner && this.rmsTemplate.RequiresRepublishingWhenRecipientsChange && this.CanRepublish && (base.Recipients.IsDirty || (base.IsPropertyDirty(ItemSchema.Sender) && this.conversationOwner == null)))) { if (this.ConversationOwner == null) { throw new InvalidOperationException("Conversation owner must be set before protecting the message."); } this.UnprotectAllAttachments(); using (MsgToRpMsgConverter msgToRpMsgConverter = new MsgToRpMsgConverter(this, this.ConversationOwner, this.orgId, this.rmsTemplate, this.options)) { msgToRpMsgConverter.Convert(this.decodedItem, stream); using (Stream stream2 = base.OpenPropertyStream(MessageItemSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create)) { DrmEmailCompression.CompressUseLicense(msgToRpMsgConverter.ServerUseLicense, stream2); } if (this.InternalSession != null && this.InternalSession.MailboxOwner.Sid != null) { ExDateTime useLicenseExpiryTime = RmsClientManagerUtils.GetUseLicenseExpiryTime(msgToRpMsgConverter.ServerUseLicense, this.UsageRights); this[MessageItemSchema.DRMRights] = (int)this.UsageRights; this[MessageItemSchema.DRMExpiryTime] = useLicenseExpiryTime; using (RightsSignatureBuilder rightsSignatureBuilder = new RightsSignatureBuilder(msgToRpMsgConverter.ServerUseLicense, msgToRpMsgConverter.PublishLicense, RmsClientManager.EnvironmentHandle, msgToRpMsgConverter.LicensePair)) { this[MessageItemSchema.DRMPropsSignature] = rightsSignatureBuilder.Sign(this.UsageRights, useLicenseExpiryTime, this.InternalSession.MailboxOwner.Sid); } } goto IL_362; } } using (MsgToRpMsgConverter msgToRpMsgConverter2 = new MsgToRpMsgConverter(this, this.orgId, this.publishLicense, this.serverUseLicense, this.options)) { msgToRpMsgConverter2.Convert(this.decodedItem, stream); } IL_362: using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create)) { stream.Seek(0L, SeekOrigin.Begin); Util.StreamHandler.CopyStreamData(stream, contentStream); } } bool flag = false; foreach (AttachmentHandle handle in this.decodedItem.AttachmentCollection) { if (!CoreAttachmentCollection.IsInlineAttachment(handle)) { flag = true; break; } } this[InternalSchema.AllAttachmentsHidden] = !flag; streamAttachment.Save(); } } this.decodedItem.Dispose(); this.decodedItem = null; this.effectiveRights = ContentRight.Owner; this.publishLicense = null; this.restrictionInfo = null; this.rmsTemplate = null; this.serverUseLicense = null; this.conversationOwner = null; } base.OnBeforeSave(); }
private Stream LoadAttachmentDocument(bool isLoadingStream, out RightsManagedMessageDecryptionStatus decryptionStatus) { decryptionStatus = RightsManagedMessageDecryptionStatus.Success; StringBuilder stringBuilder = new StringBuilder(); List <AttachmentId> list = new List <AttachmentId>(); UserContext userContext = this.owaContext.UserContext; string queryStringParameter = Utilities.GetQueryStringParameter(this.owaContext.HttpContext.Request, "ewsid", false); bool flag = string.IsNullOrEmpty(queryStringParameter); OwaStoreObjectId owaStoreObjectId; string text; if (!flag) { stringBuilder.Append("service.svc/s/GetFileAttachment?id="); stringBuilder.Append(Utilities.UrlEncode(queryStringParameter)); string canary15CookieValue = Utilities.GetCanary15CookieValue(); if (canary15CookieValue != null) { stringBuilder.Append("&X-OWA-CANARY=" + canary15CookieValue); } IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(queryStringParameter, BasicTypes.Attachment, list); owaStoreObjectId = OwaStoreObjectId.CreateFromMailboxItemId(idHeaderInformation.ToStoreObjectId()); text = owaStoreObjectId.ToString(); } else { text = Utilities.GetQueryStringParameter(this.owaContext.HttpContext.Request, "id"); owaStoreObjectId = OwaStoreObjectId.CreateFromString(text); stringBuilder.Append("attachment.ashx?attach=1&id="); stringBuilder.Append(Utilities.UrlEncode(text)); } Stream result; using (Item item = Utilities.GetItem <Item>(userContext, owaStoreObjectId, new PropertyDefinition[] { ItemSchema.SentRepresentingDisplayName, ItemSchema.Subject })) { if (!Utilities.IsPublic(item) && userContext.IsIrmEnabled && isLoadingStream) { item.OpenAsReadWrite(); } if (Utilities.IsIrmRestricted(item)) { if (!userContext.IsIrmEnabled || userContext.IsBasicExperience) { decryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled; return(null); } RightsManagedMessageItem rightsManagedMessageItem = (RightsManagedMessageItem)item; if (!rightsManagedMessageItem.CanDecode) { decryptionStatus = RightsManagedMessageDecryptionStatus.NotSupported; return(null); } try { Utilities.IrmDecryptIfRestricted(item, userContext, true); } catch (RightsManagementPermanentException exception) { decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception); return(null); } catch (RightsManagementTransientException exception2) { decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception2); return(null); } } this.messageFrom = ItemUtility.GetProperty <string>(item, ItemSchema.SentRepresentingDisplayName, string.Empty); this.messageSubject = ItemUtility.GetProperty <string>(item, ItemSchema.Subject, string.Empty); this.messageId = text; if (flag) { Utilities.FillAttachmentIdList(item, this.owaContext.HttpContext.Request, list); } using (StreamAttachment streamAttachment = Utilities.GetAttachment(item, list, userContext) as StreamAttachment) { if (streamAttachment == null) { throw new OwaInvalidRequestException("Attachment is not a stream attachment"); } this.mimeType = (streamAttachment.ContentType ?? streamAttachment.CalculatedContentType); this.fileName = ((!string.IsNullOrEmpty(streamAttachment.DisplayName)) ? streamAttachment.DisplayName : streamAttachment.FileName); this.fileSize = streamAttachment.Size; this.documentPath = this.fileName; this.documentIdStringBuilder.Append(Convert.ToBase64String(userContext.MailboxSession.MailboxOwner.MailboxInfo.GetDatabaseGuid().ToByteArray())); this.documentIdStringBuilder.Append("-"); for (int i = 0; i < list.Count; i++) { this.documentIdStringBuilder.Append(list[i].ToBase64String()); this.documentIdStringBuilder.Append("-"); if (flag) { stringBuilder.Append("&attid"); stringBuilder.Append(i.ToString(CultureInfo.InstalledUICulture)); stringBuilder.Append("="); stringBuilder.Append(Utilities.UrlEncode(list[i].ToBase64String())); } } if (flag) { stringBuilder.Append("&attcnt="); stringBuilder.Append(list.Count); } this.documentIdStringBuilder.Append(streamAttachment.LastModifiedTime.UtcTicks); this.openLink = stringBuilder.ToString(); if (isLoadingStream) { Stream contentStream = streamAttachment.GetContentStream(); MsoIpiResult msoIpiResult = MsoIpiResult.Unknown; try { msoIpiResult = ProtectorsManager.Instance.IsProtected(this.fileName, contentStream); } catch (AttachmentProtectionException exception3) { decryptionStatus = new RightsManagedMessageDecryptionStatus(RightsManagementFailureCode.CorruptData, exception3); return(null); } if (msoIpiResult == MsoIpiResult.Protected) { this.isIrmProtected = true; contentStream.Dispose(); if (!userContext.IsIrmEnabled || userContext.IsBasicExperience) { decryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled; result = null; } else { UseLicenseAndUsageRights useLicenseAndUsageRights; bool flag2; Stream stream; try { stream = StreamAttachment.OpenRestrictedAttachment(streamAttachment, this.owaContext.ExchangePrincipal.MailboxInfo.OrganizationId, this.owaContext.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), this.owaContext.LogonIdentity.UserSid, this.owaContext.ExchangePrincipal.RecipientTypeDetails, out useLicenseAndUsageRights, out flag2); } catch (RightsManagementPermanentException exception4) { decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception4); return(null); } catch (RightsManagementTransientException exception5) { decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception5); return(null); } if (flag2 && ObjectClass.IsMessage(item.ClassName, false) && !Utilities.IsIrmRestricted(item)) { object obj = item.TryGetProperty(MessageItemSchema.IsDraft); if (obj is bool && !(bool)obj && !DrmClientUtils.IsCachingOfLicenseDisabled(useLicenseAndUsageRights.UseLicense)) { streamAttachment[AttachmentSchema.DRMRights] = useLicenseAndUsageRights.UsageRights; streamAttachment[AttachmentSchema.DRMExpiryTime] = useLicenseAndUsageRights.ExpiryTime; using (Stream stream2 = streamAttachment.OpenPropertyStream(AttachmentSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create)) { DrmEmailCompression.CompressUseLicense(useLicenseAndUsageRights.UseLicense, stream2); } streamAttachment[AttachmentSchema.DRMPropsSignature] = useLicenseAndUsageRights.DRMPropsSignature; streamAttachment.Save(); item.Save(SaveMode.ResolveConflicts); } } string conversationOwnerFromPublishLicense = DrmClientUtils.GetConversationOwnerFromPublishLicense(useLicenseAndUsageRights.PublishingLicense); RmsTemplate rmsTemplate = RmsTemplate.CreateFromPublishLicense(useLicenseAndUsageRights.PublishingLicense); this.isPrintRestricted = !useLicenseAndUsageRights.UsageRights.IsUsageRightGranted(ContentRight.Print); this.isCopyRestricted = !useLicenseAndUsageRights.UsageRights.IsUsageRightGranted(ContentRight.Extract); SanitizingStringBuilder <OwaHtml> sanitizingStringBuilder = new SanitizingStringBuilder <OwaHtml>(); string str = string.Format(LocalizedStrings.GetNonEncoded(-500320626), rmsTemplate.Name, rmsTemplate.Description); sanitizingStringBuilder.Append(str); if (!string.IsNullOrEmpty(conversationOwnerFromPublishLicense)) { sanitizingStringBuilder.Append("<br>"); sanitizingStringBuilder.Append(string.Format(LocalizedStrings.GetNonEncoded(1670455506), conversationOwnerFromPublishLicense)); } this.irmInfobarMessage = sanitizingStringBuilder.ToSanitizedString <SanitizedHtmlString>(); result = stream; } } else { contentStream.Seek(0L, SeekOrigin.Begin); result = contentStream; } } else { result = null; } } } return(result); }
public static Stream OpenRestrictedAttachment(StreamAttachment sourceAttachment, OrganizationId orgId, string userIdentity, SecurityIdentifier userSid, RecipientTypeDetails userType, out UseLicenseAndUsageRights validatedUseLicenseAndUsageRights, out bool acquiredNewLicense) { StreamAttachment.< > c__DisplayClass2 CS$ < > 8__locals1 = new StreamAttachment.< > c__DisplayClass2(); CS$ < > 8__locals1.sourceAttachment = sourceAttachment; CS$ < > 8__locals1.orgId = orgId; CS$ < > 8__locals1.userIdentity = userIdentity; CS$ < > 8__locals1.userSid = userSid; CS$ < > 8__locals1.userType = userType; Util.ThrowOnNullArgument(CS$ < > 8__locals1.sourceAttachment, "sourceAttachment"); Util.ThrowOnNullArgument(CS$ < > 8__locals1.orgId, "orgId"); Util.ThrowOnNullArgument(CS$ < > 8__locals1.userIdentity, "userIdentity"); Util.ThrowOnNullArgument(CS$ < > 8__locals1.userSid, "userSid"); if (!Enum.IsDefined(typeof(RecipientTypeDetails), CS$ < > 8__locals1.userType)) { throw new EnumArgumentException("userType"); } CS$ < > 8__locals1.cachedServerUseLicense = null; if (!PropertyError.IsPropertyNotFound(CS$ < > 8__locals1.sourceAttachment.TryGetProperty(AttachmentSchema.DRMServerLicenseCompressed))) { using (Stream stream = CS$ < > 8__locals1.sourceAttachment.OpenPropertyStream(AttachmentSchema.DRMServerLicenseCompressed, PropertyOpenMode.ReadOnly)) { CS$ < > 8__locals1.cachedServerUseLicense = DrmEmailCompression.DecompressUseLicense(stream); } } StreamAttachment.< > c__DisplayClass2 CS$ < > 8__locals2 = CS$ < > 8__locals1; int?valueAsNullable = CS$ < > 8__locals1.sourceAttachment.PropertyBag.GetValueAsNullable <int>(AttachmentSchema.DRMRights); CS$ < > 8__locals2.cachedUsageRights = ((valueAsNullable != null) ? new ContentRight?((ContentRight)valueAsNullable.GetValueOrDefault()) : null); CS$ < > 8__locals1.cachedExpiryTime = CS$ < > 8__locals1.sourceAttachment.PropertyBag.GetValueAsNullable <ExDateTime>(AttachmentSchema.DRMExpiryTime); CS$ < > 8__locals1.cachedDrmPropsSignature = CS$ < > 8__locals1.sourceAttachment.PropertyBag.GetValueOrDefault <byte[]>(AttachmentSchema.DRMPropsSignature); CS$ < > 8__locals1.item = CS$ < > 8__locals1.sourceAttachment.CoreAttachment.ParentCollection.ContainerItem; if (string.IsNullOrEmpty(CS$ < > 8__locals1.cachedServerUseLicense) || CS$ < > 8__locals1.cachedUsageRights == null || CS$ < > 8__locals1.cachedExpiryTime == null || CS$ < > 8__locals1.cachedDrmPropsSignature == null) { string valueOrDefault = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <string>(StoreObjectSchema.ItemClass, string.Empty); if (ObjectClass.IsMessage(valueOrDefault, false)) { CS$ < > 8__locals1.cachedServerUseLicense = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <string>(MessageItemSchema.DRMServerLicense, string.Empty); StreamAttachment.< > c__DisplayClass2 CS$ < > 8__locals3 = CS$ < > 8__locals1; int?valueAsNullable2 = CS$ < > 8__locals1.item.PropertyBag.GetValueAsNullable <int>(MessageItemSchema.DRMRights); CS$ < > 8__locals3.cachedUsageRights = ((valueAsNullable2 != null) ? new ContentRight?((ContentRight)valueAsNullable2.GetValueOrDefault()) : null); CS$ < > 8__locals1.cachedExpiryTime = CS$ < > 8__locals1.item.PropertyBag.GetValueAsNullable <ExDateTime>(MessageItemSchema.DRMExpiryTime); CS$ < > 8__locals1.cachedDrmPropsSignature = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <byte[]>(MessageItemSchema.DRMPropsSignature); } } CS$ < > 8__locals1.unprotectionSuccess = false; CS$ < > 8__locals1.useLicenseAndUsageRights = null; CS$ < > 8__locals1.validCachedLicense = false; Stream unprotectedAttachment; using (DisposeGuard disposeGuard = default(DisposeGuard)) { StreamAttachment.< > c__DisplayClass4 CS$ < > 8__locals4 = new StreamAttachment.< > c__DisplayClass4(); CS$ < > 8__locals4.unprotectedAttachment = disposeGuard.Add <Stream>(Streams.CreateTemporaryStorageStream()); CS$ < > 8__locals4.decryptorHandle = null; using (Stream inputStream = CS$ < > 8__locals1.sourceAttachment.GetContentStream(PropertyOpenMode.ReadOnly)) { try { MsgToRpMsgConverter.CallRM(delegate { CS$ < > 8__locals1.unprotectionSuccess = ProtectorsManager.Instance.Unprotect(delegate(string protectedDocumentIssuanceLicense) { string valueOrDefault2 = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <string>(ItemSchema.InternetMessageId, string.Empty); bool flag = string.IsNullOrEmpty(valueOrDefault2); RmsClientManagerContext context = new RmsClientManagerContext(CS$ < > 8__locals1.orgId, flag ? RmsClientManagerContext.ContextId.AttachmentFileName : RmsClientManagerContext.ContextId.MessageId, flag ? CS$ < > 8__locals1.sourceAttachment.FileName : valueOrDefault2, null); if (!string.IsNullOrEmpty(CS$ < > 8__locals1.cachedServerUseLicense) && CS$ < > 8__locals1.cachedUsageRights != null && CS$ < > 8__locals1.cachedExpiryTime != null && CS$ < > 8__locals1.cachedDrmPropsSignature != null) { try { CS$ < > 8__locals4.decryptorHandle = RmsClientManager.VerifyDRMPropsSignatureAndGetDecryptor(context, CS$ < > 8__locals1.userSid, CS$ < > 8__locals1.userType, CS$ < > 8__locals1.userIdentity, CS$ < > 8__locals1.cachedUsageRights.Value, CS$ < > 8__locals1.cachedExpiryTime.Value, CS$ < > 8__locals1.cachedDrmPropsSignature, CS$ < > 8__locals1.cachedServerUseLicense, protectedDocumentIssuanceLicense, UsageRightsSignatureVerificationOptions.LookupSidHistory, StreamAttachment.EmptySidList); CS$ < > 8__locals1.validCachedLicense = true; Uri licensingUri = null; XmlNode[] array = null; bool flag2; RmsClientManager.GetLicensingUri(CS$ < > 8__locals1.orgId, protectedDocumentIssuanceLicense, out licensingUri, out array, out flag2); CS$ < > 8__locals1.useLicenseAndUsageRights = new UseLicenseAndUsageRights(CS$ < > 8__locals1.cachedServerUseLicense, CS$ < > 8__locals1.cachedUsageRights.Value, CS$ < > 8__locals1.cachedExpiryTime.Value, CS$ < > 8__locals1.cachedDrmPropsSignature, CS$ < > 8__locals1.orgId, protectedDocumentIssuanceLicense, licensingUri); } catch (BadDRMPropsSignatureException) { } } if (CS$ < > 8__locals1.useLicenseAndUsageRights == null) { CS$ < > 8__locals1.useLicenseAndUsageRights = RmsClientManager.AcquireUseLicenseAndUsageRights(context, protectedDocumentIssuanceLicense, CS$ < > 8__locals1.userIdentity, CS$ < > 8__locals1.userSid, CS$ < > 8__locals1.userType); if (CS$ < > 8__locals4.decryptorHandle != null) { CS$ < > 8__locals4.decryptorHandle.Close(); CS$ < > 8__locals4.decryptorHandle = null; } RmsClientManager.BindUseLicenseForDecryption(context, CS$ < > 8__locals1.useLicenseAndUsageRights.LicensingUri, CS$ < > 8__locals1.useLicenseAndUsageRights.UseLicense, CS$ < > 8__locals1.useLicenseAndUsageRights.PublishingLicense, out CS$ < > 8__locals4.decryptorHandle); } return(CS$ < > 8__locals4.decryptorHandle); }, CS$ < > 8__locals1.sourceAttachment.FileName, inputStream, CS$ < > 8__locals4.unprotectedAttachment); }, ServerStrings.FailedToUnprotectAttachment(CS$ < > 8__locals1.sourceAttachment.FileName)); }
// Token: 0x0600012F RID: 303 RVA: 0x00007734 File Offset: 0x00005934 private static void LicenseMessage(IExchangePrincipal userPrincipal, MessageItem item) { string publishLicense; using (Attachment attachment = item.AttachmentCollection.Open(item.AttachmentCollection.GetHandles()[0])) { using (Stream contentStream = ((StreamAttachmentBase)attachment).GetContentStream(PropertyOpenMode.ReadOnly)) { using (DrmEmailMessageContainer drmEmailMessageContainer = new DrmEmailMessageContainer()) { try { drmEmailMessageContainer.Load(contentStream, (object param0) => Streams.CreateTemporaryStorageStream()); publishLicense = drmEmailMessageContainer.PublishLicense; } catch (InvalidRpmsgFormatException arg) { LicensingProcessor.Tracer.TraceError <object, InvalidRpmsgFormatException>(0L, "{0}: LicensingProcessor:Failed to load RPMSG. {1}", TraceContext.Get(), arg); return; } } } } UseLicenseAndUsageRights useLicenseAndUsageRights; try { useLicenseAndUsageRights = RmsClientManager.AcquireUseLicenseAndUsageRights(new RmsClientManagerContext(userPrincipal.MailboxInfo.OrganizationId, RmsClientManagerContext.ContextId.MessageId, item.InternetMessageId, publishLicense), publishLicense, userPrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), userPrincipal.Sid, userPrincipal.RecipientTypeDetails); } catch (RightsManagementException ex) { LicensingProcessor.Tracer.TraceError <object, RightsManagementException>(0L, "{0}: LicensingProcessor:Failed to license message. {1}", TraceContext.Get(), ex); if (!ex.IsPermanent) { throw new StorageTransientException(Strings.FailedToAcquireUseLicense, ex); } return; } catch (ExchangeConfigurationException ex2) { LicensingProcessor.Tracer.TraceError <object, ExchangeConfigurationException>(0L, "{0}: LicensingProcessor:Failed to license message. {1}", TraceContext.Get(), ex2); throw new StorageTransientException(Strings.FailedToReadIRMConfig, ex2); } LicensingProcessor.Tracer.TraceDebug(0L, "{0}: LicensingProcesssor: Saving licenses", new object[] { TraceContext.Get() }); item.OpenAsReadWrite(); item[MessageItemSchema.DRMRights] = useLicenseAndUsageRights.UsageRights; item[MessageItemSchema.DRMExpiryTime] = useLicenseAndUsageRights.ExpiryTime; if (!DrmClientUtils.IsCachingOfLicenseDisabled(useLicenseAndUsageRights.UseLicense)) { using (Stream stream = item.OpenPropertyStream(MessageItemSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create)) { DrmEmailCompression.CompressUseLicense(useLicenseAndUsageRights.UseLicense, stream); } } item[MessageItemSchema.DRMPropsSignature] = useLicenseAndUsageRights.DRMPropsSignature; item.Save(SaveMode.ResolveConflicts); LicensingProcessor.Tracer.TraceDebug(0L, "{0}: LicensingProcesssor: message was saved successfully", new object[] { TraceContext.Get() }); }
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."); } } }