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