public void Run() { BS = new BlindSocket(); BP = new BlindPacket(); BS.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.WebDevicePort); while (true) { try { BP = BS.CryptoReceive();// 아이디에 따른 장치제어 결과 받아옴 } catch { break; } BP.data = BlindNetUtil.ByteTrimEndNull(BP.data); string ReceiveByteToStringGender = Encoding.Default.GetString(BP.data);// 변환 바이트 -> string = default,GetString | string -> 바이트 = utf8,GetBytes //11 : USB,CAM 차단 | 10: USB만 차단 | 01: 웹캠만 차단 | 00 : 모두허용 DeviceToggle(ReceiveByteToStringGender); Thread.Sleep(1000); } }
private void MainForm_Load(object sender, EventArgs e) { this.FormClosed += MainForm_FormClosed; //폼 종료되는 것 연결 if (!BlindNetUtil.IsConnectedInternet()) { MessageBox.Show("There is no internet connection", "확인", MessageBoxButtons.OK); Close(); } bool result = mainSocket.ConnectWithECDH(); if (!result) { MessageBox.Show("Main socket connection failed.", "확인", MessageBoxButtons.OK); Close(); } //단축키&타이머 등록 BlindLockTimer.Enabled = true; RegisterHotKey(this.Handle, 0, KeyModifiers.Windows, Keys.L); RegisterHotKey(this.Handle, 1, KeyModifiers.Alt, Keys.L); ActivateControl(MainControl.Document); }
public void connect() { if (!isInner) { lockSock = new BlindSocket(); lockSock.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.LOCKPORT); MessageBox.Show("락 포트 연결!"); } }
static void Main(string[] args) { Console.WriteLine("Well Come to Console \r\n\r\n"); if (!BlindNetUtil.IsConnectedInternet()) { Console.WriteLine("There is no internet connection"); Environment.Exit(0); } bool result = MainSocket.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.WebInterlockPort); if (!result) { Console.WriteLine("Main socket connection failed."); Environment.Exit(0); } Console.WriteLine("Main Server Connection. (Server IP : " + BlindNetConst.ServerIP + ")\r\n"); while (true) { //받기 -> 명령문 실행 -> 결과(Result) 스트링 전송) MainPacket = MainSocket.CryptoReceive(); //타입 + 아이디 + 비번 정보 받음 Console.Write("Server Message Receive Waiting"); //MainPacket.data = BlindNetUtil.ByteTrimEndNull(MainPacket.data); // ReceiveByteToStringGenderText = Encoding.Default.GetString(BlindNetUtil.ByteTrimEndNull(MainPacket.data)); //변환해서 ㅓㄶ음 Console.WriteLine("Receive Message : " + ReceiveByteToStringGenderText); if (CMD_Instruction(ReceiveByteToStringGenderText)) // 명령문 전달해서 실행 { Result = "true"; } else { Result = "false"; } MainSocket.CryptoSend(Encoding.UTF8.GetBytes(Result), PacketType.Response); // 결과 전송 Console.WriteLine("Send Message | Instruction Result = " + Result + "\r\n"); } }
public void Run() { ChatPacket packet; ChatTimeStamp syncTime; User user; ChatRoom room; ChatRoomJoined roomJoined; ChatMessage message; DB.Open(); sendSock = new BlindSocket(); sendSock.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.CHATPORT); recvSock = new BlindSocket(); recvSock.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.CHATPORT + 1); syncTime = DB.GetAllTime(); packet = BlindChatUtil.StructToChatPacket(syncTime); ChatPacketSend(packet); //string sql; while (true) { packet = ChatPacketReceive(); if (packet.Type == ChatType.User) { //사용자 UI에 표시 user = BlindChatUtil.ChatPacketToStruct <User>(packet); AddUser(user); } else if (packet.Type == ChatType.Room) { //방추가 UI에 표시 room = BlindChatUtil.ChatPacketToStruct <ChatRoom>(packet); AddRoom(room); } else if (packet.Type == ChatType.RoomJoined) { //방인원 UI에 표시 roomJoined = BlindChatUtil.ChatPacketToStruct <ChatRoomJoined>(packet); AddMember(roomJoined); } else if (packet.Type == ChatType.Message) { //메시지 UI에 표시 message = BlindChatUtil.ChatPacketToStruct <ChatMessage>(packet); AddMessage(message); } else if (packet.Type == ChatType.Reset) { if (!Start) { LoadList(); LoadUI(); #if DEBUG MessageBox.Show("데이터 로드 완료"); #endif } Start = true; } else if (packet.Type == ChatType.Exit) { ExecuteExit(packet); } else { } } }
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(); }