summaryrefslogtreecommitdiffstats
path: root/application/palemoon/components/preferences/security.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-02 03:35:06 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-02 03:35:06 -0500
commit49ee0794b5d912db1f95dce6eb52d781dc210db5 (patch)
tree6efefe6a09feb09d965932b24e10436b9ac8189c /application/palemoon/components/preferences/security.js
parente72ef92b5bdc43cd2584198e2e54e951b70299e8 (diff)
downloadUXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar.gz
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar.lz
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar.xz
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.zip
Add Pale Moon
Diffstat (limited to 'application/palemoon/components/preferences/security.js')
-rw-r--r--application/palemoon/components/preferences/security.js268
1 files changed, 268 insertions, 0 deletions
diff --git a/application/palemoon/components/preferences/security.js b/application/palemoon/components/preferences/security.js
new file mode 100644
index 000000000..a337f398c
--- /dev/null
+++ b/application/palemoon/components/preferences/security.js
@@ -0,0 +1,268 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+
+var gSecurityPane = {
+ _pane: null,
+
+ /**
+ * Initializes UI.
+ */
+ init: function ()
+ {
+ this._pane = document.getElementById("paneSecurity");
+ this._initMasterPasswordUI();
+ this._initHPKPUI();
+ },
+
+ // ADD-ONS
+
+ /*
+ * Preferences:
+ *
+ * xpinstall.whitelist.required
+ * - true if a site must be added to a site whitelist before extensions
+ * provided by the site may be installed from it, false if the extension
+ * may be directly installed after a confirmation dialog
+ */
+
+ /**
+ * Enables/disables the add-ons Exceptions button depending on whether
+ * or not add-on installation warnings are displayed.
+ */
+ readWarnAddonInstall: function ()
+ {
+ var warn = document.getElementById("xpinstall.whitelist.required");
+ var exceptions = document.getElementById("addonExceptions");
+
+ exceptions.disabled = !warn.value;
+
+ // don't override the preference value
+ return undefined;
+ },
+
+ /**
+ * Displays the exceptions lists for add-on installation warnings.
+ */
+ showAddonExceptions: function ()
+ {
+ var bundlePrefs = document.getElementById("bundlePreferences");
+
+ var params = this._addonParams;
+ if (!params.windowTitle || !params.introText) {
+ params.windowTitle = bundlePrefs.getString("addons_permissions_title");
+ params.introText = bundlePrefs.getString("addonspermissionstext");
+ }
+
+ document.documentElement.openWindow("Browser:Permissions",
+ "chrome://browser/content/preferences/permissions.xul",
+ "", params);
+ },
+
+ /**
+ * Parameters for the add-on install permissions dialog.
+ */
+ _addonParams:
+ {
+ blockVisible: false,
+ sessionVisible: false,
+ allowVisible: true,
+ prefilledHost: "",
+ permissionType: "install"
+ },
+
+ /**
+ * Ensures that the blocklist is enabled/disabled appropriately based on level
+ */
+ addonLevelNeedsSync: function()
+ {
+ Services.prefs.setBoolPref("extensions.blocklist.level.updated", true);
+ },
+ // called from preferences window onunload.
+ syncAddonSecurityLevel: function()
+ {
+ if (Services.prefs.getBoolPref("extensions.blocklist.level.updated") == true) {
+ Services.prefs.setBoolPref("extensions.blocklist.level.updated", false);
+ var secLevel = Services.prefs.getIntPref("extensions.blocklist.level");
+ Services.prefs.setBoolPref("extensions.blocklist.enabled",
+ !(secLevel == 99));
+ }
+ },
+
+ // PASSWORDS
+
+ /*
+ * Preferences:
+ *
+ * signon.rememberSignons
+ * - true if passwords are remembered, false otherwise
+ */
+
+ /**
+ * Enables/disables the Exceptions button used to configure sites where
+ * passwords are never saved. When browser is set to start in Private
+ * Browsing mode, the "Remember passwords" UI is useless, so we disable it.
+ */
+ readSavePasswords: function ()
+ {
+ var pref = document.getElementById("signon.rememberSignons");
+ var excepts = document.getElementById("passwordExceptions");
+
+ if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
+ document.getElementById("savePasswords").disabled = true;
+ excepts.disabled = true;
+ return false;
+ } else {
+ excepts.disabled = !pref.value;
+ // don't override pref value in UI
+ return undefined;
+ }
+ },
+
+ /**
+ * Displays a dialog in which the user can view and modify the list of sites
+ * where passwords are never saved.
+ */
+ showPasswordExceptions: function ()
+ {
+ document.documentElement.openWindow("Toolkit:PasswordManagerExceptions",
+ "chrome://passwordmgr/content/passwordManagerExceptions.xul",
+ "", null);
+ },
+
+ /**
+ * Initializes master password UI: the "use master password" checkbox, selects
+ * the master password button to show, and enables/disables it as necessary.
+ * The master password is controlled by various bits of NSS functionality, so
+ * the UI for it can't be controlled by the normal preference bindings.
+ */
+ _initMasterPasswordUI: function ()
+ {
+ var noMP = !this._masterPasswordSet();
+
+ var button = document.getElementById("changeMasterPassword");
+ button.disabled = noMP;
+
+ var checkbox = document.getElementById("useMasterPassword");
+ checkbox.checked = !noMP;
+ },
+
+ /**
+ * Returns true if the user has a master password set and false otherwise.
+ */
+ _masterPasswordSet: function ()
+ {
+ const Cc = Components.classes, Ci = Components.interfaces;
+ var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
+ getService(Ci.nsIPKCS11ModuleDB);
+ var slot = secmodDB.findSlotByName("");
+ if (slot) {
+ var status = slot.status;
+ var hasMP = status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED &&
+ status != Ci.nsIPKCS11Slot.SLOT_READY;
+ return hasMP;
+ } else {
+ // XXX I have no bloody idea what this means
+ return false;
+ }
+ },
+
+ /**
+ * Enables/disables the master password button depending on the state of the
+ * "use master password" checkbox, and prompts for master password removal if
+ * one is set.
+ */
+ updateMasterPasswordButton: function ()
+ {
+ var checkbox = document.getElementById("useMasterPassword");
+ var button = document.getElementById("changeMasterPassword");
+ button.disabled = !checkbox.checked;
+
+ // unchecking the checkbox should try to immediately remove the master
+ // password, because it's impossible to non-destructively remove the master
+ // password used to encrypt all the passwords without providing it (by
+ // design), and it would be extremely odd to pop up that dialog when the
+ // user closes the prefwindow and saves his settings
+ if (!checkbox.checked)
+ this._removeMasterPassword();
+ else
+ this.changeMasterPassword();
+
+ this._initMasterPasswordUI();
+ },
+
+ /**
+ * Displays the "remove master password" dialog to allow the user to remove
+ * the current master password. When the dialog is dismissed, master password
+ * UI is automatically updated.
+ */
+ _removeMasterPassword: function ()
+ {
+ const Cc = Components.classes, Ci = Components.interfaces;
+ var secmodDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].
+ getService(Ci.nsIPKCS11ModuleDB);
+ if (secmodDB.isFIPSEnabled) {
+ var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
+ getService(Ci.nsIPromptService);
+ var bundle = document.getElementById("bundlePreferences");
+ promptService.alert(window,
+ bundle.getString("pw_change_failed_title"),
+ bundle.getString("pw_change2empty_in_fips_mode"));
+ }
+ else {
+ document.documentElement.openSubDialog("chrome://mozapps/content/preferences/removemp.xul",
+ "", null);
+ }
+ this._initMasterPasswordUI();
+ },
+
+ /**
+ * Displays a dialog in which the master password may be changed.
+ */
+ changeMasterPassword: function ()
+ {
+ document.documentElement.openSubDialog("chrome://mozapps/content/preferences/changemp.xul",
+ "", null);
+ this._initMasterPasswordUI();
+ },
+
+ /**
+ * Shows the sites where the user has saved passwords and the associated login
+ * information.
+ */
+ showPasswords: function ()
+ {
+ document.documentElement.openWindow("Toolkit:PasswordManager",
+ "chrome://passwordmgr/content/passwordManager.xul",
+ "", null);
+ },
+
+ _initHPKPUI: function() {
+ let checkbox = document.getElementById("enableHPKP");
+ let HPKPpref = document.getElementById("security.cert_pinning.enforcement_level");
+
+ if (HPKPpref.value == 0) {
+ checkbox.checked = false;
+ } else {
+ checkbox.checked = true;
+ }
+ },
+
+ /**
+ * Updates the HPKP enforcement level to the proper value depending on checkbox
+ * state.
+ */
+ updateHPKPPref: function() {
+ let checkbox = document.getElementById("enableHPKP");
+ let HPKPpref = document.getElementById("security.cert_pinning.enforcement_level");
+
+ if (checkbox.checked) {
+ HPKPpref.value = 2;
+ } else {
+ HPKPpref.value = 0;
+ }
+ }
+};