Ejemplo n.º 1
0
        private void OpenResource(DictObj resource)
        {
            var showMessage = resource[SEBSettings.KeyAdditionalResourcesConfirm] is true;

            if (showMessage)
            {
                var title          = resource[SEBSettings.KeyAdditionalResourcesTitle] as string;
                var customMessage  = resource[SEBSettings.KeyAdditionalResourcesConfirmText] as string;
                var defaultMessage = SEBUIStrings.AdditionalResourceConfirmMessage;
                var message        = (String.IsNullOrWhiteSpace(customMessage) ? defaultMessage : customMessage).Replace("%%TITLE%%", title);
                var result         = SEBMessageBox.Show(SEBUIStrings.AdditionalResourceConfirmTitle, message, MessageBoxIcon.Question, MessageBoxButtons.YesNo);

                if (result != DialogResult.Yes)
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty((string)resource[SEBSettings.KeyAdditionalResourcesResourceData]))
            {
                OpenEmbededResource(resource);
            }
            else if (!string.IsNullOrEmpty((string)resource[SEBSettings.KeyAdditionalResourcesUrl]))
            {
                SEBXULRunnerWebSocketServer.SendMessage(new SEBXULMessage(SEBXULMessage.SEBXULHandler.AdditionalResources, new { id = resource[SEBSettings.KeyAdditionalResourcesIdentifier] }));
            }
        }
 protected override void OnClick(EventArgs e)
 {
     try
     {
         SEBWindowHandler.BringWindowToTop(SEBWindowHandler.GetOpenWindows().First <KeyValuePair <IntPtr, string> >((Func <KeyValuePair <IntPtr, string>, bool>)(w => w.Key.GetProcess().GetExecutableName().Contains("xul"))).Key);
         if ((bool)SEBSettings.settingsCurrent["touchOptimized"])
         {
             if ((bool)SEBSettings.settingsCurrent["showReloadWarning"])
             {
                 if (SEBMessageBox.Show(SEBUIStrings.reloadPage, SEBUIStrings.reloadPageMessage, MessageBoxIcon.Exclamation, MessageBoxButtons.YesNo, false) != DialogResult.Yes)
                 {
                     return;
                 }
                 SEBXULRunnerWebSocketServer.SendReloadPage();
             }
             else
             {
                 SEBXULRunnerWebSocketServer.SendReloadPage();
             }
         }
         else
         {
             SEBXULRunnerWebSocketServer.SendReloadPage();
         }
     }
     catch
     {
     }
 }
        protected override void OnClick(EventArgs e)
        {
            try
            {
                SEBWindowHandler.BringWindowToTop(
                    SEBWindowHandler.GetOpenWindows()
                    .First(w => w.Key.GetProcess().GetExecutableName().Contains("xul")).Key);

                if ((bool)SEBSettings.settingsCurrent[SEBSettings.KeyTouchOptimized])
                {
                    if ((bool)SEBSettings.settingsCurrent[SEBSettings.KeyShowReloadWarning])
                    {
                        if (
                            SEBMessageBox.Show(SEBUIStrings.reloadPage, SEBUIStrings.reloadPageMessage,
                                               MessageBoxIcon.Warning, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            SEBXULRunnerWebSocketServer.SendReloadPage();
                        }
                    }
                    else
                    {
                        SEBXULRunnerWebSocketServer.SendReloadPage();
                    }
                }
                else
                {
                    SEBXULRunnerWebSocketServer.SendReloadPage();
                }
            }
            catch {}
        }
Ejemplo n.º 4
0
        public static void CheckServicePolicy(bool isServiceAvailable)
        {
            int forceService = (Int32)SEBClientInfo.getSebSetting(SEBSettings.KeySebServicePolicy)[SEBSettings.KeySebServicePolicy];

            switch (forceService)
            {
            case (int)sebServicePolicies.ignoreService:
                break;

            case (int)sebServicePolicies.indicateMissingService:
                if (!isServiceAvailable)
                {
                    //SEBClientInfo.SebWindowsClientForm.Activate();
                    SEBMessageBox.Show(SEBUIStrings.indicateMissingService, SEBUIStrings.indicateMissingServiceReason, MessageBoxIcon.Error, MessageBoxButtons.OK);
                }
                break;

            case (int)sebServicePolicies.forceSebService:
                if (!isServiceAvailable)
                {
                    //SEBClientInfo.SebWindowsClientForm.Activate();
                    SEBMessageBox.Show(SEBUIStrings.indicateMissingService, SEBUIStrings.forceSebServiceMessage, MessageBoxIcon.Error, MessageBoxButtons.OK);
                    Logger.AddError("SEB Windows service is not available and sebServicePolicies is set to forceSebService", null, null);
                    Logger.AddInformation("SafeExamBrowser is exiting", null, null);
                    throw new SEBNotAllowedToRunEception("SEB Windows service is not available and sebServicePolicies is set to forceSebService");
                }
                break;
            }
        }
 public static void CheckIfInsideVirtualMachine()
 {
     if (SebWindowsClientMain.IsInsideVM() && !(bool)SEBClientInfo.getSebSetting("allowVirtualMachine")["allowVirtualMachine"])
     {
         int num = (int)SEBMessageBox.Show(SEBUIStrings.detectedVirtualMachine, SEBUIStrings.detectedVirtualMachineForbiddenMessage, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
         Logger.AddError("Forbidden to run SEB on a virtual machine!", (object)null, (Exception)null, (string)null);
         Logger.AddInformation("Safe Exam Browser is exiting", (object)null, (Exception)null, (string)null);
         throw new SEBNotAllowedToRunEception("Forbidden to run SEB on a virtual machine!");
     }
 }
Ejemplo n.º 6
0
 public static void CheckIfRunViaRemoteConnection()
 {
     if (System.Windows.Forms.SystemInformation.TerminalServerSession && !(bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, SEBSettings.KeyAllowScreenSharing))
     {
         SEBMessageBox.Show(SEBUIStrings.detectedRemoteConnection, SEBUIStrings.detectedRemoteConnectionMessage, MessageBoxIcon.Error, MessageBoxButtons.OK);
         Logger.AddError("Forbidden to run SEB via Terminal Session!", null, null);
         Logger.AddInformation("Safe Exam Browser is exiting", null, null);
         throw new SEBNotAllowedToRunEception("Forbidden to run SEB via Terminal Session!");
     }
 }
Ejemplo n.º 7
0
        /// ----------------------------------------------------------------------------------------
        /// <summary>
        /// Check if running in VM and if SEB Windows Service is running or not.
        /// </summary>
        /// <returns>true if both checks are positive, false means SEB needs to quit.</returns>
        /// ----------------------------------------------------------------------------------------
        public static void CheckIfInsideVirtualMachine()
        {
            // Test if run inside virtual machine
            bool allowVirtualMachine = true;// (Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyAllowVirtualMachine)[SEBSettings.KeyAllowVirtualMachine];

            if (IsInsideVM() && (!allowVirtualMachine))
            {
                SEBMessageBox.Show(SEBUIStrings.detectedVirtualMachine, SEBUIStrings.detectedVirtualMachineForbiddenMessage, MessageBoxIcon.Error, MessageBoxButtons.OK);
                Logger.AddError("Forbidden to run SEB on a virtual machine!", null, null);
                Logger.AddInformation("Safe Exam Browser is exiting", null, null);
                throw new SEBNotAllowedToRunEception("Forbidden to run SEB on a virtual machine!");
            }
        }
        public static bool InitSebSettings()
        {
            Logger.AddInformation("Attempting to InitSebSettings", (object)null, (Exception)null, (string)null);
            if (!SebWindowsClientMain._loadingSebFile && !SebWindowsClientMain.clientSettingsSet)
            {
                if (!SEBClientInfo.SetSebClientConfiguration())
                {
                    int num = (int)SEBMessageBox.Show(SEBUIStrings.ErrorCaption, SEBUIStrings.ErrorWhenOpeningSettingsFile, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                    Logger.AddError("Error when opening the file SebClientSettings.seb!", (object)null, (Exception)null, (string)null);
                    return(false);
                }
                SebWindowsClientMain.clientSettingsSet = true;
                Logger.AddError("SEB client configuration set in InitSebSettings().", (object)null, (Exception)null, (string)null);
            }
            if (!SEBClientInfo.SetSystemVersionInfo())
            {
                int num = (int)SEBMessageBox.Show(SEBUIStrings.ErrorCaption, SEBUIStrings.OSNotSupported, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                Logger.AddError("Unknown OS. Exiting SEB.", (object)null, (Exception)null, (string)null);
                return(false);
            }

            /*if (SEBClientInfo.IsNewOS)
             * {
             * SebWindowsClientMain.sessionCreateNewDesktop = (bool) SEBClientInfo.getSebSetting("createNewDesktop")["createNewDesktop"];
             * if (SebWindowsClientMain.sessionCreateNewDesktop)
             * {
             *  SEBClientInfo.OriginalDesktop = SEBDesktopController.GetCurrent();
             *  SEBDesktopController.OpenInputDesktop();
             *  SEBClientInfo.SEBNewlDesktop = SEBDesktopController.CreateDesktop("SEBDesktop");
             *  SEBDesktopController.Show(SEBClientInfo.SEBNewlDesktop.DesktopName);
             *  if (!SEBDesktopController.SetCurrent(SEBClientInfo.SEBNewlDesktop))
             *  {
             *    Logger.AddError("SetThreadDesktop failed! Looks like the thread has hooks or windows in the current desktop.", (object) null, (Exception) null, (string) null);
             *    SEBDesktopController.Show(SEBClientInfo.OriginalDesktop.DesktopName);
             *    SEBDesktopController.SetCurrent(SEBClientInfo.OriginalDesktop);
             *    SEBClientInfo.SEBNewlDesktop.Close();
             *    int num = (int) SEBMessageBox.Show(SEBUIStrings.createNewDesktopFailed, SEBUIStrings.createNewDesktopFailedReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
             *    return false;
             *  }
             *  SEBClientInfo.DesktopName = "SEBDesktop";
             * }
             * else
             * {
             *  SEBClientInfo.OriginalDesktop = SEBDesktopController.GetCurrent();
             *  SEBClientInfo.DesktopName = SEBClientInfo.OriginalDesktop.DesktopName;
             * }
             * }*/
            Logger.AddInformation("Successfully InitSebSettings", (object)null, (Exception)null, (string)null);
            return(true);
        }
Ejemplo n.º 9
0
        private void ShowMessageOrPasswordDialog(string processName)
        {
            var quitPassword = (String)SEBClientInfo.getSebSetting(SEBSettings.KeyHashedQuitPassword)[SEBSettings.KeyHashedQuitPassword];

            if (!string.IsNullOrEmpty(quitPassword))
            {
                ShowPasswordDialog(processName, quitPassword);
            }
            else
            {
                SEBMessageBox.Show(SEBUIStrings.prohibitedProcessDetectedTitle,
                                   SEBUIStrings.prohibitedProcessDetectedText + processName,
                                   MessageBoxIcon.Error, MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 10
0
        private void textBoxAdditionalResourceUrl_Leave(object sender, EventArgs e)
        {
            SetIconFromUrl(textBoxAdditionalResourceUrl.Text);
            CreateURLFilterRule(textBoxAdditionalResourceUrl.Text);

            // Make sure URL filter is enabled and show message box if not
            if ((Boolean)SEBSettings.settingsCurrent[SEBSettings.KeyURLFilterEnable] == false)
            {
                SEBSettings.settingsCurrent[SEBSettings.KeyURLFilterEnable] = true;
                SEBMessageBox.Show("URL Filter Enabled", "When adding an external additional resource, an according URL filter must be defined " +
                                   "and URL filtering enabled. You can edit the filter(s) for the resource in its URL Filter list. " +
                                   "You may also have to create filter rules for your exam in Network/Filter settings (SEB internally only creates a rule exactly matching the Start URL). " +
                                   "For full control of displayed content, 'Filter also embedded content' (Network/Filter tab) should be activated as well.", MessageBoxIcon.Warning, MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 11
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     if (string.Compare((string)SEBClientInfo.getSebSetting("hashedQuitPassword")["hashedQuitPassword"], SEBProtectionController.ComputePasswordHash(this.txtQuitPassword.Text), StringComparison.OrdinalIgnoreCase) != 0)
     {
         this.Hide();
         int num = (int)SEBMessageBox.Show(SEBUIStrings.quittingFailed, SEBUIStrings.quittingFailedReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
         this.txtQuitPassword.Text = "";
         this.Visible = false;
     }
     else
     {
         this.Visible = false;
         SEBClientInfo.SebWindowsClientForm.ExitApplication(true);
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Start the server if not already running
        /// </summary>
        public static void StartServer()
        {
            if (IsRunning && Started)
            {
                return;
            }

            if (IsRunning)
            {
                for (int i = 0; i < 60; i++)
                {
                    if (!IsRunning)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }
                if (IsRunning)
                {
                    SEBMessageBox.Show(SEBUIStrings.alertWebSocketPortBlocked, SEBUIStrings.alertWebSocketPortBlockedMessage, MessageBoxIcon.Error, MessageBoxButtons.OK);
                }
                //MessageBox.Show(SEBUIStrings.alertWebSocketPortBlocked);
            }

            try
            {
                Logger.AddInformation("Starting WebSocketServer on " + ServerAddress);
                server         = new WebSocketServer(ServerAddress);
                FleckLog.Level = LogLevel.Debug;
                server.Start(socket =>
                {
                    socket.OnOpen    = () => OnClientConnected(socket);
                    socket.OnClose   = OnClientDisconnected;
                    socket.OnMessage = OnClientMessage;
                });
                Logger.AddInformation("Started WebSocketServer on " + ServerAddress);
                Started = true;
            }
            catch (Exception ex)
            {
                Logger.AddError("Unable to start WebSocketsServer for communication with XULRunner", null, ex);
            }
        }
Ejemplo n.º 13
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            string profileName = this.availableNetworks[this.listNetworks.SelectedIndex].profileName;

            this.buttonConnect.Text    = SEBUIStrings.WlanConnecting;
            this.buttonConnect.Enabled = false;
            this.listNetworks.Enabled  = false;
            try
            {
                int num = (int)this.wlanInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, this.wlanInterface.GetProfileXml(profileName), true);
                this.wlanInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
                this.Close();
            }
            catch (Exception ex)
            {
                int num = (int)SEBMessageBox.Show(SEBUIStrings.WlanConnectionFailedMessageTitle, SEBUIStrings.WlanConnectionFailedMessage, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                Logger.AddError(ex.Message, (object)this, ex, (string)null);
            }
        }
Ejemplo n.º 14
0
        protected override void OnClick(EventArgs e)
        {
            string restartExamTitle = (String)SEBClientInfo.getSebSetting(SEBSettings.KeyRestartExamText)[SEBSettings.KeyRestartExamText];

            // If there was no individual restart exam text set, we use the default text (which is localized)
            if (String.IsNullOrEmpty(restartExamTitle))
            {
                restartExamTitle = SEBUIStrings.restartExamDefaultTitle;
            }

            string quitPassword = (String)SEBClientInfo.getSebSetting(SEBSettings.KeyHashedQuitPassword)[SEBSettings.KeyHashedQuitPassword];

            if ((Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyRestartExamPasswordProtected)[SEBSettings.KeyRestartExamPasswordProtected] && !String.IsNullOrWhiteSpace(quitPassword))
            {
                var password = SebPasswordDialogForm.ShowPasswordDialogForm(restartExamTitle, SEBUIStrings.restartExamEnterPassword);

                //cancel button has been clicked
                if (password == null)
                {
                    return;
                }

                var hashedPassword = SEBProtectionController.ComputePasswordHash(password);
                if (String.IsNullOrWhiteSpace(password) ||
                    String.Compare(quitPassword, hashedPassword, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    SEBMessageBox.Show(restartExamTitle, SEBUIStrings.wrongQuitRestartPasswordText, MessageBoxIcon.Error, MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    SEBXULRunnerWebSocketServer.SendRestartExam();
                    return;
                }
            }

            if (SEBMessageBox.Show(restartExamTitle, SEBUIStrings.restartExamConfirm, MessageBoxIcon.Question, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                SEBXULRunnerWebSocketServer.SendRestartExam();
            }
        }
Ejemplo n.º 15
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string userQuitPassword = this.txtQuitPassword.Text;

            string hPassword            = SEBProtectionController.ComputePasswordHash(userQuitPassword);
            string settingsPasswordHash = (string)SEBClientInfo.getSebSetting(SEBSettings.KeyHashedQuitPassword)[SEBSettings.KeyHashedQuitPassword];
            int    quit = String.Compare(settingsPasswordHash, hPassword, StringComparison.OrdinalIgnoreCase);

            if (quit != 0)
            {
                this.Hide();
                SEBMessageBox.Show(SEBUIStrings.quittingFailed, SEBUIStrings.quittingFailedReason, MessageBoxIcon.Error, MessageBoxButtons.OK);
                this.txtQuitPassword.Text = "";
                this.Visible = false;
            }
            else
            {
                this.Visible = false;
                SEBClientInfo.SebWindowsClientForm.ExitApplication();
            }
        }
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            var profileName = availableNetworks[listNetworks.SelectedIndex].profileName;

            buttonConnect.Text    = SEBUIStrings.WlanConnecting;
            buttonConnect.Enabled = false;
            listNetworks.Enabled  = false;

            try
            {
                var profile = wlanInterface.GetProfileXml(profileName);
                wlanInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, profile, true);
                wlanInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
                this.Close();
            }
            catch (Exception ex)
            {
                SEBMessageBox.Show(SEBUIStrings.WlanConnectionFailedMessageTitle,
                                   SEBUIStrings.WlanConnectionFailedMessage, MessageBoxIcon.Error, MessageBoxButtons.OK);
                Logger.AddError(ex.Message, this, ex);
            }
        }
Ejemplo n.º 17
0
        private void OpenEmbededResource(DictObj resource)
        {
            var launcher = (int)resource[SEBSettings.KeyAdditionalResourcesResourceDataLauncher];
            var filename = (string)resource[SEBSettings.KeyAdditionalResourcesResourceDataFilename];
            var path     =
                _fileCompressor.DecompressDecodeAndSaveFile(
                    (string)resource[SEBSettings.KeyAdditionalResourcesResourceData], filename, resource[SEBSettings.KeyAdditionalResourcesIdentifier].ToString());

            //XulRunner
            if (launcher == 0)
            {
                SEBXULRunnerWebSocketServer.SendMessage(
                    new SEBXULMessage(
                        SEBXULMessage.SEBXULHandler.AdditionalResources, new
                {
                    id   = resource[SEBSettings.KeyAdditionalResourcesIdentifier],
                    path = path
                }
                        )
                    );
            }
            else
            {
                var permittedProcess = (DictObj)SEBSettings.permittedProcessList[launcher];
                var fullPath         = SEBClientInfo.SebWindowsClientForm.GetPermittedApplicationPath(permittedProcess);
                try
                {
                    Process process = SEBClientInfo.SebWindowsClientForm.CreateProcessWithExitHandler(string.Join(" ", fullPath, "\"" + path + filename + "\""));
                    if (SEBClientInfo.SebWindowsClientForm.permittedProcessesReferences[launcher] == null)
                    {
                        SEBClientInfo.SebWindowsClientForm.permittedProcessesReferences[launcher] = process;
                    }
                }
                catch (Exception ex)
                {
                    SEBMessageBox.Show(SEBUIStrings.errorOpeningResource, ex.Message, MessageBoxIcon.Error, MessageBoxButtons.OK);
                }
            }
        }
Ejemplo n.º 18
0
 public static void CheckIfTabletModeIsEnabled()
 {
     if ((bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, SEBSettings.KeyTouchOptimized))
     {
         bool?tabletMode = null;
         try
         {
             //returns null if the key is not existing (another windows version than 10)
             tabletMode = (int)Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ImmersiveShell", "TabletMode", 1) == 1;
         }
         catch (Exception ex)
         {
             Logger.AddError("Unable to check for tablet mode, assuming its not a Windows Version with a tablet mode and if so, ignore this error", null, ex, ex.StackTrace);
         }
         if (tabletMode != null && tabletMode == false)
         {
             SEBMessageBox.Show(SEBUIStrings.tableModeNotEnabledWarningTitle, SEBUIStrings.tableModeNotEnabledWarningText, MessageBoxIcon.Error, MessageBoxButtons.OK);
             Logger.AddInformation("Windows Tablet mode was not enabled, exiting seb", null, null);
             throw new SEBNotAllowedToRunEception("SEB not running without Tablet mode...");
         }
     }
 }
Ejemplo n.º 19
0
 public static byte[] DecryptDataWithCertificate(byte[] encryptedData, X509Certificate2 sebCertificate)
 {
     try
     {
         RSACryptoServiceProvider privateKey = sebCertificate.PrivateKey as RSACryptoServiceProvider;
         int          count1       = privateKey.KeySize / 8;
         byte[]       rgb1         = new byte[count1];
         byte[]       numArray     = new byte[count1];
         MemoryStream memoryStream = new MemoryStream();
         int          num          = encryptedData.Length / count1;
         for (int index = 0; index < num; ++index)
         {
             Buffer.BlockCopy((Array)encryptedData, index * count1, (Array)rgb1, 0, count1);
             byte[] buffer = privateKey.Decrypt(rgb1, false);
             memoryStream.Write(buffer, 0, buffer.Length);
         }
         int count2 = encryptedData.Length - num * count1;
         if (count2 > 0)
         {
             byte[] rgb2 = new byte[count2];
             Buffer.BlockCopy((Array)encryptedData, num * count1, (Array)rgb2, 0, count2);
             byte[] buffer = privateKey.Decrypt(rgb2, false);
             memoryStream.Write(buffer, 0, buffer.Length);
         }
         return(memoryStream.ToArray());
     }
     catch (CryptographicException ex)
     {
         Logger.AddError("Decrypting SEB config data encrypted with an identity failed with cryptographic exception:", (object)null, (Exception)ex, ex.Message);
         int num = (int)SEBMessageBox.Show(SEBUIStrings.errorDecryptingSettings, SEBUIStrings.certificateDecryptingError + ex.Message, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
         return((byte[])null);
     }
     catch (Exception ex)
     {
         Logger.AddError("Decrypting SEB config data encrypted with an identity failed with exception:", (object)null, ex, ex.Message);
         int num = (int)SEBMessageBox.Show(SEBUIStrings.errorDecryptingSettings, SEBUIStrings.certificateDecryptingError + ex.Message, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
         return((byte[])null);
     }
 }
        public static void CheckServicePolicy(bool isServiceAvailable)
        {
            switch ((int)SEBClientInfo.getSebSetting("sebServicePolicy")["sebServicePolicy"])
            {
            case 1:
                if (isServiceAvailable)
                {
                    break;
                }
                int num1 = (int)SEBMessageBox.Show(SEBUIStrings.indicateMissingService, SEBUIStrings.indicateMissingServiceReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                break;

            case 2:
                if (isServiceAvailable)
                {
                    break;
                }
                int num2 = (int)SEBMessageBox.Show(SEBUIStrings.indicateMissingService, SEBUIStrings.forceSebServiceMessage, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                Logger.AddError("SEB Windows service is not available and sebServicePolicies is set to forceSebService", (object)null, (Exception)null, (string)null);
                Logger.AddInformation("SafeExamBrowser is exiting", (object)null, (Exception)null, (string)null);
                throw new SEBNotAllowedToRunEception("SEB Windows service is not available and sebServicePolicies is set to forceSebService");
            }
        }
Ejemplo n.º 21
0
        protected override void OnClick(EventArgs e)
        {
            string examDefaultTitle = (string)SEBClientInfo.getSebSetting("restartExamText")["restartExamText"];

            if (string.IsNullOrEmpty(examDefaultTitle))
            {
                examDefaultTitle = SEBUIStrings.restartExamDefaultTitle;
            }
            string strA = (string)SEBClientInfo.getSebSetting("hashedQuitPassword")["hashedQuitPassword"];

            if ((bool)SEBClientInfo.getSebSetting("restartExamPasswordProtected")["restartExamPasswordProtected"] && !string.IsNullOrWhiteSpace(strA))
            {
                string input = SebPasswordDialogForm.ShowPasswordDialogForm(examDefaultTitle, SEBUIStrings.restartExamEnterPassword);
                if (input == null)
                {
                    return;
                }
                string passwordHash = SEBProtectionController.ComputePasswordHash(input);
                if (string.IsNullOrWhiteSpace(input) || string.Compare(strA, passwordHash, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    int num = (int)SEBMessageBox.Show(examDefaultTitle, SEBUIStrings.wrongQuitRestartPasswordText, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                }
                else
                {
                    SEBXULRunnerWebSocketServer.SendRestartExam();
                }
            }
            else
            {
                if (SEBMessageBox.Show(examDefaultTitle, SEBUIStrings.restartExamConfirm, MessageBoxIcon.Question, MessageBoxButtons.YesNo, false) != DialogResult.Yes)
                {
                    return;
                }
                SEBXULRunnerWebSocketServer.SendRestartExam();
            }
        }
Ejemplo n.º 22
0
 public static void StartServer()
 {
     if (SEBXULRunnerWebSocketServer.IsRunning && SEBXULRunnerWebSocketServer.Started)
     {
         return;
     }
     if (SEBXULRunnerWebSocketServer.IsRunning)
     {
         for (int index = 0; index < 60 && SEBXULRunnerWebSocketServer.IsRunning; ++index)
         {
             Thread.Sleep(1000);
         }
         if (SEBXULRunnerWebSocketServer.IsRunning)
         {
             int num = (int)SEBMessageBox.Show(SEBUIStrings.alertWebSocketPortBlocked, SEBUIStrings.alertWebSocketPortBlockedMessage, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
         }
     }
     try
     {
         Logger.AddInformation("Starting WebSocketServer on " + SEBXULRunnerWebSocketServer.ServerAddress, (object)null, (Exception)null, (string)null);
         SEBXULRunnerWebSocketServer.server = new WebSocketServer(SEBXULRunnerWebSocketServer.ServerAddress);
         FleckLog.Level = Fleck.LogLevel.Debug;
         SEBXULRunnerWebSocketServer.server.Start((Action <IWebSocketConnection>)(socket =>
         {
             socket.OnOpen    = (Action)(() => SEBXULRunnerWebSocketServer.OnClientConnected(socket));
             socket.OnClose   = new Action(SEBXULRunnerWebSocketServer.OnClientDisconnected);
             socket.OnMessage = new Action <string>(SEBXULRunnerWebSocketServer.OnClientMessage);
         }));
         Logger.AddInformation("Started WebSocketServer on " + SEBXULRunnerWebSocketServer.ServerAddress, (object)null, (Exception)null, (string)null);
         SEBXULRunnerWebSocketServer.Started = true;
     }
     catch (Exception ex)
     {
         Logger.AddError("Unable to start WebSocketsServer for communication with XULRunner", (object)null, ex, (string)null);
     }
 }
Ejemplo n.º 23
0
        /// ----------------------------------------------------------------------------------------
        /// <summary>
        /// Create and initialize SEB client settings and check system compatibility.
        /// This method needs to be executed only once when SEB first starts
        /// (not when reconfiguring).
        /// </summary>
        /// <returns>true if succeed</returns>
        /// ----------------------------------------------------------------------------------------
        public static bool InitSebSettings()
        {
            Logger.AddInformation("Attempting to InitSebSettings");

            // If loading of a .seb file isn't in progress and client settings aren't set yet
            if (_loadingSebFile == false && clientSettingsSet == false)
            {
                // Set SebClient configuration
                if (!SEBClientInfo.SetSebClientConfiguration())
                {
                    SEBMessageBox.Show(SEBUIStrings.ErrorCaption, SEBUIStrings.ErrorWhenOpeningSettingsFile, MessageBoxIcon.Error, MessageBoxButtons.OK);
                    Logger.AddError("Error when opening the file KiteStudentPortalSettings.seb!", null, null);
                    return(false);
                }
                clientSettingsSet = true;
                Logger.AddInformation("SEB client configuration set in InitSebSettings().", null, null);
            }

            // Check system version
            if (!SEBClientInfo.SetSystemVersionInfo())
            {
                SEBMessageBox.Show(SEBUIStrings.ErrorCaption, SEBUIStrings.OSNotSupported, MessageBoxIcon.Error, MessageBoxButtons.OK);
                Logger.AddError("Unknown OS. Exiting SEB.", null, null);
                return(false);
            }

            //on NT4/NT5 ++ a new desktop is created
            if (SEBClientInfo.IsNewOS)
            {
                sessionCreateNewDesktop = (Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyCreateNewDesktop)[SEBSettings.KeyCreateNewDesktop];
                if (sessionCreateNewDesktop)
                {
                    SEBClientInfo.OriginalDesktop = SEBDesktopController.GetCurrent();
                    SEBDesktopController OriginalInput = SEBDesktopController.OpenInputDesktop();

                    SEBClientInfo.SEBNewlDesktop = SEBDesktopController.CreateDesktop(SEBClientInfo.SEB_NEW_DESKTOP_NAME);
                    SEBDesktopController.Show(SEBClientInfo.SEBNewlDesktop.DesktopName);
                    if (!SEBDesktopController.SetCurrent(SEBClientInfo.SEBNewlDesktop))
                    {
                        Logger.AddError("SetThreadDesktop failed! Looks like the thread has hooks or windows in the current desktop.", null, null);
                        SEBDesktopController.Show(SEBClientInfo.OriginalDesktop.DesktopName);
                        SEBDesktopController.SetCurrent(SEBClientInfo.OriginalDesktop);
                        SEBClientInfo.SEBNewlDesktop.Close();
                        SEBMessageBox.Show(SEBUIStrings.createNewDesktopFailed, SEBUIStrings.createNewDesktopFailedReason, MessageBoxIcon.Error, MessageBoxButtons.OK);

                        return(false);
                    }
                    SEBClientInfo.DesktopName = SEBClientInfo.SEB_NEW_DESKTOP_NAME;
                }
                else
                {
                    SEBClientInfo.OriginalDesktop = SEBDesktopController.GetCurrent();
                    SEBClientInfo.DesktopName     = SEBClientInfo.OriginalDesktop.DesktopName;
                    //If you kill the explorer shell you don't need this!
                    //SebWindowsClientForm.SetVisibility(false);
                }
            }

            Logger.AddInformation("Successfully InitSebSettings");
            return(true);
        }
Ejemplo n.º 24
0
        /// ----------------------------------------------------------------------------------------
        /// <summary>
        /// Decrypt with X509 certificate/private key and RSA algorithm
        /// </summary>
        /// ----------------------------------------------------------------------------------------
        public static byte[] DecryptDataWithCertificate(byte[] encryptedData, X509Certificate2 sebCertificate)
        {
            try
            {
                // Decrypt config data

                RSACryptoServiceProvider privateKey = sebCertificate.PrivateKey as RSACryptoServiceProvider;
                //byte[] decryptedData = privateKey.Decrypt(encryptedDataBytes, false);

                // Blocksize is for example 2048/8 = 256
                int blockSize = privateKey.KeySize / 8;

                // buffer to hold byte sequence of the encrypted source data
                byte[] encryptedBuffer = new byte[blockSize];

                // buffer for the decrypted information
                byte[] decryptedBuffer = new byte[blockSize];

                // initialize array so it holds at least the amount needed to decrypt.
                //byte[] decryptedData = new byte[encryptedData.Length];
                MemoryStream decryptedStream = new MemoryStream();

                // Calculate number of full data blocks that will have to be decrypted
                int blockCount = encryptedData.Length / blockSize;

                for (int i = 0; i < blockCount; i++)
                {
                    // copy byte sequence from encrypted source data to the buffer
                    Buffer.BlockCopy(encryptedData, i * blockSize, encryptedBuffer, 0, blockSize);
                    // decrypt the block in the buffer
                    decryptedBuffer = privateKey.Decrypt(encryptedBuffer, false);
                    // write decrypted result back to the destination array
                    //decryptedBuffer.CopyTo(decryptedData, i*blockSize);
                    decryptedStream.Write(decryptedBuffer, 0, decryptedBuffer.Length);
                }
                int remainingBytes = encryptedData.Length - (blockCount * blockSize);
                if (remainingBytes > 0)
                {
                    encryptedBuffer = new byte[remainingBytes];
                    // copy remaining bytes from encrypted source data to the buffer
                    Buffer.BlockCopy(encryptedData, blockCount * blockSize, encryptedBuffer, 0, remainingBytes);
                    // decrypt the block in the buffer
                    decryptedBuffer = privateKey.Decrypt(encryptedBuffer, false);
                    // write decrypted result back to the destination array
                    //decryptedBuffer.CopyTo(decryptedData, blockCount * blockSize);
                    decryptedStream.Write(decryptedBuffer, 0, decryptedBuffer.Length);
                }
                byte[] decryptedData = decryptedStream.ToArray();

                return(decryptedData);
            }
            catch (CryptographicException cex)
            {
                Logger.AddError("Decrypting SEB config data encrypted with an identity failed with cryptographic exception:", null, cex, cex.Message);
                SEBMessageBox.Show(SEBUIStrings.errorDecryptingSettings, SEBUIStrings.certificateDecryptingError + cex.Message, MessageBoxIcon.Error, MessageBoxButtons.OK);
                return(null);
            }
            catch (Exception ex)
            {
                Logger.AddError("Decrypting SEB config data encrypted with an identity failed with exception:", null, ex, ex.Message);
                SEBMessageBox.Show(SEBUIStrings.errorDecryptingSettings, SEBUIStrings.certificateDecryptingError + ex.Message, MessageBoxIcon.Error, MessageBoxButtons.OK);
                return(null);
            }
        }