Example #1
0
        public void Run()
        {
            this.hDB = new MySqlConnection("Server=" + BlindNetConst.DatabaseIP + ";Database=BlindChat;Uid=root;Pwd=kit2020;");
            this.hDB.Open();

            recvSock = GetChatRecvSocket();
            sendSock = GetChatSendSocket();

            IPEndPoint iep = (IPEndPoint)(recvSock.socket.RemoteEndPoint);

            logger = new Logger(UserID, iep.Address.ToString(), LogService.Chat);


            SetOnline((int)UserStat.Online);

            byte[] data;
            while (true)
            {
                data = recvSock.CryptoReceiveMsg();

                if (data == null)
                {
                    recvSock.Close();
                    sendSock.Close();
                    SetOnline((int)UserStat.Offline);
                    global.ListBlindChat.Remove(this);
                    logger.Log(LogRank.INFO, "BlindChat Disconnected");
                    return;
                }

                ChatPacket chatPacket = BlindNetUtil.ByteToStruct <ChatPacket>(data);
                if (chatPacket.Type == ChatType.Time)
                {
                    ClientUpdateData(chatPacket);
                    logger.Log(LogRank.INFO, "Chat Data Synchronized");
                }
                else if (chatPacket.Type == ChatType.NewRoom)
                {
                    ExecuteNewRoom(chatPacket);
                    logger.Log(LogRank.INFO, "Created New Chat Room");
                }
                else if (chatPacket.Type == ChatType.Message)
                {
                    MessageToParticipants(chatPacket);
                }
                else if (chatPacket.Type == ChatType.RoomJoined)
                {
                    ExecuteInvitation(chatPacket);
                }
                else if (chatPacket.Type == ChatType.Exit)
                {
                    ExecuteExit(chatPacket);
                }
            }
        }
Example #2
0
        public void Run()
        {
            connection = new MySqlConnection("Server = " + BlindNetConst.DatabaseIP + "; Port = 3306; Database = document_center; Uid = root; Pwd = kit2020");
            mainSocket = new BlindServerScoket(BlindNetConst.ServerIP, BlindNetConst.OPENNERPORT);
            mainSocket.BindListen();
            while (true)
            {
                BlindSocket client = mainSocket.AcceptWithECDH();
                IPEndPoint  iep    = (IPEndPoint)(client.socket.RemoteEndPoint);
                Console.WriteLine("Accepted {0} : {1}", iep.Address, iep.Port);
                if (client == null)
                {
                    continue;
                }

                byte[] data = BlindNetUtil.ByteTrimEndNull(client.CryptoReceiveMsg());
                byte[] tmp  = new byte[4];
                Array.Copy(data, 0, tmp, 0, data.Length);
                string ext = GetExt(BitConverter.ToUInt32(tmp, 0));
                if (ext == null)
                {
                    client.CryptoSend(null, PacketType.Disconnect);
                    continue;
                }
                client.CryptoSend(Encoding.UTF8.GetBytes(ext), PacketType.Info);

                data = BlindNetUtil.ByteTrimEndNull(client.CryptoReceiveMsg());
                tmp  = new byte[4];
                Array.Copy(data, 0, tmp, 0, data.Length);
                int    encryptDate = BitConverter.ToInt32(tmp, 0);
                byte[] key, iv;
                if (!GetSpecifyKeyPair(out key, out iv, encryptDate))
                {
                    client.CryptoSend(null, PacketType.Disconnect);
                    continue;
                }
                client.CryptoSend(key, PacketType.Info);
                client.CryptoSend(iv, PacketType.Info);

                byte[] latestKey, latestIv;
                if (!GetLatestKeyPair(out latestKey, out latestIv))
                {
                    client.CryptoSend(null, PacketType.Disconnect);
                    continue;
                }
                client.CryptoSend(latestKey, PacketType.Info);
                client.CryptoSend(latestIv, PacketType.Info);

                client.Close();
            }
        }
