1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 // Any copyright is dedicated to the Public Domain.
3 // http://creativecommons.org/publicdomain/zero/1.0/
6 // Tests the methods and attributes for interfacing with a PKCS #11 slot.
8 // Ensure that the appropriate initialization has happened.
11 function find_slot_by_name(module, name) {
12 for (let slot of module.listSlots()) {
13 if (slot.name == name) {
20 function find_module_by_name(moduleDB, name) {
21 for (let slot of moduleDB.listModules()) {
22 if (slot.name == name) {
30 QueryInterface: ChromeUtils.generateQI(["nsIPrompt"]),
32 // This intentionally does not use arrow function syntax to avoid an issue
33 // where in the context of the arrow function, |this != gPrompt| due to
34 // how objects get wrapped when going across xpcom boundaries.
38 "Please authenticate to the token “Test PKCS11 Tokeñ 2 Label”. " +
39 "How to do so depends on the token (for example, using a fingerprint " +
40 "reader or entering a code with a keypad)."
45 const gPromptFactory = {
46 QueryInterface: ChromeUtils.generateQI(["nsIPromptFactory"]),
47 getPrompt: () => gPrompt,
51 MockRegistrar.register("@mozilla.org/prompter;1", gPromptFactory);
53 let libraryFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
54 libraryFile.append("pkcs11testmodule");
55 libraryFile.append(ctypes.libraryName("pkcs11testmodule"));
56 loadPKCS11Module(libraryFile, "PKCS11 Test Module", false);
58 let moduleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(
61 let testModule = find_module_by_name(moduleDB, "PKCS11 Test Module");
62 notEqual(testModule, null, "should be able to find test module");
63 let testSlot = find_slot_by_name(testModule, "Test PKCS11 Slot 二");
64 notEqual(testSlot, null, "should be able to find 'Test PKCS11 Slot 二'");
69 "Actual and expected name should match"
74 "Actual and expected description should match"
78 "Test PKCS11 Manufacturer ID",
79 "Actual and expected manufacturer ID should match"
84 "Actual and expected hardware version should match"
89 "Actual and expected firmware version should match"
93 Ci.nsIPKCS11Slot.SLOT_NOT_LOGGED_IN,
94 "Actual and expected status should match"
98 "Test PKCS11 Tokeñ 2 Label",
99 "Actual and expected token name should match"
102 let testToken = testSlot.getToken();
103 notEqual(testToken, null, "getToken() should succeed");
106 "Test PKCS11 Tokeñ 2 Label",
107 "Spot check: the actual and expected test token names should be equal"
109 ok(!testToken.isInternalKeyToken, "This token is not the internal key token");
111 testToken.login(true);
112 ok(testToken.isLoggedIn(), "Should have 'logged in' successfully");
114 testSlot = find_slot_by_name(testModule, "Empty PKCS11 Slot");
115 notEqual(testSlot, null, "should be able to find 'Empty PKCS11 Slot'");
116 equal(testSlot.tokenName, null, "Empty slot is empty");
119 Ci.nsIPKCS11Slot.SLOT_NOT_PRESENT,
120 "Actual and expected status should match"
123 let bundle = Services.strings.createBundle(
124 "chrome://pipnss/locale/pipnss.properties"
126 let internalModule = find_module_by_name(
128 "NSS Internal PKCS #11 Module"
130 notEqual(internalModule, null, "should be able to find internal module");
131 let cryptoSlot = find_slot_by_name(
133 bundle.GetStringFromName("TokenDescription")
135 notEqual(cryptoSlot, "should be able to find internal crypto slot");
138 bundle.GetStringFromName("SlotDescription"),
139 "crypto slot should have expected 'desc'"
143 bundle.GetStringFromName("ManufacturerID"),
144 "crypto slot should have expected 'manID'"
146 let keySlot = find_slot_by_name(
148 bundle.GetStringFromName("PrivateTokenDescription")
150 notEqual(keySlot, "should be able to find internal key slot");
153 bundle.GetStringFromName("PrivateSlotDescription"),
154 "key slot should have expected 'desc'"
158 bundle.GetStringFromName("ManufacturerID"),
159 "key slot should have expected 'manID'"