mobile/android/chrome/content/MasterPassword.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:cbd3902e72ec
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 "use strict";
5
6 var MasterPassword = {
7 pref: "privacy.masterpassword.enabled",
8 _tokenName: "",
9
10 get _secModuleDB() {
11 delete this._secModuleDB;
12 return this._secModuleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(Ci.nsIPKCS11ModuleDB);
13 },
14
15 get _pk11DB() {
16 delete this._pk11DB;
17 return this._pk11DB = Cc["@mozilla.org/security/pk11tokendb;1"].getService(Ci.nsIPK11TokenDB);
18 },
19
20 get enabled() {
21 let slot = this._secModuleDB.findSlotByName(this._tokenName);
22 if (slot) {
23 let status = slot.status;
24 return status != Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED && status != Ci.nsIPKCS11Slot.SLOT_READY;
25 }
26 return false;
27 },
28
29 setPassword: function setPassword(aPassword) {
30 try {
31 let status;
32 let slot = this._secModuleDB.findSlotByName(this._tokenName);
33 if (slot)
34 status = slot.status;
35 else
36 return false;
37
38 let token = this._pk11DB.findTokenByName(this._tokenName);
39
40 if (status == Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED)
41 token.initPassword(aPassword);
42 else if (status == Ci.nsIPKCS11Slot.SLOT_READY)
43 token.changePassword("", aPassword);
44
45 BrowserApp.notifyPrefObservers(this.pref);
46 return true;
47 } catch(e) {
48 dump("MasterPassword.setPassword: " + e);
49 }
50 return false;
51 },
52
53 removePassword: function removePassword(aOldPassword) {
54 try {
55 let token = this._pk11DB.getInternalKeyToken();
56 if (token.checkPassword(aOldPassword)) {
57 token.changePassword(aOldPassword, "");
58 BrowserApp.notifyPrefObservers(this.pref);
59 return true;
60 }
61 } catch(e) {
62 dump("MasterPassword.removePassword: " + e + "\n");
63 }
64 NativeWindow.toast.show(Strings.browser.GetStringFromName("masterPassword.incorrect"), "short");
65 return false;
66 }
67 };

mercurial