// Token: 0x060002C9 RID: 713 RVA: 0x0000A280 File Offset: 0x00008480
        public static WacRequest ParseWacRequest(string mailboxSmtpAddress, HttpRequest request)
        {
            if (request == null)
            {
                throw new OwaInvalidRequestException("Request object is null");
            }
            if (!UrlUtilities.IsWacRequest(request))
            {
                throw new OwaInvalidRequestException("Expected a WAC request, but got this instead: " + request.Url.AbsoluteUri);
            }
            WacRequestType requestType       = WacRequest.GetRequestType(request);
            string         text              = request.QueryString["access_token"] ?? string.Empty;
            string         exchangeSessionId = WacUtilities.GetExchangeSessionId(text);
            string         ewsAttachmentId;

            WacRequest.ParseAccessToken(text, out ewsAttachmentId);
            string     fileRepAsString = request.QueryString["owaatt"] ?? string.Empty;
            WacFileRep fileRep         = WacFileRep.Parse(fileRepAsString);
            string     value           = request.Headers["X-WOPI-PerfTraceRequested"] ?? string.Empty;
            bool       perfTraceRequested;

            if (!bool.TryParse(value, out perfTraceRequested))
            {
                perfTraceRequested = false;
            }
            return(new WacRequest(requestType, fileRep, (SmtpAddress)mailboxSmtpAddress, exchangeSessionId, ewsAttachmentId, request.QueryString["ui"] ?? "en-us", request.Headers["X-WOPI-InterfaceVersion"] ?? string.Empty, request.Headers["X-WOPI-MachineName"] ?? string.Empty, perfTraceRequested, request.Headers["X-WOPI-CorrelationID"] ?? string.Empty));
        }
