Esempio n. 1
0
        /// <summary>
        /// JSON Serialization of Settings Dictionary
        /// </summary>
        public static string XULRunnerConfigDictionarySerialize(Dictionary <string, object> xulRunnerSettings)
        {
            // Add current Browser Exam Key
            if ((bool)xulRunnerSettings[SEBSettings.KeySendBrowserExamKey])
            {
                string browserExamKey = SEBProtectionController.ComputeBrowserExamKey();
                xulRunnerSettings[SEBSettings.KeyBrowserExamKey] = browserExamKey;
                xulRunnerSettings[SEBSettings.KeyBrowserURLSalt] = true;
            }

            //If necessary replace the starturl with the path to the startResource
            xulRunnerSettings[SEBSettings.KeyStartURL] = GetStartupPathOrUrl();

            // Eventually update setting
            if ((Boolean)SEBSettings.settingsCurrent[SEBSettings.KeyRestartExamUseStartURL] == true)
            {
                xulRunnerSettings[SEBSettings.KeyRestartExamURL] = xulRunnerSettings[SEBSettings.KeyStartURL];
            }

            // Check if URL filter is enabled and send according keys to XULRunner seb only if it is
            if ((bool)xulRunnerSettings[SEBSettings.KeyURLFilterEnable] == false)
            {
                xulRunnerSettings[SEBSettings.KeyUrlFilterBlacklist] = "";
                xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] = "";
            }
            else
            {
                //Add the socket address
                if (!String.IsNullOrWhiteSpace(xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist].ToString()))
                {
                    xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] += @";";
                }
                //Add the Socket address with http protocoll instead of ws protocoll for the injected iframe
                xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] += String.Format("http://{0}", SEBXULRunnerWebSocketServer.ServerAddress.Substring(5));
            }

            // Add websocket sever address to XULRunner seb settings
            xulRunnerSettings[SEBSettings.KeyBrowserMessagingSocket]        = SEBXULRunnerWebSocketServer.ServerAddress;
            xulRunnerSettings[SEBSettings.KeyBrowserMessagingSocketEnabled] = true;
            Logger.AddInformation("Socket: " + xulRunnerSettings[SEBSettings.KeyBrowserMessagingSocket].ToString(), null, null);

            // Expand environment variables in paths which XULRunner seb is processing
            string downloadDirectoryWin = (string)xulRunnerSettings[SEBSettings.KeyDownloadDirectoryWin];

            downloadDirectoryWin = Environment.ExpandEnvironmentVariables(downloadDirectoryWin);
            //downloadDirectoryWin = downloadDirectoryWin.Replace(@"\", @"\\");
            xulRunnerSettings[SEBSettings.KeyDownloadDirectoryWin] = downloadDirectoryWin;

            if ((bool)xulRunnerSettings[SEBSettings.KeyTouchOptimized] == true)
            {
                // Switch off XULRunner seb reload warnings
                xulRunnerSettings[SEBSettings.KeyShowReloadWarning] = false;
                xulRunnerSettings[SEBSettings.KeyNewBrowserWindowShowReloadWarning] = false;


                // Set correct taskbar height according to display dpi
                xulRunnerSettings[SEBSettings.KeyTaskBarHeight] = (int)Math.Round((int)xulRunnerSettings[SEBSettings.KeyTaskBarHeight] * 1.7);
            }

            // Add proper browser user agent string to XULRunner seb settings
            xulRunnerSettings[SEBSettings.KeyBrowserUserAgent] = SEBClientInfo.BROWSER_USERAGENT_SEB + "/" + Application.ProductVersion +
                                                                 (String.IsNullOrEmpty((String)xulRunnerSettings[SEBSettings.KeyBrowserUserAgent]) ? "" : " " + xulRunnerSettings[SEBSettings.KeyBrowserUserAgent]);
            //Logger.AddInformation("Useragent String generated in SEBXulRunnerSettings: " + SEBClientInfo.BROWSER_USERAGENT_SEB + "/" + Application.ProductVersion +
            //  (String.IsNullOrEmpty((String)xulRunnerSettings[SEBSettings.KeyBrowserUserAgent]) ? "" : " " + xulRunnerSettings[SEBSettings.KeyBrowserUserAgent]));

            // Set onscreen keyboard settings flag when touch optimized is enabled
            xulRunnerSettings[SEBSettings.KeyBrowserScreenKeyboard] = (bool)xulRunnerSettings[SEBSettings.KeyTouchOptimized];

            //Remove all AdditionalResourceData from settings
            RecursivelyRemoveAdditionalResourceData((ListObj)xulRunnerSettings[SEBSettings.KeyAdditionalResources]);

            // The additional dictionary data is being extracted by the .NET-part, the browser only expects a path to the respective folder
            xulRunnerSettings.Remove(SEBSettings.KeyAdditionalDictionaries);

            xulRunnerSettings.Remove(SEBSettings.KeyPermittedProcesses);
            xulRunnerSettings.Remove(SEBSettings.KeyProhibitedProcesses);
            xulRunnerSettings.Remove(SEBSettings.KeyURLFilterRules);

            // The installed operating system culture for correct website localization
            xulRunnerSettings.Add("browserLanguage", System.Globalization.CultureInfo.CurrentCulture.Name);

            // Serialise
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonSettings             = serializer.Serialize(xulRunnerSettings);

            // Convert to Base64 String
            byte[] bytesJson  = Encoding.UTF8.GetBytes(jsonSettings);
            string base64Json = Convert.ToBase64String(bytesJson);

            //// remove the two chars "==" from the end of the string
            //string base64Json = base64String.Substring(0, base64String.Length - 2);

            return(base64Json);
        }
