void worker_DoWork(object sender, DoWorkEventArgs e) { Console.WriteLine("Initiating pipe server"); NamedPipeServerStream pipeServer = new NamedPipeServerStream("AntidotePipe", PipeDirection.InOut, 1); int threadId = Thread.CurrentThread.ManagedThreadId; // Wait for a client to connect Console.WriteLine("waiting for pipe client..."); pipeServer.WaitForConnection(); Console.WriteLine("Client connected on thread[{0}].", threadId); try { // Read the request from the client. Once the client has // written to the pipe its security token will be available. StreamString ss = new StreamString(pipeServer); string msg = ss.ReadString(); if (msg == Constants.SHUTDOWN_ANTIDOTE_CLIENT_FOR_UPDATE) { AppState.SHUTDOWN_FOR_UPDATE_MODE = true; // Shutdown the entire program // TODO: Add method to unload SSDT Driver // this.Dispatcher.Invoke(() => { Application.Current.Shutdown(); }); } } // Catch the IOException that is raised if the pipe is broken // or disconnected. catch (IOException exception) { SentrySdk.CaptureException(exception); Console.WriteLine("ERROR: {0}", exception.Message); } pipeServer.Close(); }
private void OnLogin(object sender, RoutedEventArgs e) { String Username = LoginUsernameTextBox.Text; String Password = LoginPasswordTextBox.Password; Console.WriteLine("EXECUTING LOGIN with username " + Username + " Password " + Password); LoginBtn.IsEnabled = false; var req = ApiController.getLoginReq(Username, Password); // TODO : Delete this code after building admin login + PKI verification if (Username == "kill_process" && Password == "02356 01357") { Application.Current.Shutdown(); Common.SetTaskManager(true); NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "AntidoteShieldPipe", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation); Console.WriteLine("Connecting to server...\n"); try { pipeClient.Connect(10000); Console.WriteLine("Connected!! to pipe\n"); StreamString ss = new StreamString(pipeClient); ss.WriteString("STOP_REVIVING_ANTIDOTE"); pipeClient.Close(); } catch (System.TimeoutException te) { te.Data.Add("Username", Username); te.Data.Add("Cause", "Timed out while asking AntidoteShield to close beacuse user entered kill_process directive"); AppState.ravenClient.Capture(new SentryEvent(te)); Console.WriteLine("Pipe connect timeout!"); } } ApiController.client.ExecuteAsync(req, res => { try { Console.WriteLine("Response received!"); dynamic resDic = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(res.Content); String status = resDic.Status; if (status == "success") { UnhookWindowsHookEx(hHook); sessionModel.Initialize(resDic); Dictionary <String, String> msg = new Dictionary <string, string>(); msg.Add("MessageCode", Constants.MSG_IDENTIFY_SOCKET); string sessionCode = resDic.Data.SessionCode; Console.WriteLine("Received login res from API, SessionCode is " + sessionCode); msg.Add("SessionCode", sessionCode); string serialized_msg = JsonConvert.SerializeObject(msg); Console.WriteLine("Registering WS Connection with msg: " + serialized_msg); if (!ws.IsAlive) { ws.Connect(); } ws.Send(serialized_msg); AppState.SESSION_ACTIVE = true; Common.SetTaskManager(true); this.Dispatcher.Invoke(() => { MainWindow mainWindow = new MainWindow(sessionModel); AppState.openWindow = mainWindow; CloseWindow(); mainWindow.Show(); }); } else { String ErrMsg = resDic.ErrMsg; String ActionCode = String.Empty; try { ActionCode = resDic.ActionCode; } catch (RuntimeBinderException) { } if ((Constants.REQ_PW_RESET).Equals(ActionCode)) { // 비밀번호 리셋이 요구되는 경우 this.Dispatcher.Invoke(() => { LoginBtn.IsEnabled = true; MessageBox.Show(ErrMsg); PwResetWindow pwResetWindow = new PwResetWindow(Username); pwResetWindow.Owner = this; pwResetWindow.ShowDialog(); }); } else { this.Dispatcher.Invoke(() => { LoginBtn.IsEnabled = true; MessageBox.Show(ErrMsg); LoginPasswordTextBox.Clear(); }); } } } catch (Exception exception) { Console.WriteLine(exception); exception.Data.Add("Username", Username); AppState.ravenClient.Capture(new SentryEvent(exception)); this.Dispatcher.Invoke(() => { LoginBtn.IsEnabled = true; MessageBox.Show("로그인 서버에 문제가 발생해 로그인에 실패하였습니다."); LoginPasswordTextBox.Clear(); }); } }); }