Beispiel #1
0
        public string GetRealScopeIDFromEasyID(string pEasyID, bool bNoLogging = false, bool bUseEasyScope16 = false)
        {
            Guid   tG = CU.CGuid(MySecrets?.GetAK());
            string tg = InsertCodeIntoGUID(pEasyID, tG, bNoLogging, bUseEasyScope16).ToString();

            return(CU.cdeEncrypt(CU.CGuid(tg.Substring(0, 11) + tG.ToString().Substring(11, "00-0000-0000-000000000000".Length)).ToByteArray(), MySecrets?.GetAI()));
        }
Beispiel #2
0
        public bool ParseISBPath(string pRealPage, out Guid?pSessionID, out cdeSenderType pType, out long pFID, out string pVersion)
        {
            pSessionID = null;
            pType      = cdeSenderType.NOTSET;
            pFID       = 0;
            pVersion   = "";
            var tRealPage = CU.cdeDecrypt(pRealPage, MySecrets?.GetAI(), true);

            if (tRealPage?.StartsWith(MySecrets?.GetApID5()) != true)
            {
                return(false);
            }

            string[] tQ = tRealPage.Split('&');

            pType = tQ.Length == 4 ? (cdeSenderType)(CU.CInt(tQ[2])) : cdeSenderType.NOTSET;
            if (tQ.Length > 1)
            {
                pFID = CU.CLng(tQ[1]);
            }
            if (tQ.Length > 3)
            {
                pSessionID = CU.CGuid(tQ[3]);
            }
            if (tQ[0].Length == 7)
            {
                pVersion = tQ[0].Substring(5);
            }
            return(true);
        }
        public bool ParseISBPath(string pRealPage, out Guid?pSessionID, out cdeSenderType pType, out long pFID, out string pVersion)
        {
            pSessionID = null;
            pType      = cdeSenderType.NOTSET;
            pFID       = 0;
            pVersion   = "";

            try
            {
                string[] tQ = Base64Decode(pRealPage).Split('_');

                pType = tQ.Length == 4 ? (cdeSenderType)(CU.CInt(tQ[2])) : cdeSenderType.NOTSET;
                if (tQ.Length > 1)
                {
                    pFID = CU.CLng(tQ[1]);
                }
                if (tQ.Length > 3)
                {
                    pSessionID = CU.CGuid(tQ[3]);
                }
                if (tQ[0].Length == 7)
                {
                    pVersion = tQ[0].Substring(5);
                }
            }
            catch (Exception)
            {
                // ignored
            }
            return(true);
        }
        /// <summary>
        /// NEW in V4: Returns the next node in GRO to optimize Route traffic
        /// </summary>
        /// <returns></returns>
        public Guid GetNextNode()
        {
            if (string.IsNullOrEmpty(GRO) || !GRO.Contains(TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID.ToString()))
            {
                return(Guid.Empty);
            }

            var tNodes = TheCommonUtils.cdeSplit(GRO, ';', false, false);

            if (tNodes.Length < 2)
            {
                return(Guid.Empty);
            }
            var tLastNode = tNodes[0].Split(':')[0];

            for (int i = 1; i < tNodes.Length; i++)
            {
                var tN = tNodes[i].Split(':')[0];
                if (tN == TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID.ToString())
                {
                    return(TheCommonUtils.CGuid(tLastNode));
                }
                tLastNode = tN;
            }
            return(Guid.Empty);
        }
