From 03c9c7ee8bf30f61766659ffa9c20b7ad727b906 Mon Sep 17 00:00:00 2001 From: "mcgreer%netscape.com" Date: Tue, 15 May 2001 20:40:28 +0000 Subject: [PATCH] bug 80094, implement device manager for PSM2 r=thayes, sr=blizzard --- .../pki/resources/content/device_manager.js | 353 ++++++++++++++++++ .../pki/resources/content/device_manager.xul | 122 ++++++ .../pki/resources/content/load_device.xul | 64 ++++ .../pki/resources/content/pref-security.js | 6 + .../pki/resources/content/pref-security.xul | 5 +- security/manager/pki/resources/jar.mn | 4 + .../resources/locale/en-US/certManager.dtd | 2 +- .../resources/locale/en-US/deviceManager.dtd | 44 +++ .../resources/locale/en-US/pippki.properties | 16 + .../manager/ssl/public/nsIPK11TokenDB.idl | 8 + security/manager/ssl/public/nsIPKCS11Slot.idl | 58 ++- .../resources/locale/en-US/pipnss.properties | 12 +- security/manager/ssl/src/Makefile.in | 1 + security/manager/ssl/src/makefile.win | 1 + security/manager/ssl/src/nsNSSComponent.cpp | 11 +- security/manager/ssl/src/nsNSSModule.cpp | 9 + security/manager/ssl/src/nsPK11TokenDB.cpp | 102 +++-- security/manager/ssl/src/nsPK11TokenDB.h | 25 ++ security/manager/ssl/src/nsPKCS11Slot.cpp | 349 +++++++++++++++++ security/manager/ssl/src/nsPKCS11Slot.h | 75 ++++ 20 files changed, 1222 insertions(+), 45 deletions(-) create mode 100644 security/manager/pki/resources/content/device_manager.js create mode 100644 security/manager/pki/resources/content/device_manager.xul create mode 100644 security/manager/pki/resources/content/load_device.xul create mode 100644 security/manager/pki/resources/locale/en-US/deviceManager.dtd create mode 100644 security/manager/ssl/src/nsPKCS11Slot.cpp create mode 100644 security/manager/ssl/src/nsPKCS11Slot.h diff --git a/security/manager/pki/resources/content/device_manager.js b/security/manager/pki/resources/content/device_manager.js new file mode 100644 index 000000000000..62d835a98d79 --- /dev/null +++ b/security/manager/pki/resources/content/device_manager.js @@ -0,0 +1,353 @@ +/* + * 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 Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Bob Lord + * Ian McGreer + */ + +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; + +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); + 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 = slots.currentItem().QueryInterface(nsIPKCS11Slot); + // 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? + slotnames[slotnames.length] = slot.name; + try { + slots.next(); + } catch (e) { slots_done = true; } + } + AddModule(module.name, slotnames); + } + try { + modules.next(); + } catch (e) { done = 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("class", "propertylist"); + cell.setAttribute("label", module); + cell.setAttribute("style", "font-weight: bold"); + cell.setAttribute("crop", "never"); + row.appendChild(cell); + item.appendChild(row); + var parent = document.createElement("treechildren"); + for (var i = 0; i 0) { + var kind = items[0].getAttribute("pk11kind"); + if (kind == "slot") { + // get the module cell for this slot cell + var cell = items[0].parentNode.parentNode.firstChild.firstChild; + var module_name = cell.getAttribute("label"); + var module = secmoddb.findModuleByName(module_name); + // get the cell for the selected row (the slot to display) + cell = items[0].firstChild.firstChild; + var slot_name = cell.getAttribute("label"); + selected_slot = module.findSlotByName(slot_name); + } + /* else (kind == "module") */ /* nothing for now */ + } +} + +function enableButtons() +{ + var toggle = "true"; + var login_toggle = "true"; + var logout_toggle = "true"; + var pw_toggle = "true"; + getSelectedSlot(); + if (!selected_slot) { + ClearInfoList(); + return; + } + // here's the workaround - login functions are all with token, + // so grab the token type + var selected_token = selected_slot.getToken(); + if (selected_token != null) { + toggle="false"; + if (selected_token.needsLogin()) { + pw_toggle = "false"; + if (selected_token.isLoggedIn()) { + login_toggle = "true"; + logout_toggle = "false"; + } else { + login_toggle = "false"; + logout_toggle = "true"; + } + } + } + var thebutton = document.getElementById('change_slotname_button'); + // not implemented + //thebutton.setAttribute("disabled", toggle); + thebutton.setAttribute("disabled", "true"); + thebutton = document.getElementById('login_button'); + thebutton.setAttribute("disabled", login_toggle); + thebutton = document.getElementById('logout_button'); + thebutton.setAttribute("disabled", logout_toggle); + thebutton = document.getElementById('change_pw_button'); + // not implemented + //thebutton.setAttribute("disabled", pw_toggle); + thebutton.setAttribute("disabled", "true"); + showSlotInfo(); +} + +// clear the display of information for the slot +function ClearInfoList() +{ + var info_list = document.getElementById("info_list"); + var nodes = info_list.childNodes; + for (var i=0; i + + + + + +%deviceManangerDTD; + +%pippkiDTD; +]> + + + + +