Beispiel #2
0
        public static WacFileRep Parse(string fileRepAsString)
        {
            byte[]     array      = WacUtilities.FromBase64String(fileRepAsString);
            WacFileRep wacFileRep = null;

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(array))
                {
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream, new UTF8Encoding()))
                    {
                        string   text                    = binaryReader.ReadString();
                        DateTime creationTime            = new DateTime(binaryReader.ReadInt64());
                        bool     directFileAccessEnabled = binaryReader.ReadBoolean();
                        bool     externalServicesEnabled = binaryReader.ReadBoolean();
                        bool     wacOMEXEnabled          = binaryReader.ReadBoolean();
                        bool     isEdit                  = binaryReader.ReadBoolean();
                        bool     isArchive               = binaryReader.ReadBoolean();
                        wacFileRep = new WacFileRep(new SecurityIdentifier(text), creationTime, directFileAccessEnabled, externalServicesEnabled, wacOMEXEnabled, isEdit, isArchive);
                        if (!wacFileRep.LogonSid.IsAccountSid())
                        {
                            throw new OwaInvalidRequestException("WacFileRep contained an invalid SecurityIdentifier: " + text);
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                throw new OwaInvalidRequestException("Unable to parse WacRequest. (" + array.Length.ToString() + " bytes)");
            }
            return(wacFileRep);
        }
        // Token: 0x06001ADA RID: 6874 RVA: 0x000661A0 File Offset: 0x000643A0
        private static void GenerateWopiSrcUrl(HttpRequest request, WacFileRep wacFileRep, string emailAddress, out string wopiSrcUrl, out string wopiSrcUrlForLogging)
        {
            string text  = string.Format("owa/{0}/wopi/files/@/owaatt", HttpUtility.UrlEncode(emailAddress));
            string text2 = string.Format("owa/{0}/wopi/files/@/owaatt", ExtensibleLogger.FormatPIIValue(emailAddress));
            Uri    requestUrlEvenIfProxied = request.GetRequestUrlEvenIfProxied();

            wopiSrcUrl = string.Format("{0}://{1}:{2}/{3}?{4}={5}", new object[]
            {
                requestUrlEvenIfProxied.Scheme,
                requestUrlEvenIfProxied.Host,
                requestUrlEvenIfProxied.Port,
                text,
                "owaatt",
                HttpUtility.UrlEncode(wacFileRep.Serialize())
            });
            wopiSrcUrlForLogging = string.Format("{0}://{1}:{2}/{3}?{4}={5}", new object[]
            {
                requestUrlEvenIfProxied.Scheme,
                requestUrlEvenIfProxied.Host,
                requestUrlEvenIfProxied.Port,
                text2,
                "owaatt",
                HttpUtility.UrlEncode(wacFileRep.Serialize())
            });
            if (Globals.IsPreCheckinApp && request.Cookies["X-DFPOWA-Vdir"] != null)
            {
                wopiSrcUrl = string.Format("{0}&vdir={1}", wopiSrcUrl, request.Cookies["X-DFPOWA-Vdir"].Value);
            }
        }
 private static string GetDownloadUrl(HttpRequest request, WacFileRep wacFileRep, WacRequest wacRequest)
 {
     if (wacFileRep.DirectFileAccessEnabled)
     {
         Uri    url  = request.Url;
         string text = request.Headers["X-OWA-ProxyUri"];
         string text2;
         if (wacRequest == null || wacRequest.WacFileRep.LogonSid == null || string.IsNullOrWhiteSpace(wacRequest.WacFileRep.LogonSid.Value))
         {
             text2 = "WAC_no_user_sid";
         }
         else
         {
             Canary15 canary = new Canary15(wacRequest.WacFileRep.LogonSid.Value);
             text2 = canary.ToString();
         }
         return(string.Format(CultureInfo.InvariantCulture, "{0}{1}?id={2}&{3}={4}", new object[]
         {
             text,
             "/service.svc/s/GetFileAttachment",
             HttpUtility.UrlEncode(wacRequest.EwsAttachmentId),
             "X-OWA-CANARY",
             text2
         }));
     }
     return(string.Empty);
 }
 // Token: 0x060002B3 RID: 691 RVA: 0x0000A148 File Offset: 0x00008348
 private WacRequest(WacRequestType requestType, WacFileRep fileRep, SmtpAddress mailboxSmtpAddress, string exchangeSessionId, string ewsAttachmentId, string culture, string clientVersion, string machineName, bool perfTraceRequested, string correlationID)
 {
     this.RequestType        = requestType;
     this.WacFileRep         = fileRep;
     this.MailboxSmtpAddress = mailboxSmtpAddress;
     this.ExchangeSessionId  = exchangeSessionId;
     this.EwsAttachmentId    = ewsAttachmentId;
     this.CultureName        = culture;
     this.ClientVersion      = clientVersion;
     this.MachineName        = machineName;
     this.PerfTraceRequested = perfTraceRequested;
     this.CorrelationID      = correlationID;
 }
        // Token: 0x06001AD7 RID: 6871 RVA: 0x00065FAC File Offset: 0x000641AC
        private static WacAttachmentType GetResultForStreamAttachment(CallContext callContext, UserContext userContext, ConfigurationContext configurationContext, AttachmentPolicy attachmentPolicy, bool isPublicLogon, string cultureName, bool isEdit, IStreamAttachment attachment, string attachmentExtension, AttachmentIdType attachmentIdType, bool isInDraft, IStoreSession storeSession, string mailboxSmtpAddress, bool isArchive)
        {
            WacFileRep  wacFileRep = GetWacAttachmentInfo.CreateWacFileRep(callContext, configurationContext, attachmentPolicy, isPublicLogon, isEdit, isArchive);
            HttpRequest request    = callContext.HttpContext.Request;
            string      text;
            string      arg;

            GetWacAttachmentInfo.GenerateWopiSrcUrl(request, wacFileRep, mailboxSmtpAddress, out text, out arg);
            if (text == null)
            {
                throw new OwaInvalidOperationException("WOPI URL is null.");
            }
            string      id                = attachmentIdType.Id;
            TokenResult oauthToken        = GetWacAttachmentInfo.GetOAuthToken(id, userContext, mailboxSmtpAddress, text);
            string      exchangeSessionId = WacUtilities.GetExchangeSessionId(oauthToken.TokenString);

            callContext.ProtocolLog.Set(GetWacAttachmentInfoMetadata.ExchangeSessionId, exchangeSessionId);
            SecurityIdentifier effectiveCallerSid = callContext.EffectiveCallerSid;

            CachedAttachmentInfo.GetInstance(mailboxSmtpAddress, id, exchangeSessionId, effectiveCallerSid, cultureName);
            string wacUrl = GetWacAttachmentInfo.GetWacUrl(isEdit, cultureName, attachmentExtension);

            if (string.IsNullOrEmpty(wacUrl))
            {
                throw new OwaInvalidRequestException(string.Format("Wac Base Url is null for this given extension {0} and culture {1}", attachmentExtension, cultureName));
            }
            new Uri(wacUrl);
            string format = "{0}WOPISrc={1}&access_token={2}";
            string arg2   = HttpUtility.UrlEncode(oauthToken.TokenString);
            string text2  = string.Format(format, wacUrl, HttpUtility.UrlEncode(text), arg2);
            string value  = string.Format(format, wacUrl, arg, arg2);

            callContext.ProtocolLog.Set(GetWacAttachmentInfoMetadata.WacUrl, value);
            if (!Uri.IsWellFormedUriString(text2, UriKind.Absolute))
            {
                throw new OwaInvalidOperationException("The WAC Iframe URL that was generated is not a well formed URI: " + text2);
            }
            return(new WacAttachmentType
            {
                AttachmentId = attachmentIdType,
                IsEdit = isEdit,
                IsInDraft = isInDraft,
                WacUrl = text2,
                Status = WacAttachmentStatus.Success
            });
        }
        private static void ProcessCheckFileRequest(HttpContext context, WacRequest wacRequest, RequestDetailsLogger logger)
        {
            WacRequestHandler.UpdateAttachment(wacRequest, logger);
            CachedAttachmentInfo cachedAttachmentInfo = WacRequestHandler.GetCachedAttachmentInfo(wacRequest);
            string attachmentStreamHash   = null;
            long   attachmentStreamLength = 0L;
            string attachmentFileName     = null;
            string attachmentExtension    = null;
            bool   attachmentIsProtected  = false;

            WacRequestHandler.ProcessAttachment(wacRequest, PropertyOpenMode.ReadOnly, delegate(IExchangePrincipal exchangePrincipal, Attachment attachment, Stream stream, bool isProtected)
            {
                attachmentStreamHash   = WacUtilities.GenerateSHA256HashForStream(stream);
                attachmentStreamLength = stream.Length;
                attachmentFileName     = attachment.FileName;
                attachmentExtension    = attachment.FileExtension;
                attachmentIsProtected  = isProtected;
            });
            WacFileRep           wacFileRep           = wacRequest.WacFileRep;
            string               downloadUrl          = WacRequestHandler.GetDownloadUrl(context.Request, wacFileRep, wacRequest);
            WacCheckFileResponse wacCheckFileResponse = new WacCheckFileResponse(attachmentFileName, attachmentStreamLength, attachmentStreamHash, downloadUrl, cachedAttachmentInfo.MailboxSmtpAddress, cachedAttachmentInfo.LogonSmtpAddress, cachedAttachmentInfo.LogonDisplayName, cachedAttachmentInfo.LogonPuid, attachmentIsProtected, wacFileRep.DirectFileAccessEnabled, wacFileRep.WacExternalServicesEnabled, wacFileRep.OMEXEnabled);

            if (wacFileRep.IsEdit)
            {
                wacCheckFileResponse.UserCanWrite    = true;
                wacCheckFileResponse.ReadOnly        = false;
                wacCheckFileResponse.SupportsUpdate  = true;
                wacCheckFileResponse.SupportsLocks   = true;
                wacCheckFileResponse.SupportsCobalt  = true;
                wacCheckFileResponse.SupportsFolders = true;
            }
            DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(WacCheckFileResponse));

            using (MemoryStream memoryStream = new MemoryStream())
            {
                dataContractJsonSerializer.WriteObject(memoryStream, wacCheckFileResponse);
                memoryStream.Position = 0L;
                context.Response.OutputStream.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
            }
        }