Example #1
0
        public void ToHashesTest()
        {
            foreach (DataRow row in dictionaryTest.Rows)
            {
                HashString hashString = new HashString((string)row["Chave"]);

                Assert.AreEqual(((string)row["Chave"]).ToMD5(), hashString.GetHashString(HashStringType.MD5));
                Assert.AreEqual(((string)row["Chave"]).ToSHA1(), hashString.GetHashString(HashStringType.SHA1));
                Assert.AreEqual(((string)row["Chave"]).ToSHA256(), hashString.GetHashString(HashStringType.SHA256));
                Assert.AreEqual(((string)row["Chave"]).ToSHA384(), hashString.GetHashString(HashStringType.SHA384));
                Assert.AreEqual(((string)row["Chave"]).ToSHA512(), hashString.GetHashString(HashStringType.SHA512));
            }
        }
Example #2
0
        public void GetHashStringTest()
        {
            foreach (DataRow row in dictionaryTest.Rows)
            {
                HashString hashString = new HashString((string)row["Chave"]);

                Assert.AreEqual((string)row["MD5"], hashString.GetHashString(HashStringType.MD5));
                Assert.AreEqual((string)row["SHA1"], hashString.GetHashString(HashStringType.SHA1));
                Assert.AreEqual((string)row["SHA256"], hashString.GetHashString(HashStringType.SHA256));
                Assert.AreEqual((string)row["SHA384"], hashString.GetHashString(HashStringType.SHA384));
                Assert.AreEqual((string)row["SHA512"], hashString.GetHashString(HashStringType.SHA512));



                TestContext.WriteLine($"{(string)row["Chave"]} -> MD5: {(string)row["MD5"]},SHA1: {(string)row["SHA1"]},SHA256: {(string)row["SHA256"]},SHA384: {(string)row["SHA384"]},SHA512: {(string)row["SHA512"]}");
            }
        }
        static void find_superpeer()
        {
            Console.Write("Destination: ");
            string     dest_key        = Console.ReadLine();
            IPAddress  ipAddress       = IPAddress.Parse(local_ip);
            IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, local_port);

            //Connect to server
            TcpClient client = new TcpClient(ipLocalEndPoint);

            client.Connect(server_ip, server_port);
            SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);

            authenticate_server(sslStream);

            TCPCommunication.send_message_tcp(sslStream, "FIND_P");
            TCPCommunication.send_message_tcp(sslStream, HashString.GetHashString(pubKey.ToString()));

            string response = TCPCommunication.recieve_message_tcp(sslStream);

            if (String.Compare(response, "ACCEPT") == 0)
            {
                TCPCommunication.send_message_tcp(sslStream, dest_key);

                response = TCPCommunication.recieve_message_tcp(sslStream);

                string[] temp_split = response.Split(':');
                dest_ip   = temp_split[1];
                dest_port = Int32.Parse(temp_split[2]);

                Console.WriteLine($"destination peer in {dest_ip}:{dest_port}");

                //TCPCommunication.send_message_tcp(sslStream, pubKey.ToString());
                //response = TCPCommunication.recieve_message_tcp(sslStream);
                //Console.WriteLine(response);
                sslStream.Close();
                client.Close();

                client = new TcpClient(ipLocalEndPoint);
                Console.WriteLine("Client connecting");
                client.Connect(dest_ip, dest_port);
                Console.WriteLine("Client connected");
                sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
                authenticate_server(sslStream);

                req_connection(sslStream, client, dest_key);


                sslStream.Close();
                client.Close();
            }
            else if (String.Compare(response, "REJECT") == 0)
            {
                Console.WriteLine("Connection rejected");
                sslStream.Close();
                client.Close();
            }
        }
Example #4
0
        public UserDTO ChangeUser(UserDTO _user)
        {
            var user = _context.Users.FirstOrDefault(u => u.Id == _user.Id);

            if (user == null)
            {
                throw new Exception("Пользователь не найден");
            }
            user.Login      = _user.Login;
            user.Password   = HashString.GetHashString(_user.Password);
            user.FirstName  = _user.FirstName;
            user.SecondName = _user.SecondName;
            _context.SaveChanges();
            return(new UserDTO(user));
        }