Beispiel #5
0
        private static Guid GetCryptoGuid()
        {
            RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();

            byte[] data = new byte[16];
            crypto.GetBytes(data);
            return(CU.CGuid(data));
        }
        public Guid GenerateNewAppDeviceID(cdeSenderType tS)
        {
            string tg = Guid.NewGuid().ToString();
            string t  = tg.Substring(0, 35);

            t += ((int)tS).ToString();
            return(CU.CGuid(t));
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new DeviceID/NodeID for the current Application Scope
        /// </summary>
        /// <param name="tS">Sender Type of the Node</param>
        /// <returns></returns>
        public Guid GenerateNewAppDeviceID(cdeSenderType tS)
        {
            string tg = GetCryptoGuid().ToString();
            //return new Guid(tg.Substring(0, 11) + ((int)tS).ToString() + (new Guid(TheBaseAssets.cdeAK)).ToString().Substring(12, "0-0000-0000-000000000000".Length));
            string t = tg.Substring(0, 29);

            t += ((int)tS).ToString();
            t += (CU.CGuid(MySecrets?.GetAK())).ToString().Substring(29, 6);
            return(CU.CGuid(t));
        }
        private static Guid InsertCodeIntoGUID(string pCode, Guid pGuid, bool useEasyScope16)
        {
            string tg    = MD5(pCode, useEasyScope16);
            string tguid = pGuid.ToString().Replace("{", "").Replace("}", "").Replace("-", "");

            if (tg.Length > tguid.Length)
            {
                return(CU.CGuid(tg.Substring(0, tguid.Length)));
            }
            return(CU.CGuid(tg + tguid.Substring(0, tguid.Length - tg.Length)));
        }
        /// <summary>
        /// Return a Scrambled ScopeID from an easy scopeID
        /// </summary>
        /// <param name="pEasyScope">Source EasyScope</param>
        /// <param name="bNoLogging">If true, errors will not be logged</param>
        /// <param name="bUseEasyScope16">if true, the EasyScopeID can have up to 16 characters. Attention: this might not be compatible to existing mesh setups as all nodes in a mesh need to understand 16chars ScopeIDs</param>
        /// <returns></returns>
        public string GetScrambledScopeIDFromEasyID(string pEasyScope, bool bNoLogging, bool bUseEasyScope16)
        {
            if (string.IsNullOrEmpty(pEasyScope))
            {
                return(null);                                   //NEW 10/20/2012
            }
            Guid tG = CU.CGuid(TheBaseAssets.MySecrets.GetAK());

            MyServiceHostInfo?.MyKPIs?.IncrementKPI(eKPINames.KPI4);
            return(Base64Encode($"{CU.GetRandomUInt(0, 1000)}&{InsertCodeIntoGUID(pEasyScope, tG, bUseEasyScope16)}"));
        }
Beispiel #10
0
        /// <summary>
        /// Return a Scrambled ScopeID from an easy scopeID
        /// </summary>
        /// <param name="pEasyScope">Source EasyScope</param>
        /// <param name="bNoLogging">If true, errors will not be logged</param>
        /// <param name="bUseEasyScope16">if true, the EasyScopeID can have up to 16 characters. Attention: this might not be compatible to existing mesh setups as all nodes in a mesh need to understand 16chars ScopeIDs</param>
        /// <returns></returns>
        public string GetScrambledScopeIDFromEasyID(string pEasyScope, bool bNoLogging, bool bUseEasyScope16)
        {
            if (string.IsNullOrEmpty(pEasyScope))
            {
                return(null);                                   //NEW 10/20/2012
            }
            Guid   tG = CU.CGuid(MySecrets?.GetAK());
            string tg = InsertCodeIntoGUID(pEasyScope, tG, bNoLogging, bUseEasyScope16).ToString();

            MyServiceHostInfo?.MyKPIs?.IncrementKPI(eKPINames.KPI4);
            return(CU.cdeEncrypt(CU.GetRandomUInt(0, 1000) + "&" + CU.cdeEncrypt(CU.CGuid(tg.Substring(0, 11) + tG.ToString().Substring(11, "00-0000-0000-000000000000".Length)).ToByteArray(), MySecrets?.GetAI()), MySecrets?.GetAI()));
        }
Beispiel #11
0
        private Guid InsertCodeIntoGUID(string pCode, Guid pGuid, bool bNoLogging, bool useEasyScope16)
        {
            long calc = 0;

            if (pCode.Length < 8)
            {
                pCode += "00000000".Substring(0, 8 - pCode.Length);
            }
            else
            {
                if (!bNoLogging && pCode.Length > 8 && MyServiceHostInfo?.UseEasyScope16 != true)
                {
                    MyServiceHostInfo?.MySYSLOG?.WriteToLog(MyServiceHostInfo?.IsCloudService == true ? eDEBUG_LEVELS.VERBOSE : eDEBUG_LEVELS.OFF, 2353, "TheScopeManager", "EasyID was longer than 8 characters: extra characters were ignored.", eMsgLevel.l2_Warning);
                }
            }
            var pCodeUpper      = pCode.ToUpper();
            var pCodeNormalized = pCodeUpper.Replace('O', '0').Replace('U', 'V').Replace('I', 'J').Replace('L', 'J');

            if (!bNoLogging && !string.Equals(pCodeNormalized, pCodeUpper, StringComparison.Ordinal))
            {
                //Do not log in cloud! This can fill the log if too many scopeIDs are using these chars (which is not a problem in the cloud)
                MyServiceHostInfo?.MySYSLOG?.WriteToLog(MyServiceHostInfo?.IsCloudService == true ? eDEBUG_LEVELS.VERBOSE : eDEBUG_LEVELS.OFF, 2354, "TheScopeManager", "EasyID contained reserved characters (O, V, I or L) that were normalized to (0, U, or J).", eMsgLevel.l2_Warning);
            }
            char[] tAr = pCodeNormalized.ToCharArray();
            for (int i = 0; i < 8; i++)
            {
                long tt = MySecrets.GetCodeArray().IndexOf(tAr[i]);
                calc <<= 5;
                calc  += tt;
            }
            string tg = string.Format("{0:x10}", calc);

            if (useEasyScope16) //Use16 digits ScopeID with new ApplicationID insert
            {
                for (int i = 8; i < pCode.Length; i++)
                {
                    long tt = MySecrets.GetCodeArray().IndexOf(tAr[i]);
                    calc <<= 5;
                    calc  += tt;
                }
                tg  = string.Format("{0:x16}", calc);
                tg  = tg.Substring(0, 8) + "-" + tg.Substring(8, 4) + "-" + tg.Substring(12, 4);
                tg += pGuid.ToString().Substring(18, "-0000-000000000000".Length);
            }
            else
            {
                tg  = tg.Substring(0, 8) + "-" + tg.Substring(8, 2);
                tg += pGuid.ToString().Substring(11, "00-0000-0000-000000000000".Length);
            }
            return(CU.CGuid(tg));
        }
Beispiel #12
0
        /// <summary>
        /// Returns the cdeSenderType of a given NodeID
        /// </summary>
        /// <param name="pNodeID">Source NodeID</param>
        /// <returns></returns>
        public cdeSenderType GetSenderTypeFromDeviceID(Guid pNodeID)
        {
            cdeSenderType tRes = cdeSenderType.NOTSET;
            string        tN   = pNodeID.ToString();

            if (string.IsNullOrEmpty(AKEnd))
            {
                AKEnd = CU.CGuid(MySecrets?.GetAK()).ToString().Substring(29, 6);
            }
            if (tN.EndsWith(AKEnd))
            {
                tRes = (cdeSenderType)CU.CInt(tN.Substring(29, 1));
            }
            return(tRes);
        }
        /// <summary>
        /// This function will return the first NodeID in the TSM that matches a Relay. Browsers do not have trust but the first-node a browser is conencted to is the browsers security proxy
        /// The function will return the Originator if no proxy was found
        /// </summary>
        /// <returns></returns>
        public Guid GetOriginatorSecurityProxy()
        {
            if (string.IsNullOrEmpty(ORG))
            {
                return(Guid.Empty);
            }
            string[] t = ORG.Split(';');

            Guid relay = TheCommonUtils.CGuid(t[0].Split(':')[0]);

            if (t.Length > 2 && TheBaseAssets.MyScopeManager.GetSenderTypeFromDeviceID(relay) == cdeSenderType.CDE_JAVAJASON)
            {
                relay = TheCommonUtils.CGuid(t[1].Split(':')[0]);
            }
            return(relay);
        }
 /// <summary>
 /// Gets the initial Originating thing of the message (commonly used for replying to the originating thing)
 /// </summary>
 /// <returns></returns>
 public Guid GetOriginatorThing()   //SL SAFE
 {
     if (string.IsNullOrEmpty(ORG))
     {
         return(Guid.Empty);
     }
     string[] t = ORG.Split(';');
     if (t.Length > 0)
     {
         var urlParts = t[0].Split(':');
         if (urlParts.Length > 1)
         {
             return(TheCommonUtils.CGuid(urlParts[1]));
         }
     }
     return(Guid.Empty);
 }
        /// <summary>
        /// Gets the DeviceID of the last known Relay forwarding this message
        /// </summary>
        /// <returns></returns>
        public Guid GetLastRelay()
        {
            string[] t     = ORG.Split(';');
            Guid     relay = Guid.Empty;

            if (t.Length > 0)
            {
                var tLast = t[t.Length - 1].Split(':')[0];
                if (tLast.Equals(TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID.ToString()) && t.Length > 1)
                {
                    relay = TheCommonUtils.CGuid(t[t.Length - 2].Split(':')[0]);
                }
                else
                {
                    relay = TheCommonUtils.CGuid(tLast);
                }
            }
            return(relay);
        }
 public string GetRealScopeIDFromEasyID(string pEasyID, bool bNoLogging = false, bool bUseEasyScope16 = false)
 {
     return(InsertCodeIntoGUID(pEasyID, CU.CGuid(TheBaseAssets.MySecrets.GetAK()), bUseEasyScope16).ToString());
 }