Inheritance: ISharedRegionModule
Beispiel #1
0
        public static bool ValidateRequest(Hashtable communicationData, Hashtable requestData, string gatewayURL)
        {
            m_log.Debug("[OMECONOMY]: ValidateRequest (cd, rd, " + gatewayURL + ")");
            foreach (DictionaryEntry cd in communicationData)
            {
                m_log.Debug("[OMECONOMY]:   cd[" + cd.Key.ToString() + "]=" + cd.Value.ToString());
            }
            foreach (DictionaryEntry rd in requestData)
            {
                m_log.Debug("[OMECONOMY]:   rd[" + rd.Key.ToString() + "]=" + rd.Value.ToString());
            }
            Hashtable requestDataHashing = (Hashtable)requestData.Clone();

            requestDataHashing.Remove("method");

            UUID   regionUUID     = UUID.Parse((string)communicationData["regionUUID"]);
            String nonce          = (string)communicationData["nonce"];
            string notificationID = (string)communicationData["notificationID"];

            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("method", "verifyNotification");
            d.Add("notificationID", notificationID);
            d.Add("regionUUID", regionUUID.ToString());
            d.Add("hashValue", hashParameters(requestDataHashing, nonce, regionUUID));
            Dictionary <string, string> response = DoRequest(gatewayURL, d);

            string status = response["status"];

            m_log.Debug("[OMECONOMY]:   -> " + status);

            if (status == "OK")
            {
                return(true);
            }

            // Sometimes the server just goes braindead on us and somehow loses the key
            // and keeps failing subsequent validate requests.
            // So we fetch a new one if the validate request fails.
            // Unfortunately replaying this validate request with the new key also fails.
            // But at least the next validate request seems to succeed.
            m_log.Warn("[OMECONOMY]: refetching secret");
            OMBaseModule.InitializeRegion(regionUUID);
            return(false);
        }
Beispiel #2
0
        public static String hashParameters(Hashtable parameters, string nonce, UUID regionUUID)
        {
            StringBuilder concat = new StringBuilder();

            //Ensure that the parameters are in the correct order
            SortedList <string, string> sortedParameters = new SortedList <string, string>();

            foreach (DictionaryEntry parameter in parameters)
            {
                sortedParameters.Add((string)parameter.Key, (string)parameter.Value);
            }

            foreach (KeyValuePair <string, string> de in sortedParameters)
            {
                concat.Append((string)de.Key + (string)de.Value);
            }

            String regionSecret = OMBaseModule.GetRegionSecret(regionUUID);
            String message      = concat.ToString() + nonce + regionSecret;

            SHA1 hashFunction = new SHA1Managed();

            byte[] hashValue = hashFunction.ComputeHash(Encoding.UTF8.GetBytes(message));

            string hashHex = "";

            foreach (byte b in hashValue)
            {
                hashHex += String.Format("{0:x2}", b);
            }

            #if DEBUG
            //m_log.Debug(String.Format("[OMECONOMY] SHA1({0}) = {1}", message, hashHex));
            #endif
            return(hashHex);
        }
        public static bool ValidateRequest(Hashtable communicationData, Hashtable requestData, string gatewayURL)
        {
            OMBaseModule omBase = new OMBaseModule();

            string hashValue = (string)(communicationData)["hashValue"];
            UUID regionUUID = UUID.Parse((string)(communicationData)["regionUUID"]);
            UInt32 nonce = UInt32.Parse((string)(communicationData)["nonce"]);
            string notificationID = (string)(communicationData)["notificationID"];

            Dictionary<string, string> d = new Dictionary<string, string>();
            d.Add("method", "verifyNotification");
            d.Add("notificationID", notificationID);
            d.Add("regionUUID", regionUUID.ToString());
            d.Add("hashValue", HashString(nonce++.ToString(), omBase.GetRegionSecret(regionUUID)));
            Dictionary<string, string> response = DoRequest(gatewayURL, d);
            string secret = (string)response["secret"];

            if (hashValue == HashParameters(requestData, secret))
            {
                return true;
            }
            else
            {
                return false;
            }
        }