Example #5
0
        public UserDTO GetUserAuthorize(string login, string password)
        {
            var user = _context.Users.FirstOrDefault(u => u.Login == login);

            if (user == null)
            {
                throw new Exception("Пользователь не найден. Неправильно введён логин или пароль!");
            }
            var temp = HashString.GetHashString(password);

            if (user.Password != temp)
            {
                throw new Exception("Неправильно введён логин или пароль!");
            }
            return(new UserDTO(user));
        }
Example #6
0
        public UserDTO AddUser(UserDTO _user)
        {
            var pass = HashString.GetHashString(_user.Password);
            var user = _context.Users.FirstOrDefault(u => u.Login.Equals(_user.Login) && u.Password.Equals(pass));

            if (user != null)
            {
                throw new Exception("Пользователь уже существует");
            }
            var nUser    = _user.MapToUser();
            var userStat = new Statistics(0, 0, 0, nUser.Id);

            _context.Users.Add(nUser);
            _context.Statistics.Add(userStat);
            _context.SaveChanges();
            return(new UserDTO(nUser));
        }
Example #7
0
        public User MapToUser()
        {
            var user = new User();

            user.Id = this.Id ?? Guid.NewGuid();
            if (string.IsNullOrEmpty(this.FirstName) || string.IsNullOrEmpty(this.SecondName) || string.IsNullOrEmpty(this.Login) || string.IsNullOrEmpty(this.Password))
            {
                throw new Exception("Внутреняя ошибка сервера");
            }
            user.FirstName  = this.FirstName;
            user.SecondName = this.SecondName;
            user.Login      = this.Login;
            user.Password   = HashString.GetHashString(this.Password);
            user.Space      = 262144000;
            user.VkId       = this.VkId;
            user.DiscUsage  = this.DiscUsage ?? 0;

            return(user);
        }
        static void anonym_peer()
        {
            IPAddress  ipAddress       = IPAddress.Parse(local_ip);
            IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, local_port);

            //Connect to server
            TcpClient client = new TcpClient(ipLocalEndPoint);

            client.Connect(server_ip, server_port);
            SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);

            authenticate_server(sslStream);

            TCPCommunication.send_message_tcp(sslStream, "ANONYM_P");
            TCPCommunication.send_message_tcp(sslStream, HashString.GetHashString(pubKey.ToString()));

            string response = TCPCommunication.recieve_message_tcp(sslStream);

            if (String.Compare(response, "ACCEPT") == 0)
            {
                node = new ECDiffieHellmanOpenSsl();
                ECParameters node_ep = node.ExportParameters(false);

                pubKey = new PublicKeyCoordinates(node_ep.Q.X, node_ep.Q.Y);
                string hash = HashString.GetHashString(pubKey.ToString());

                TCPCommunication.send_message_tcp(sslStream, hash);

                response = TCPCommunication.recieve_message_tcp(sslStream);

                Console.WriteLine(response);

                sslStream.Close();
                client.Close();
            }
            else if (String.Compare(response, "REJECT") == 0)
            {
                Console.WriteLine("Connection rejected");
                sslStream.Close();
                client.Close();
            }
        }
        static void init_connection(SslStream sslStream)
        {
            //Authenticate certificate
            authenticate_server(sslStream);

            TCPCommunication.send_message_tcp(sslStream, "INIT_P");
            string response = TCPCommunication.recieve_message_tcp(sslStream);

            Console.WriteLine(response);

            node = new ECDiffieHellmanOpenSsl();
            ECParameters node_ep = node.ExportParameters(false);

            pubKey = new PublicKeyCoordinates(node_ep.Q.X, node_ep.Q.Y);

            Console.WriteLine("My hash key: " + HashString.GetHashString(pubKey.ToString()));

            //Console.WriteLine(pubKey.ToString());

            TCPCommunication.send_message_tcp(sslStream, pubKey.ToString());
        }
