/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 2001 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Bob Lord * Ian McGreer * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ 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"; var bundle; var secmoddb; /* Do the initial load of all PKCS# modules and list them. */ function LoadModules() { bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties"); secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB); window.crypto.enableSmartCardEvents = true; document.addEventListener("smartcard-insert", onSmartCardChange, false); document.addEventListener("smartcard-remove", onSmartCardChange, false); RefreshDeviceList(); } 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.GetStringFromName("disable_fips"); } else { label = bundle.GetStringFromName("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