Example #3
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            VPNClass = new VPN_Class();
            //클라이언트 cid 서버로부터 받아오기
            //ClientID = "test1";
            string SendMsg = ClientID + "," + isInner;                             //아이디 + 내부 외부 보내서 외부면 vpn로그남김 (isInner bool형. 디버그했을때 실질적인 값 : true -> "True" | false -> "False")

            byte[] SendStringToByteGender = Encoding.UTF8.GetBytes(SendMsg);       // String -> bytes 변환
            mainSocket.CryptoSend(SendStringToByteGender, PacketType.Response);    //서버로 클라이언트 id 보냄
            blindClientCidPacket = mainSocket.CryptoReceive();                     // 서버로부터 cid받아옴
            byte[] data = BlindNetUtil.ByteTrimEndNull(blindClientCidPacket.data); // 넑값 지움
            byte[] tmp  = new byte[4];
            Array.Copy(data, 0, tmp, 0, data.Length);
            uint ClintCID = BitConverter.ToUInt32(tmp, 0);

            if (ClintCID == 0) //서버에서 아이디를 조회못했을때 0반환
            {
                MessageBox.Show("서버로부터 id를 받지 못하였거나 등록되지 않은 아이디입니다." + Environment.NewLine + "\t           관리자에게 문의하십시요.");
                mainSocket.Close();
                Application.Exit();
                return;
            }

            //각 기능 객체 및 Task 생성
            TaskScheduler scheduler = TaskScheduler.Default;

            token = new CancellationTokenSource();

            documentCenter = new Doc_Center(document_Center, isInner);
            documentCenter.Run();
            document_Center.docCenter = documentCenter;

            _ChatMain      = new ChatMain(ClintCID);
            _ChatMain.Dock = DockStyle.Fill;
            MainControlPanel.Controls.Add(_ChatMain);

            //Func
            chat  = new BlindChat(ClintCID, ref _ChatMain, this);
            tChat = Task.Factory.StartNew(() => chat.Run(), token.Token, TaskCreationOptions.LongRunning, scheduler);

            //ScreenLocking
            lockForm = new LockForm(isInner, ClientID);
            lockForm.connect();
            MessageBox.Show("락 연결!");

            deviceDriver  = new DeviceDriverHelper();
            tDeviceDriver = Task.Factory.StartNew(() => deviceDriver.Run(), token.Token, TaskCreationOptions.LongRunning, scheduler);
        }
Example #4
0
        static async void AddConnectedUser(BlindSocket socket)
        {
            if (socket == null)
            {
                return;
            }
            IPEndPoint iep = (IPEndPoint)(socket.socket.RemoteEndPoint);

            //로그인 인증
            uint cid;

            byte[] ClientReceiveMsg = socket.CryptoReceiveMsg();                 // 아이디,isinner 받음. (bool형. 디버그했을때 실질적인 값 : true -> "True" | false -> "False")
            string ClientGenderMsg  = Encoding.UTF8.GetString(ClientReceiveMsg); // 바이트 -> 스트링

            if (Encoding.UTF8.GetString(ClientReceiveMsg) != "\0")
            {
                cid = GetClientID(ClientGenderMsg.Split(',')[0].ToString()); //[0] -> dkdlel
            }
            else
            {
                cid = 0;
            }

            logger = new Logger(cid, iep.Address.ToString(), LogService.Login);
            if (cid != 0)
            {
                logger.Log(LogRank.INFO, "[Login Success] " + "Login ID : \"" + ClientGenderMsg.Split(',')[0].ToString() + "\" " +
                           "VPN Whether: \"" + (ClientGenderMsg.Split(',')[1].ToString() == "True" ? "True" : "False") + "\"");
            }
            else
            {
                logger.Log(LogRank.WARN, "[Login Fail] " + "Login ID : \"" + ClientGenderMsg.Split(',')[0].ToString() + "\" " +
                           "VPN Whether: \"" + (ClientGenderMsg.Split(',')[1].ToString() == "True" ? "True" : "False") + "\"");
            }

            socket.CryptoSend(BitConverter.GetBytes(cid), PacketType.Response);//cid 보냄

            if (cid == 0)
            {
                socket.Close();
                return;
            }
            uint[] gids = GetGids(cid);


            Console.WriteLine("Accepted {0} : {1}" + $"({cid})", iep.Address, iep.Port);

            //Client 구조체 초기화 및 추가
            TaskScheduler scheduler = TaskScheduler.Default;
            BlindClient   client    = new BlindClient();

            client.socket = socket;
            client.token  = new CancellationTokenSource();

            client.documentCenter  = new Doc_Center(cid, gids);                                                                                                //기능 객체 생성
            client.tDocumentCenter = Task.Factory.StartNew(() => client.documentCenter.Run(), client.token.Token, TaskCreationOptions.LongRunning, scheduler); //기능 객체의 최초 함수 실행

            client.chat  = new BlindChat(cid);
            client.tChat = Task.Factory.StartNew(() => client.chat.Run(), client.token.Token, TaskCreationOptions.LongRunning, scheduler);

            client.blindLock  = new BlindLock(cid);
            client.tBlindLock = Task.Factory.StartNew(() => client.blindLock.Run(), client.token.Token, TaskCreationOptions.LongRunning, scheduler);

            client.blindWebDevice  = new BlindWebDevice(cid);
            client.tBlindWebDevice = Task.Factory.StartNew(() => client.blindWebDevice.Run(), client.token.Token, TaskCreationOptions.LongRunning, scheduler);

            Clients.Add(client);
        }