Esempio n. 2
0
        public static string XULRunnerConfigDictionarySerialize(Dictionary <string, object> xulRunnerSettings)
        {
            if ((bool)xulRunnerSettings["sendBrowserExamKey"])
            {
                string browserExamKey = SEBProtectionController.ComputeBrowserExamKey();
                xulRunnerSettings["browserExamKey"] = (object)browserExamKey;
                xulRunnerSettings["browserURLSalt"] = (object)true;
            }
            xulRunnerSettings["startURL"] = (object)SEBXulRunnerSettings.ResolveResourceUrl((string)xulRunnerSettings["startURL"]);
            SEBXulRunnerSettings.OverwriteSystemProxySettings(xulRunnerSettings);
            if ((bool)SEBSettings.settingsCurrent["restartExamUseStartURL"])
            {
                xulRunnerSettings["restartExamURL"] = xulRunnerSettings["startURL"];
            }
            if (!(bool)xulRunnerSettings["URLFilterEnable"])
            {
                xulRunnerSettings["blacklistURLFilter"] = (object)"";
                xulRunnerSettings["whitelistURLFilter"] = (object)"";
            }
            else
            {
                xulRunnerSettings["urlFilterTrustedContent"] = (object)(bool)xulRunnerSettings["URLFilterEnableContentFilter"];
                if (!xulRunnerSettings["whitelistURLFilter"].ToString().Contains(xulRunnerSettings["startURL"].ToString()) && !string.IsNullOrWhiteSpace(xulRunnerSettings["whitelistURLFilter"].ToString()))
                {
                    Dictionary <string, object> dictionary = xulRunnerSettings;
                    dictionary["whitelistURLFilter"] = (object)(dictionary["whitelistURLFilter"].ToString() + ";");
                }
                Dictionary <string, object> dictionary1 = xulRunnerSettings;
                dictionary1["whitelistURLFilter"] = (object)(dictionary1["whitelistURLFilter"].ToString() + xulRunnerSettings["startURL"].ToString());
                if ((bool)xulRunnerSettings["URLFilterEnableContentFilter"])
                {
                    if (!string.IsNullOrWhiteSpace(xulRunnerSettings["whitelistURLFilter"].ToString()))
                    {
                        Dictionary <string, object> dictionary2 = xulRunnerSettings;
                        dictionary2["whitelistURLFilter"] = (object)(dictionary2["whitelistURLFilter"].ToString() + ";");
                    }
                    Dictionary <string, object> dictionary3 = xulRunnerSettings;
                    dictionary3["whitelistURLFilter"] = (object)(dictionary3["whitelistURLFilter"].ToString() + string.Format("http://{0}", (object)SEBXULRunnerWebSocketServer.ServerAddress.Substring(5)));
                }
            }
            xulRunnerSettings["browserMessagingSocket"] = (object)SEBXULRunnerWebSocketServer.ServerAddress;
            Logger.AddInformation("Socket: " + xulRunnerSettings["browserMessagingSocket"].ToString(), (object)null, (Exception)null, (string)null);
            string str = Environment.ExpandEnvironmentVariables((string)xulRunnerSettings["downloadDirectoryWin"]);

            xulRunnerSettings["downloadDirectoryWin"] = (object)str;
            if ((bool)xulRunnerSettings["touchOptimized"])
            {
                xulRunnerSettings["showReloadWarning"] = (object)false;
                xulRunnerSettings["taskBarHeight"]     = (object)(int)Math.Round((double)(int)xulRunnerSettings["taskBarHeight"] * 1.7);
                if ((int)xulRunnerSettings["browserUserAgentWinTouchMode"] == 0)
                {
                    xulRunnerSettings["browserUserAgent"] = (object)"Mozilla/5.0 (Windows NT 6.3; rv:41.0; Touch) Gecko/20100101 Firefox/41";
                }
                else if ((int)xulRunnerSettings["browserUserAgentWinTouchMode"] == 1)
                {
                    xulRunnerSettings["browserUserAgent"] = (object)"Mozilla/5.0 (iPad; CPU OS 9_0_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A452 Safari/601.1";
                }
                else if ((int)xulRunnerSettings["browserUserAgentWinTouchMode"] == 2)
                {
                    xulRunnerSettings["browserUserAgent"] = xulRunnerSettings["browserUserAgentWinTouchModeCustom"];
                }
            }
            else if ((int)xulRunnerSettings["browserUserAgentWinDesktopMode"] == 0)
            {
                OperatingSystem osVersion = Environment.OSVersion;
                xulRunnerSettings["browserUserAgent"] = (object)string.Format("Mozilla/5.0 (Windows NT {0}.{1}; rv:41.0) Gecko/20100101 Firefox/41", (object)osVersion.Version.Major, (object)osVersion.Version.Minor);
            }
            else
            {
                xulRunnerSettings["browserUserAgent"] = xulRunnerSettings["browserUserAgentWinDesktopModeCustom"];
            }
            Dictionary <string, object> dictionary4 = xulRunnerSettings;

            dictionary4["browserUserAgent"]            = (object)(dictionary4["browserUserAgent"].ToString() + " SEB " + Application.ProductVersion);
            xulRunnerSettings["browserScreenKeyboard"] = (object)(bool)xulRunnerSettings["touchOptimized"];
            return(Convert.ToBase64String(Encoding.UTF8.GetBytes(new JavaScriptSerializer().Serialize((object)xulRunnerSettings))));
        }
