Esempio n. 1
0
        public static byte[] CreateKey(int len, int Complexity)
        {
            Random       RND    = new Random();
            int          stairs = RND.Next() / ((Complexity + 4) / 4);
            int          doors  = RND.Next();
            int          Energy = RND.Next() * 3;
            string       output = "";
            OneKeyHasher HS     = new OneKeyHasher()
            {
                TheCharsetUsed = Encoding.ASCII, TheHashSize = 1
            };

            for (int y = 0; y < stairs || Energy <= 0; y++)
            {
                for (int x = 0; x < doors || Energy <= 0; x++, Energy--)
                {
                    byte[] ff = new byte[Complexity];
                    RND.NextBytes(ff);
                    output += (char)HS.Hash(ff)[0];
                }
            }

            HS.TheHashSize = len;
            return(HS.Hash(output));
        }
Esempio n. 2
0
        public BDSocket(string Password, EncryptionType Crypto, int BDv2Complexity = 10)
        {
            if (!Info.Moduls.Contains("Net/BDSocket.cs"))
            {
                Info.Moduls.Add("Net/BDSocket.cs");
            }

            CT      = Crypto;
            EnCoder = Encoding.ASCII;
            OneKeyHasher Hs = new OneKeyHasher()
            {
                TheCharsetUsed = Encoding.ASCII,
                TheHashSize    = 1024,
            };

            PassHash = Encoding.ASCII.GetString(Hs.Hash(Password));
            switch (CT)
            {
            case (EncryptionType.BDCryptoV1):
                BDCryptoV1 = new BDCrypto(PassHash);
                break;

            case (EncryptionType.BDCryptoV2):
                BDCryptoV2 = new BDCryptoV2(PassHash, BDv2Complexity);
                break;

            default:
                throw new ArgumentNullException("No Encryption type Speciffyed");
            }
            Soc          = AutoSocket.Tcp;
            DownStream   = new Queue <byte>();
            ReciveThread = new Thread(new ThreadStart(ReadThread));
        }
Esempio n. 3
0
        }//clean up

        public bool Connect(string host, int port)
        {
            Soc.Connect(host, port);
            string[] RPT = (Soc.RemoteEndPoint as IPEndPoint).Address.ToString().Split(new char[] { '.' });
            string[] LPT = (Soc.LocalEndPoint as IPEndPoint).Address.ToString().Split(new char[] { '.' });

            OneKeyHasher HS = new OneKeyHasher()
            {
                TheCharsetUsed = Encoding.ASCII, TheHashSize = 1024
            };
            BDCryptoV2 STM = new BDCryptoV2(Encoding.ASCII.GetString(HS.Hash($"{RPT[0]}.{LPT[3]}.{RPT[1]}.{LPT[2]}.{RPT[2]}.{LPT[1]}.{RPT[3]}.{LPT[0]}")), 2);

            Soc.Send(STM.Compute(Encoding.ASCII.GetBytes($"{BitConverter.GetBytes(PassHash.Length)}{PassHash}{(CT == EncryptionType.BDCryptoV1).ToString()}"), false));
            DateTime TMR = DateTime.Now;

            while (DateTime.Now - TMR < TimeSpan.FromSeconds(10) && Soc.Available < 0)
            {
                Thread.Sleep(10);                                                                       //wait for Return
            }
            if (Soc.Available < 1)
            {
                return(false);
            }
            Run = true;

            byte[] Return = new byte[1];
            Soc.Receive(Return);

            Return = STM.Compute(Return, true);

            TMR = DateTime.Now;
            while (DateTime.Now - TMR < TimeSpan.FromSeconds(10) && Soc.Available < 0)
            {
                Thread.Sleep(10);                                                                       //wait for Return
            }
            if (Soc.Available < 1)
            {
                return(false);
            }

            switch (Return[0])
            {
            case (157):
                ReciveThread.Start();
                return(true);

            case (168):
                Soc.Disconnect(true);    //Connection Reject via Crypto NOT accepted
                return(false);

            case (28):
                throw new Exception("IpBan");

            default:
                throw new ArgumentException("this is most likly not a BDServer");
            }
        }
Esempio n. 4
0
        public static byte[] CreateKey(int len)
        {
            byte[] KK  = new byte[len];
            Random RND = new Random();

            RND.NextBytes(KK);
            OneKeyHasher HS = new OneKeyHasher()
            {
                TheCharsetUsed = Encoding.ASCII, TheHashSize = len * 24
            };

            KK             = HS.Hash(KK);
            HS.TheHashSize = len;
            KK             = HS.Hash(KK);
            string K = Encoding.UTF8.GetString(KK);

            KK = null;//free mem
            for (int x = 0; x < len; x++)
            {
                K += RND.Next();
            }
            return(HS.Hash(K));
        }
