mobile/android/chrome/content/MasterPassword.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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";
     6 var MasterPassword = {
     7   pref: "privacy.masterpassword.enabled",
     8   _tokenName: "",
    10   get _secModuleDB() {
    11     delete this._secModuleDB;
    12     return this._secModuleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(Ci.nsIPKCS11ModuleDB);
    13   },
    15   get _pk11DB() {
    16     delete this._pk11DB;
    17     return this._pk11DB = Cc["@mozilla.org/security/pk11tokendb;1"].getService(Ci.nsIPK11TokenDB);
    18   },
    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   },
    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;
    38       let token = this._pk11DB.findTokenByName(this._tokenName);
    40       if (status == Ci.nsIPKCS11Slot.SLOT_UNINITIALIZED)
    41         token.initPassword(aPassword);
    42       else if (status == Ci.nsIPKCS11Slot.SLOT_READY)
    43         token.changePassword("", aPassword);
    45       BrowserApp.notifyPrefObservers(this.pref);
    46       return true;
    47     } catch(e) {
    48       dump("MasterPassword.setPassword: " + e);
    49     }
    50     return false;
    51   },
    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