Esempio n. 3
0
        /// <summary>
        /// JSON Serialization of Settings Dictionary
        /// </summary>
        public static string XULRunnerConfigDictionarySerialize(Dictionary <string, object> xulRunnerSettings)
        {
            // Add current Browser Exam Key
            if ((bool)xulRunnerSettings[SEBSettings.KeySendBrowserExamKey])
            {
                string browserExamKey = SEBProtectionController.ComputeBrowserExamKey();
                xulRunnerSettings[SEBSettings.KeyBrowserExamKey] = browserExamKey;
                xulRunnerSettings[SEBSettings.KeyBrowserURLSalt] = true;
            }

            // Eventually update setting
            if ((Boolean)SEBSettings.settingsCurrent[SEBSettings.KeyRestartExamUseStartURL] == true)
            {
                xulRunnerSettings[SEBSettings.KeyRestartExamURL] = xulRunnerSettings[SEBSettings.KeyStartURL];
            }

            // Check if URL filter is enabled and send according keys to XULRunner seb only if it is
            if ((bool)xulRunnerSettings[SEBSettings.KeyURLFilterEnable] == false)
            {
                xulRunnerSettings[SEBSettings.KeyUrlFilterBlacklist] = "";
                xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] = "";
            }
            else
            {
                // URL filter is enabled: Set trusted content flag to same value (what actually doesn't make sense, but it's implemented wrong in seb winctrl.jsm)
                xulRunnerSettings[SEBSettings.KeyUrlFilterTrustedContent] = (bool)xulRunnerSettings[SEBSettings.KeyURLFilterEnableContentFilter];

                //add the starturl to the whitelist if not yet added
                if (!xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist].ToString().Contains(xulRunnerSettings[SEBSettings.KeyStartURL].ToString()))
                {
                    if (!String.IsNullOrWhiteSpace(xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist].ToString()))
                    {
                        xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] += @";";
                    }
                }
                xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] += xulRunnerSettings[SEBSettings.KeyStartURL].ToString();

                //Add the socket address if content filter is enabled
                if ((bool)xulRunnerSettings[SEBSettings.KeyURLFilterEnableContentFilter] == true)
                {
                    if (!String.IsNullOrWhiteSpace(xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist].ToString()))
                    {
                        xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] += @";";
                    }
                    //Add the Socket address with http protocoll instead of ws protocoll for the injected iframe
                    xulRunnerSettings[SEBSettings.KeyUrlFilterWhitelist] += String.Format("http://{0}", SEBXULRunnerWebSocketServer.ServerAddress.Substring(5));
                }
            }

            // Add websocket sever address to XULRunner seb settings
            xulRunnerSettings[SEBSettings.KeyBrowserMessagingSocket] = SEBXULRunnerWebSocketServer.ServerAddress;
            Logger.AddInformation("Socket: " + xulRunnerSettings[SEBSettings.KeyBrowserMessagingSocket].ToString(), null, null);

            // Expand environment variables in paths which XULRunner seb is processing
            string downloadDirectoryWin = (string)xulRunnerSettings[SEBSettings.KeyDownloadDirectoryWin];

            downloadDirectoryWin = Environment.ExpandEnvironmentVariables(downloadDirectoryWin);
            //downloadDirectoryWin = downloadDirectoryWin.Replace(@"\", @"\\");
            xulRunnerSettings[SEBSettings.KeyDownloadDirectoryWin] = downloadDirectoryWin;

            // Add proper browser user agent string to XULRunner seb settings

            if ((bool)xulRunnerSettings[SEBSettings.KeyTouchOptimized] == true)
            {
                // Switch off XULRunner seb reload warning
                xulRunnerSettings[SEBSettings.KeyShowReloadWarning] = false;

                // Set correct task bar height according to display dpi
                xulRunnerSettings[SEBSettings.KeyTaskBarHeight] = (int)Math.Round((int)xulRunnerSettings[SEBSettings.KeyTaskBarHeight] * 1.7);

                if ((int)xulRunnerSettings[SEBSettings.KeyBrowserUserAgentTouchMode] == 0)
                {
                    xulRunnerSettings[SEBSettings.KeyBrowserUserAgent] = SEBClientInfo.BROWSER_USERAGENT_TOUCH;
                }
                else if ((int)xulRunnerSettings[SEBSettings.KeyBrowserUserAgentTouchMode] == 1)
                {
                    xulRunnerSettings[SEBSettings.KeyBrowserUserAgent] = SEBClientInfo.BROWSER_USERAGENT_TOUCH_IPAD;
                }
                else if ((int)xulRunnerSettings[SEBSettings.KeyBrowserUserAgentTouchMode] == 2)
                {
                    xulRunnerSettings[SEBSettings.KeyBrowserUserAgent] = xulRunnerSettings[SEBSettings.KeyBrowserUserAgentTouchModeCustom];
                }
            }
            else
            {
                if ((int)xulRunnerSettings[SEBSettings.KeyBrowserUserAgentDesktopMode] == 0)
                {
                    xulRunnerSettings[SEBSettings.KeyBrowserUserAgent] = SEBClientInfo.BROWSER_USERAGENT_DESKTOP;
                }
                else
                {
                    xulRunnerSettings[SEBSettings.KeyBrowserUserAgent] = xulRunnerSettings[SEBSettings.KeyBrowserUserAgentDesktopModeCustom];
                }
            }
            xulRunnerSettings[SEBSettings.KeyBrowserUserAgent] += " " + SEBClientInfo.BROWSER_USERAGENT_SEB + " " + Application.ProductVersion;

            // Set onscreen keyboard settings flag when touch optimized is enabled
            xulRunnerSettings[SEBSettings.KeyBrowserScreenKeyboard] = (bool)xulRunnerSettings[SEBSettings.KeyTouchOptimized];

            // Serialise
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonSettings             = serializer.Serialize(xulRunnerSettings);

            // Convert to Base64 String
            byte[] bytesJson  = Encoding.UTF8.GetBytes(jsonSettings);
            string base64Json = Convert.ToBase64String(bytesJson);

            //// remove the two chars "==" from the end of the string
            //string base64Json = base64String.Substring(0, base64String.Length - 2);

            return(base64Json);
        }