Esempio n. 5
0
        public BDCrypto(string Password)
        {
            if (!Info.Moduls.Contains("Crypto/BDCrypto.cs"))
            {
                Info.Moduls.Add("Crypto/BDCrypto.cs");
            }

            OneKeyHasher Translator = new OneKeyHasher();

            Encryption = new Dictionary <byte, byte>();
            Decryption = new Dictionary <byte, byte>();

            byte[] TMPStore;

            using (SHA384Cng Seg2 = new SHA384Cng())
                using (HMACSHA384 Seg1 = new HMACSHA384(Encoding.UTF32.GetBytes(Password)))
                {
                    Seg1.Initialize();
                    Translator.TheHashSize    = 512;
                    Translator.TheCharsetUsed = Encoding.UTF8;
                    TMPStore = Translator.Hash(Password);

                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    TMPStore = Seg1.TransformFinalBlock(TMPStore, 0, TMPStore.Length);
                    TMPStore = Seg2.ComputeHash(TMPStore);
                }

            Translator.TheCharsetUsed = Encoding.Unicode;
            Translator.TheHashSize    = 255;
            TMPStore = Translator.Hash(TMPStore);

            int  pos = 0;
            byte tmp = 0;

            while (true)
            {
                if (!Encryption.ContainsValue(TMPStore[pos]) && !Decryption.ContainsKey(TMPStore[pos]))
                {
                    Encryption.Add(tmp, TMPStore[pos]);
                    Decryption.Add(TMPStore[pos], tmp);
                    if (tmp == 255)
                    {
                        break;
                    }
                    else
                    {
                        tmp++;
                    }
                }

                pos++;
                if (pos == TMPStore.Length)
                {
                    TMPStore = Translator.Hash(TMPStore);
                    pos      = 0;
                }
            }

            _Key   = new byte[256];
            Layers = 5;

            byte x = 0;

            while (true)
            {
                _Key[x] = Encryption[x];
                if (x == 255)
                {
                    break;
                }
                else
                {
                    x++;
                }
            }
        }
Esempio n. 6
0
        public BDSocket Accept()
        {
            try
            {
                Socket soc = Soc.Accept();
            }
            catch (SocketException e)
            {
                if (e.ErrorCode == 10035)
                {
                    return(null);
                }
                else
                {
                    throw e;
                }
            }

            byte[]   LIP     = new byte[4];
            string[] tmp_LIP = (Soc.RemoteEndPoint as IPEndPoint).Address.ToString().Split(new char[] { '.' });

            for (int x = 0; x < 4; x++)
            {
                LIP[x] = byte.Parse(tmp_LIP[x]);
            }
            OneKeyHasher HS = new OneKeyHasher()
            {
                TheCharsetUsed = Encoding.ASCII, TheHashSize = 1024
            };
            BDCryptoV2 CSTM = new BDCryptoV2(Encoding.ASCII.GetString(HS.Hash($"{EIP[0]}.{LIP[3]}.{EIP[1]}.{LIP[2]}.{EIP[2]}.{LIP[1]}.{EIP[3]}.{LIP[0]}")), 2);

            if (IPBANS.Contains((Soc.RemoteEndPoint as IPEndPoint).Address.ToString()))
            {
                Soc.Send(CSTM.Compute(new byte[] { 28 }, false));
                return(Accept());//try to get a new client that the Coder Gods Want
            }
            LIP     = null;
            tmp_LIP = null;
            byte[]   input = new byte[4];
            DateTime TMR   = DateTime.Now;

            while (DateTime.Now - TMR < TimeSpan.FromSeconds(10) && Soc.Available < 4)
            {
                Thread.Sleep(10);                                                                       //wait for Return
            }
            if (Soc.Available < 1)
            {
                throw new TimeoutException("Client Failed to send Auth Data");
            }

            Soc.Receive(input);
            input = new byte[BitConverter.ToInt32(CSTM.Compute(input, true), 0)];
            TMR   = DateTime.Now;
            while (DateTime.Now - TMR < TimeSpan.FromSeconds(10) && Soc.Available < input.Length)
            {
                Thread.Sleep(10);                                                                                  //wait for Return
            }
            if (Soc.Available < 1)
            {
                throw new TimeoutException("Client Failed to send Auth Data");
            }
            Soc.Receive(input);
            string pass = Encoding.ASCII.GetString(CSTM.Compute(input, true));

            input = new byte[Soc.Available];
            Soc.Receive(input);
            EncryptionType CT;

            if (!WhiteListing)
            {
                if (Encoding.Default.GetString(CSTM.Compute(input, true)) == "true")
                {
                    CT = EncryptionType.BDCryptoV1;
                }
                else
                {
                    CT = EncryptionType.BDCryptoV2;
                }
            }
            else
            {
                if (Encoding.Default.GetString(CSTM.Compute(input, true)) != CryptoType.ToString())
                {
                    Soc.Send(CSTM.Compute(new byte[] { 157 }, false));
                    return(Accept());//MORE FOR THE CODER GODS
                }
                else if (CryptoType)
                {
                    CT = EncryptionType.BDCryptoV1;
                }
                else
                {
                    CT = EncryptionType.BDCryptoV2;
                }
            }

            input = null;
            Soc.Send(CSTM.Compute(new byte[] { 157 }, false));

            return(CreateBDSocket(Soc, pass, CT));
        }