diff -r 000000000000 -r 6474c204b198 security/manager/pki/resources/content/device_manager.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/security/manager/pki/resources/content/device_manager.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,521 @@ +/* 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/. */ + +const nsIFilePicker = Components.interfaces.nsIFilePicker; +const nsFilePicker = "@mozilla.org/filepicker;1"; +const nsIPKCS11Slot = Components.interfaces.nsIPKCS11Slot; +const nsIPKCS11Module = Components.interfaces.nsIPKCS11Module; +const nsPKCS11ModuleDB = "@mozilla.org/security/pkcs11moduledb;1"; +const nsIPKCS11ModuleDB = Components.interfaces.nsIPKCS11ModuleDB; +const nsIPK11Token = Components.interfaces.nsIPK11Token; +const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1"; +const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB; +const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock; +const nsDialogParamBlock = "@mozilla.org/embedcomp/dialogparam;1"; +const nsIPKCS11 = Components.interfaces.nsIPKCS11; +const nsPKCS11ContractID = "@mozilla.org/security/pkcs11;1"; + +var bundle; +var secmoddb; +var skip_enable_buttons = false; + +/* Do the initial load of all PKCS# modules and list them. */ +function LoadModules() +{ + bundle = document.getElementById("pippki_bundle"); + secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB); + window.crypto.enableSmartCardEvents = true; + document.addEventListener("smartcard-insert", onSmartCardChange, false); + document.addEventListener("smartcard-remove", onSmartCardChange, false); + + RefreshDeviceList(); +} + +function getPKCS11() +{ + return Components.classes[nsPKCS11ContractID].getService(nsIPKCS11); +} + +function getNSSString(name) +{ + return document.getElementById("pipnss_bundle").getString(name); +} + +function doPrompt(msg) +{ + let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]. + getService(Components.interfaces.nsIPromptService); + prompts.alert(window, null, msg); +} + +function doConfirm(msg) +{ + let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]. + getService(Components.interfaces.nsIPromptService); + return prompts.confirm(window, null, msg); +} + +function RefreshDeviceList() +{ + var modules = secmoddb.listModules(); + var done = false; + + try { + modules.isDone(); + } catch (e) { done = true; } + while (!done) { + var module = modules.currentItem().QueryInterface(nsIPKCS11Module); + if (module) { + var slotnames = []; + var slots = module.listSlots(); + var slots_done = false; + try { + slots.isDone(); + } catch (e) { slots_done = true; } + while (!slots_done) { + var slot = null; + try { + slot = slots.currentItem().QueryInterface(nsIPKCS11Slot); + } catch (e) { slot = null; } + // in the ongoing discussion of whether slot names or token names + // are to be shown, I've gone with token names because NSS will + // prefer lookup by token name. However, the token may not be + // present, so maybe slot names should be listed, while token names + // are "remembered" for lookup? + if (slot != null) { + if (slot.tokenName) + slotnames[slotnames.length] = slot.tokenName; + else + slotnames[slotnames.length] = slot.name; + } + try { + slots.next(); + } catch (e) { slots_done = true; } + } + AddModule(module.name, slotnames); + } + try { + modules.next(); + } catch (e) { done = true; } + } + /* Set the text on the fips button */ + SetFIPSButton(); +} + +function SetFIPSButton() +{ + var fipsButton = document.getElementById("fipsbutton"); + var label; + if (secmoddb.isFIPSEnabled) { + label = bundle.getString("disable_fips"); + } else { + label = bundle.getString("enable_fips"); + } + fipsButton.setAttribute("label", label); + + var can_toggle = secmoddb.canToggleFIPS; + if (can_toggle) { + fipsButton.removeAttribute("disabled"); + } else { + fipsButton.setAttribute("disabled", "true"); + } +} + +/* Add a module to the tree. slots is the array of slots in the module, + * to be represented as children. + */ +function AddModule(module, slots) +{ + var tree = document.getElementById("device_list"); + var item = document.createElement("treeitem"); + var row = document.createElement("treerow"); + var cell = document.createElement("treecell"); + cell.setAttribute("label", module); + row.appendChild(cell); + item.appendChild(row); + var parent = document.createElement("treechildren"); + for (var i = 0; i