Example #5
0
        static void Main(string[] args)
        {
#if !DEBUG
            var handl = GetConsoleWindow();
            ShowWindow(handl, SW_HIDE);
#endif

            if (args.Length != 1)
            {
                MessageBox.Show("잘못된 접근입니다.", "오류");
                //return;
            }

            string   test = @"C:\Users\rgh48\Downloads\부서원 인적사항.blind";
            FileInfo file = new FileInfo(test);
            if (!file.Exists)
            {
                MessageBox.Show("파일이 존재하지 않습니다.", "파일 열기");
                return;
            }
            FileStream fs       = file.Open(FileMode.Open);
            byte[]     buffer   = new byte[fs.Length];
            Task <int> taskRead = fs.ReadAsync(buffer, 0, (int)file.Length);

            BlindSocket socket = new BlindSocket();
            Console.WriteLine("Start connecting.");
            //Task<bool> taskCon = socket.ConnectWithECDHAsync(BlindNetConst.ServerIP, BlindNetConst.OPENNERPORT);
            //taskCon.Wait();
            //if (!taskCon.Result)
            socket.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.OPENNERPORT);
            if (false)
            {
                MessageBox.Show("서버와 연결에 실패했습니다.", "파일 열기");
                return;
            }
            Console.WriteLine("Connected with server.");

            taskRead.Wait();
            if (taskRead.Result == 0)
            {
                MessageBox.Show("파일 읽기에 실패했습니다.", "파일 열기");
                return;
            }
            fs.Close();

            uint   id  = BitConverter.ToUInt32(buffer, 0);
            string ext = GetSpecifyExt(id, socket);
            if (ext == null)
            {
                return;
            }

            Cryptography.AES256 aes256;
            if (!GetAES(ref buffer, socket, out aes256))
            {
                return;
            }

            Console.WriteLine("Start decrypted");
            byte[] decrypted = aes256.Decryption(buffer);
            Console.WriteLine("Decrypted");

            string tempFilePath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(args[0]) + ext;
            MakeTempFile(tempFilePath, decrypted);
            Console.WriteLine("File maked");

            Process procFile = Process.Start(tempFilePath);

            Cryptography.AES256 latestAes;
            if (!GetLatestAES(socket, out latestAes))
            {
                MessageBox.Show("최신 키 받아오기를 실패했습니다.");
                return;
            }
            socket.Close();

            procFile.WaitForExit();
            Console.WriteLine("Canceled");

            FileInfo   decFile = new FileInfo(tempFilePath);
            FileStream decFs   = decFile.OpenRead();
            buffer = new byte[decFile.Length];
            decFs.Read(buffer, 0, (int)decFile.Length);
            decFs.Close();

            buffer = AddDataToFile(id, latestAes.Encryption(buffer));

            FileStream encFs = file.Open(FileMode.Open);
            encFs.Write(buffer, 0, buffer.Length);
            encFs.Close();
            decFile.Delete();
        }