Exemplo n.º 1
0
        /// <summary>
        /// Create the info section for the cast call.
        /// </summary>
        /// <returns>The infor section.</returns>
        internal XElement CreateCastCallInfoSection()
        {
            XElement content = new XElement("content",
                                            new XElement("app-id", AppIdInstance.ToString()),
                                            new XElement("hmac", "HMACSHA256"),
                                            new XElement("signing-time", DateTime.UtcNow.ToString("O"))
                                            );

            XElement outer = new XElement("outer", content);

            XmlReader reader = outer.CreateReader();

            reader.MoveToContent();
            string s = reader.ReadInnerXml();

            s = HealthVaultService.GetOuterXml(content);

            string hmac = MobilePlatform.ComputeSha256Hmac(Convert.FromBase64String(SharedSecret), s);

            XElement info = new XElement("info",
                                         new XElement("auth-info",
                                                      new XElement("app-id", AppIdInstance.ToString()),
                                                      new XElement("credential",
                                                                   new XElement("appserver2",
                                                                                new XElement("hmacSig", hmac,
                                                                                             new XAttribute("algName", "HMACSHA256")
                                                                                             ),
                                                                                content
                                                                                )
                                                                   )
                                                      )
                                         );

            return(info);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the last-saved configuration from isolated storage.
        /// </summary>
        /// <param name="name">The filename to use.</param>
        public void LoadSettings(string name)
        {
            string settingsXml = MobilePlatform.ReadTextFromFile(name);

            if (settingsXml != null)
            {
                XElement settings = XElement.Parse(settingsXml);

                string version = settings.Element("Version").Value;

                string applicationIdString = settings.Element("ApplicationId").Value;
                AppIdInstance             = new Guid(applicationIdString);
                AuthorizationSessionToken = settings.Element("AuthorizationSessionToken").Value;
                SharedSecret        = settings.Element("SharedSecret").Value;
                Country             = settings.Element("Country").Value;
                Language            = settings.Element("Language").Value;
                SessionSharedSecret = settings.Element("SessionSharedSecret").Value;

                // Create a temporary current record until we fetch the real one.
                XElement personIdNode = settings.Element("PersonId");
                if (settings.Element("PersonId") != null)
                {
                    Guid personId = new Guid(settings.Element("PersonId").Value);
                    Guid recordId = new Guid(settings.Element("RecordId").Value);

                    CurrentRecord            = new HealthVaultRecord(personId, recordId);
                    CurrentRecord.RecordName = settings.Element("RecordName").Value;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the current configuration to isolated storage.
        /// </summary>
        /// <param name="name">The filename to use.</param>
        public void SaveSettings(string name)
        {
            XElement settings = new XElement("HealthVaultSettings",
                                             new XElement("Version", SettingsVersion),
                                             new XElement("ApplicationId", AppIdInstance.ToString()),
                                             new XElement("ApplicationCreationToken", ApplicationCreationToken),
                                             new XElement("AuthorizationSessionToken", AuthorizationSessionToken),
                                             new XElement("SharedSecret", SharedSecret),
                                             new XElement("Country", Country),
                                             new XElement("Language", Language),
                                             new XElement("SessionSharedSecret", SessionSharedSecret)
                                             );

            if (CurrentRecord != null)
            {
                settings.Add(new XElement("PersonId", CurrentRecord.PersonId.ToString()),
                             new XElement("RecordId", CurrentRecord.RecordId.ToString()),
                             new XElement("RecordName", CurrentRecord.RecordName));
            }

            MobilePlatform.SaveTextToFile(name, settings.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generate the XML for a request.
        /// </summary>
        /// <param name="clientRequest">The request.</param>
        /// <returns>The XML representation.</returns>
        internal string GenerateRequestXml(HealthVaultRequest clientRequest)
        {
            XElement request = XElement.Parse(@"<wc-request:request xmlns:wc-request=""urn:com.microsoft.wc.request"" />");

            XElement header = new XElement("header");
            {
                header.Add(new XElement("method", clientRequest.MethodName));
                header.Add(new XElement("method-version", clientRequest.MethodVersion));

                if (CurrentRecord != null)
                {
                    header.Add(new XElement("record-id", CurrentRecord.RecordId.ToString()));
                }

                if (!String.IsNullOrEmpty(AuthorizationSessionToken))
                {
                    XElement authSession = new XElement("auth-session");
                    authSession.Add(new XElement("auth-token", AuthorizationSessionToken));

                    if (CurrentRecord != null)
                    {
                        authSession.Add(new XElement("offline-person-info",
                                                     new XElement("offline-person-id", CurrentRecord.PersonId.ToString())));
                    }

                    header.Add(authSession);
                }
                else
                {
                    if (AppIdInstance == Guid.Empty)
                    {
                        header.Add(new XElement("app-id", MasterAppId.ToString()));
                    }
                    else
                    {
                        header.Add(new XElement("app-id", AppIdInstance.ToString()));
                    }
                }

                header.Add(new XElement("language", Language));
                header.Add(new XElement("country", Country));
                header.Add(new XElement("msg-time", clientRequest.MessageTime.ToUniversalTime().ToString("O")));
                header.Add(new XElement("msg-ttl", "1800"));
                header.Add(new XElement("version", MobilePlatform.PlatformAbbreviationAndVersion));
            }

            XElement info = new XElement("info");

            if (clientRequest.InfoSection != null)
            {
                info = clientRequest.InfoSection;
            }

            if (clientRequest.MethodName != "CreateAuthenticatedSessionToken")
            {
                // if we have an info section, we need to compute the hash of that and put it in the header.
                if (clientRequest.InfoSection != null)
                {
                    string infoString = GetOuterXml(info);
                    header.Add(new XElement("info-hash",
                                            MobilePlatform.ComputeSha256HashAndWrap(infoString)));
                }

                if (!String.IsNullOrEmpty(SessionSharedSecret))
                {
                    byte[] sharedSecretKey = Convert.FromBase64String(SessionSharedSecret);
                    string headerXml       = GetOuterXml(header);

                    request.Add(new XElement("auth",
                                             MobilePlatform.ComputeSha256HmacAndWrap(sharedSecretKey, headerXml)));
                }
            }

            request.Add(header);
            request.Add(info);

            string requestString = GetOuterXml(request);

            return(requestString);
        }