Example #10
0
        protected override void Seed(SDContext db)
        {
            HashString hash = new HashString();

            db.Users.Add(new User {
                Id = Guid.NewGuid(), FirstName = "Масленников", SecondName = "Сергей", Login = "******", Password = HashString.GetHashString("123")
            });
            db.Users.Add(new User {
                Id = Guid.NewGuid(), FirstName = "Бальзамов", SecondName = "Александр", Login = "******", Password = HashString.GetHashString("123")
            });
            db.Statistics.Add(new Statistics(0, 0, 0, db.Users.Local.First(st => st.Login == "Sergey").Id));
            db.Statistics.Add(new Statistics(0, 0, 0, db.Users.Local.First(st => st.Login == "Alex").Id));
            base.Seed(db);
        }
        static void listen_connection(SslStream sslStream, TcpClient client)
        {
            myAes     = Aes.Create();
            myAes.Key = new byte[16] {
                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
            };
            myAes.IV = new byte[16] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };


            TCPCommunication.send_message_tcp(sslStream, "LISTEN_P");
            TCPCommunication.send_message_tcp(sslStream, HashString.GetHashString(pubKey.ToString()));

            string response = TCPCommunication.recieve_message_tcp(sslStream);

            if (String.Compare(response, "ACCEPT") == 0)
            {
                byte[] data = new Byte[256];
                data = Encoding.UTF8.GetBytes(pubKey.ToString());
                sslStream.Write(data);
                sslStream.Flush();


                data = new Byte[256];
                sslStream.Read(data, 0, data.Length);
                response = Encoding.UTF8.GetString(data);
                PublicKeyCoordinates request_key = JsonConvert.DeserializeObject <PublicKeyCoordinates>(response);

                sslStream.Close();
                client.Close();

                ECDiffieHellmanOpenSsl temp   = new ECDiffieHellmanOpenSsl();
                ECParameters           epTemp = temp.ExportParameters(false);

                epTemp.Q.X = request_key.X;
                epTemp.Q.Y = request_key.Y;

                ECDiffieHellmanPublicKey servePubKey = ECDiffieHellman.Create(epTemp).PublicKey;
                byte[] sharedKey = node.DeriveKeyMaterial(servePubKey);
                Console.WriteLine(BitConverter.ToString(sharedKey).Replace("-", ""));

                //myAes.Key = sharedKey;
                //myAes.Key = new byte[16] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };


                DTLSClient dtls_client = new DTLSClient(server_ip, server_port.ToString(), new byte[] { 0xBA, 0xA0 });

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    dtls_client.Unbuffer      = "winpty.exe";
                    dtls_client.Unbuffer_Args = "-Xplain -Xallow-non-tty";
                }
                else
                {
                    dtls_client.Unbuffer      = "stdbuf";
                    dtls_client.Unbuffer_Args = "-i0 -o0";
                }
                dtls_client.Start();

                /* statpair IOStream = new statpair(new StreamReader(Console.OpenStandardInput()), new StreamWriter(Console.OpenStandardOutput()));
                 * new Thread(() => dtls_client.GetStream().CopyTo(IOStream, 16)).Start();*/

                read_relay(dtls_client);

                /*while(true)
                 * {
                 *  string input = Console.ReadLine();
                 *  byte[] encryptedData = EncryptStringToBytes_Aes(input, myAes.Key, myAes.IV);
                 *  dtls_client.GetStream().Write(encryptedData);
                 *  //dtls_client.GetStream().Write(Encoding.Default.GetBytes(input+Environment.NewLine));
                 * }*/

                dtls_client.WaitForExit();
            }
            else if (String.Compare(response, "REJECT") == 0)
            {
                Console.WriteLine("Connection rejected");
                sslStream.Close();
                client.Close();
            }
        }
        static void req_connection(SslStream sslStream, TcpClient client, string dest_key)
        {
            myAes     = Aes.Create();
            myAes.Key = new byte[16] {
                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
            };
            myAes.IV = new byte[16] {
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            };

            TCPCommunication.send_message_tcp(sslStream, "CONNECT_P");
            TCPCommunication.send_message_tcp(sslStream, HashString.GetHashString(pubKey.ToString()));

            string response = TCPCommunication.recieve_message_tcp(sslStream);

            if (String.Compare(response, "ACCEPT") == 0)
            {
                TCPCommunication.send_message_tcp(sslStream, dest_key);

                response = TCPCommunication.recieve_message_tcp(sslStream);
                Console.WriteLine(response);

                if (String.Compare(response, "ACCEPT") == 0)
                {
                    response = TCPCommunication.recieve_message_tcp(sslStream);
                    int dtls_port = Int32.Parse(response);


                    byte[] data = new Byte[256];
                    data = Encoding.UTF8.GetBytes(pubKey.ToString());

                    sslStream.Write(data);
                    sslStream.Flush();

                    data = new Byte[256];
                    sslStream.Read(data, 0, data.Length);
                    response = Encoding.UTF8.GetString(data);
                    PublicKeyCoordinates listen_key = JsonConvert.DeserializeObject <PublicKeyCoordinates>(response);



                    sslStream.Close();
                    client.Close();

                    ECDiffieHellmanOpenSsl temp   = new ECDiffieHellmanOpenSsl();
                    ECParameters           epTemp = temp.ExportParameters(false);

                    epTemp.Q.X = listen_key.X;
                    epTemp.Q.Y = listen_key.Y;

                    ECDiffieHellmanPublicKey servePubKey = ECDiffieHellman.Create(epTemp).PublicKey;
                    byte[] sharedKey = node.DeriveKeyMaterial(servePubKey);
                    Console.WriteLine(BitConverter.ToString(sharedKey).Replace("-", ""));
                    //myAes.Key = sharedKey;
                    //myAes.Key = new byte[16] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };

                    DTLSClient dtls_client = new DTLSClient(server_ip, dtls_port.ToString(), new byte[] { 0xBA, 0xA0 });

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        dtls_client.Unbuffer      = "winpty.exe";
                        dtls_client.Unbuffer_Args = "-Xplain -Xallow-non-tty";
                    }
                    else
                    {
                        dtls_client.Unbuffer      = "stdbuf";
                        dtls_client.Unbuffer_Args = "-i0 -o0";
                    }
                    dtls_client.Start();

                    /*statpair IOStream = new statpair(new StreamReader(Console.OpenStandardInput()), new StreamWriter(Console.OpenStandardOutput()));
                     * new Thread(() => dtls_client.GetStream().CopyTo(IOStream, 16)).Start();*/

                    //new Thread(() => read_relay(dtls_client)).Start();

                    UdpClient receivingUdpClient = new UdpClient(32000);

                    //Creates an IPEndPoint to record the IP Address and port number of the sender.
                    // The IPEndPoint will allow you to read datagrams sent from any source.
                    IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

                    /*Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                     *
                     * IPAddress broadcast = IPAddress.Parse("127.0.0.1");
                     *
                     * //byte[] sendbuf = Encoding.ASCII.GetBytes(args[0]);
                     * IPEndPoint ep = new IPEndPoint(broadcast, 11000);*/

                    dtls_client.GetStream().Write(Encoding.Default.GetBytes("SUCCESS\n"));
                    dtls_client.GetStream().Write(Encoding.Default.GetBytes("SUCCESS\n"));
                    //dtls_client.GetStream().Write(Encoding.Default.GetBytes("SUCCESS"));

                    while (true)
                    {
                        byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
                        //dtls_client.GetStream().Write(receiveBytes);
                        //dtls_client.GetStream().Flush();

                        string input = BitConverter.ToString(receiveBytes) + '\n';
                        //Console.WriteLine(input);

                        byte[] send = Encoding.Default.GetBytes(input);

                        //Console.WriteLine(receiveBytes);
                        dtls_client.GetStream().Write(send);
                        //Thread.Sleep(50);



                        //byte[] rec = Encoding.Default.GetBytes(cut_str);
                        //Console.WriteLine(bytes);

                        //s.SendTo(bytes, ep);

                        //dtls_client.GetStream().Write(Encoding.Default.GetBytes(input));

                        /*string input = Encoding.Default.GetString(receiveBytes);
                         *
                         * byte[] send = Encoding.Default.GetBytes(input);
                         *
                         * s.SendTo(send, ep);*/

                        /*byte[] out_byte = Encoding.Default.GetBytes(input);
                         *
                         * string out_str = Encoding.Default.GetString(out_byte);
                         *
                         * String[] arr=out_str.Split('-');
                         * byte[] bytes=new byte[arr.Length];
                         * for(int i=0; i<arr.Length; i++) bytes[i]=Convert.ToByte(arr[i],16);
                         *
                         * s.SendTo(bytes, ep);*/

                        /*String[] arr=input.Split('-');
                         * byte[] bytes=new byte[arr.Length];
                         * for(int i=0; i<arr.Length; i++) bytes[i]=Convert.ToByte(arr[i],16);*/

                        /*String[] arr_in=input.Split('-');
                         * byte[] array_in=new byte[arr.Length];
                         * for(int i=0; i<arr.Length; i++) array[i]=Convert.ToByte(arr[i],16);
                         *
                         * string out_str = BitConverter.ToString(out_bt);
                         *
                         * String[] arr=out_str.Split('-');
                         * byte[] bytes=new byte[arr.Length];
                         * for(int i=0; i<arr.Length; i++) bytes[i]=Convert.ToByte(arr[i],16);
                         *
                         * //byte[] bytes = BitConverter.GetBytes(input);
                         *
                         * s.SendTo(bytes, ep);*/


                        //string input = BitConverter.ToString(receiveBytes);

                        //byte[] encryptedData = EncryptStringToBytes_Aes(BitConverter.ToString(receiveBytes), myAes.Key, myAes.IV);

                        //dtls_client.GetStream().Write(encryptedData);

                        //dtls_client.GetStream().Write(receiveBytes);
                        //dtls_client.GetStream().Write(bytes);
                        //dtls_client.GetStream().Write();
                    }

                    dtls_client.WaitForExit();
                }
                else if (String.Compare(response, "REJECT") == 0)
                {
                    Console.WriteLine("Connection rejected");
                }
            }
            else if (String.Compare(response, "REJECT") == 0)
            {
                Console.WriteLine("Connection rejected");
                sslStream.Close();
                client.Close();
            }
        }
        static void listen_connection(SslStream sslStream, TcpClient client)
        {
            /*myAes = Aes.Create();
             * myAes.Key = new byte[16] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
             * myAes.IV = new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
             */

            TCPCommunication.send_message_tcp(sslStream, "LISTEN_P");
            TCPCommunication.send_message_tcp(sslStream, HashString.GetHashString(pubKey.ToString()));

            string response = TCPCommunication.recieve_message_tcp(sslStream);

            if (String.Compare(response, "ACCEPT") == 0)
            {
                Console.WriteLine("Start authenticating");
                Byte[] data = new Byte[2048];
                sslStream.Read(data, 0, data.Length);
                string             message = Encoding.UTF8.GetString(data);
                string             P_str   = message;
                RsaKeyParameters[] P       = restructure_P(P_str);

                Console.WriteLine("P: " + P_str);
                Console.WriteLine();

                data = new Byte[2048];
                sslStream.Read(data, 0, data.Length);

                message = Encoding.UTF8.GetString(data);
                string   X_str = message;
                byte[][] X     = restructure_X(X_str);

                Console.WriteLine("X: " + X_str);
                Console.WriteLine();

                response = TCPCommunication.recieve_message_tcp(sslStream);
                string m = response;
                Console.WriteLine("m: " + m);
                Console.WriteLine();


                data = new Byte[64];
                sslStream.Read(data, 0, data.Length);
                byte[] v = data;
                Console.WriteLine("v: " + ByteArrayToString(v));
                Console.WriteLine();

                if (ring_verify(P, v, X, m))
                {
                    Console.WriteLine("Authentication success");
                }
                else
                {
                    Console.WriteLine("Authentication failure");
                }


                /*byte[] data = new Byte[256];
                 * data = Encoding.UTF8.GetBytes(pubKey.ToString());
                 * sslStream.Write(data);
                 * sslStream.Flush();*/


                /*data = new Byte[256];
                 * sslStream.Read(data, 0, data.Length);
                 * response = Encoding.UTF8.GetString(data);
                 * PublicKeyCoordinates request_key = JsonConvert.DeserializeObject<PublicKeyCoordinates>(response);
                 *
                 * sslStream.Close();
                 * client.Close();
                 *
                 *
                 *
                 * ECDiffieHellmanOpenSsl temp = new ECDiffieHellmanOpenSsl();
                 * ECParameters epTemp = temp.ExportParameters(false);
                 *
                 * epTemp.Q.X = request_key.X;
                 * epTemp.Q.Y = request_key.Y;
                 *
                 * ECDiffieHellmanPublicKey servePubKey = ECDiffieHellman.Create(epTemp).PublicKey;
                 * byte[] sharedKey = node.DeriveKeyMaterial(servePubKey);
                 * Console.WriteLine(BitConverter.ToString(sharedKey).Replace("-", ""));
                 *
                 * //myAes.Key = sharedKey;
                 * //myAes.Key = new byte[16] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
                 *
                 *
                 * DTLSClient dtls = new DTLSClient(server_ip, server_port.ToString(), new byte[] { 0xBA, 0xA0 });
                 *
                 * if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                 * {
                 *  dtls.Unbuffer = "winpty.exe";
                 *  dtls.Unbuffer_Args = "-Xplain -Xallow-non-tty";
                 * }
                 * else
                 * {
                 *  dtls.Unbuffer = "stdbuf";
                 *  dtls.Unbuffer_Args = "-i0 -o0";
                 * }
                 * dtls.Start();
                 *
                 * byte[] bytes;
                 *
                 * new Thread(() => read_relay(dtls)).Start();
                 *
                 * while (true)
                 * {
                 *  string input = Console.ReadLine();
                 *  byte[] encryptedData = EncryptStringToBytes_Aes(input, myAes.Key, myAes.IV);
                 *  //dtls.GetStream().Write(Encoding.Default.GetBytes(input+Environment.NewLine));
                 *  dtls.GetStream().Write(encryptedData);
                 * }
                 * dtls.WaitForExit();*/
            }
            else if (String.Compare(response, "REJECT") == 0)
            {
                Console.WriteLine("Connection rejected");
                sslStream.Close();
                client.Close();
            }
        }
        static void req_connection(SslStream sslStream, TcpClient client, string dest_key)
        {
            /*myAes = Aes.Create();
             * myAes.Key = new byte[16] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
             * myAes.IV = new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
             */

            Console.WriteLine("requesting");
            TCPCommunication.send_message_tcp(sslStream, "CONNECT_P");
            TCPCommunication.send_message_tcp(sslStream, HashString.GetHashString(pubKey.ToString()));

            string response = TCPCommunication.recieve_message_tcp(sslStream);

            if (String.Compare(response, "ACCEPT") == 0)
            {
                TCPCommunication.send_message_tcp(sslStream, dest_key);

                response = TCPCommunication.recieve_message_tcp(sslStream);
                Console.WriteLine(response);

                if (String.Compare(response, "ACCEPT") == 0)
                {
                    Console.WriteLine("Start Authenticating");
                    ring_authenticate(sslStream);


                    /*response = TCPCommunication.recieve_message_tcp(sslStream);
                     * int dtls_port = Int32.Parse(response);
                     *
                     *
                     * byte[] data = new Byte[256];
                     * data = Encoding.UTF8.GetBytes(pubKey.ToString());
                     *
                     * sslStream.Write(data);
                     * sslStream.Flush();
                     *
                     * data = new Byte[256];
                     * sslStream.Read(data, 0, data.Length);
                     * response = Encoding.UTF8.GetString(data);
                     * PublicKeyCoordinates listen_key = JsonConvert.DeserializeObject<PublicKeyCoordinates>(response);
                     *
                     *
                     *
                     * sslStream.Close();
                     * client.Close();*/

                    /*ECDiffieHellmanOpenSsl temp = new ECDiffieHellmanOpenSsl();
                     * ECParameters epTemp = temp.ExportParameters(false);
                     *
                     * epTemp.Q.X = listen_key.X;
                     * epTemp.Q.Y = listen_key.Y;
                     *
                     * ECDiffieHellmanPublicKey servePubKey = ECDiffieHellman.Create(epTemp).PublicKey;
                     * byte[] sharedKey = node.DeriveKeyMaterial(servePubKey);
                     * Console.WriteLine(BitConverter.ToString(sharedKey).Replace("-", ""));
                     * //myAes.Key = sharedKey;
                     * //myAes.Key = new byte[16] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
                     *
                     * DTLSClient dtls = new DTLSClient(dest_ip, dtls_port.ToString(), new byte[] { 0xBA, 0xA0 });
                     *
                     * if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                     * {
                     *  dtls.Unbuffer = "winpty.exe";
                     *  dtls.Unbuffer_Args = "-Xplain -Xallow-non-tty";
                     * }
                     * else
                     * {
                     *  dtls.Unbuffer = "stdbuf";
                     *  dtls.Unbuffer_Args = "-i0 -o0";
                     * }
                     * dtls.Start();
                     *
                     * new Thread(() => read_relay(dtls)).Start();
                     *
                     * while (true)
                     * {
                     *  string input = Console.ReadLine();
                     *  byte[] encryptedData = EncryptStringToBytes_Aes(input, myAes.Key, myAes.IV);
                     *  //dtls.GetStream().Write(Encoding.Default.GetBytes(input+Environment.NewLine));
                     *  dtls.GetStream().Write(encryptedData);
                     * }
                     * dtls.WaitForExit();*/
                }

                else if (String.Compare(response, "REJECT") == 0)
                {
                    Console.WriteLine("Connection rejected");
                }
            }
            else if (String.Compare(response, "REJECT") == 0)
            {
                Console.WriteLine("Connection rejected");
                sslStream.Close();
                client.Close();
            }
        }