Bug 1382937 - Rewrite Sync's master password functions to use the `nsILoginManagerCrypto` wrappers. r=MattN
authorKit Cambridge <kit@yakshaving.ninja>
Mon, 23 Oct 2017 10:40:56 -0700
changeset 444525 b4a5450f62bca390a5fdda70e423f021d2a2eb2d
parent 444524 270709ba8f6796dd655b782a80e6ced6eafc5b78
child 444526 c7986c821efe5d4d122784da3547299de5086de7
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1382937
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382937 - Rewrite Sync's master password functions to use the `nsILoginManagerCrypto` wrappers. r=MattN Using `nsISecretDecoderRing` directly bypasses `nsILoginManagerCrypto.uiBusy` and the observer notifications, so other consumers might not be aware we're already showing the dialog. We also bail early if the UI is busy, to avoid showing multiple dialogs. MozReview-Commit-ID: I7xzUWZkyPH
services/sync/Weave.js
services/sync/modules/util.js
--- a/services/sync/Weave.js
+++ b/services/sync/Weave.js
@@ -108,17 +108,16 @@ WeaveService.prototype = {
           // this check into this file if our above code is yielding too
           // many false positives.
           Components.utils.import("resource://services-sync/main.js");
           isConfigured = Weave.Status.checkSetup() != Weave.CLIENT_NOT_CONFIGURED;
         }
         let getHistogramById = Services.telemetry.getHistogramById;
         getHistogramById("WEAVE_CONFIGURED").add(isConfigured);
         if (isConfigured) {
-          getHistogramById("WEAVE_CONFIGURED_MASTER_PASSWORD").add(Utils.mpEnabled());
           this.ensureLoaded();
         }
       }
     }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
   },
 
   /**
    * Whether Sync appears to be enabled.
--- a/services/sync/modules/util.js
+++ b/services/sync/modules/util.js
@@ -18,16 +18,20 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 
 // FxAccountsCommon.js doesn't use a "namespace", so create one here.
 XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
   let FxAccountsCommon = {};
   Cu.import("resource://gre/modules/FxAccountsCommon.js", FxAccountsCommon);
   return FxAccountsCommon;
 });
 
+XPCOMUtils.defineLazyServiceGetter(this, "cryptoSDR",
+                                   "@mozilla.org/login-manager/crypto/SDR;1",
+                                   "nsILoginManagerCrypto");
+
 /*
  * Custom exception types.
  */
 class LockException extends Error {
   constructor(message) {
     super(message);
     this.name = "LockException";
   }
@@ -476,45 +480,30 @@ this.Utils = {
     return foo.concat(Utils.arraySub(bar, foo));
   },
 
   bind2: function Async_bind2(object, method) {
     return function innerBind() { return method.apply(object, arguments); };
   },
 
   /**
-   * Is there a master password configured, regardless of current lock state?
-   */
-  mpEnabled: function mpEnabled() {
-    let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"]
-                    .getService(Ci.nsIPK11TokenDB);
-    let token = tokenDB.getInternalKeyToken();
-    return token.hasPassword;
-  },
-
-  /**
    * Is there a master password configured and currently locked?
    */
-  mpLocked: function mpLocked() {
-    let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"]
-                    .getService(Ci.nsIPK11TokenDB);
-    let token = tokenDB.getInternalKeyToken();
-    return token.hasPassword && !token.isLoggedIn();
+  mpLocked() {
+    return !cryptoSDR.isLoggedIn;
   },
 
   // If Master Password is enabled and locked, present a dialog to unlock it.
   // Return whether the system is unlocked.
-  ensureMPUnlocked: function ensureMPUnlocked() {
-    if (!Utils.mpLocked()) {
-      return true;
+  ensureMPUnlocked() {
+    if (cryptoSDR.uiBusy) {
+      return false;
     }
-    let sdr = Cc["@mozilla.org/security/sdr;1"]
-                .getService(Ci.nsISecretDecoderRing);
     try {
-      sdr.encryptString("bacon");
+      cryptoSDR.encrypt("bacon");
       return true;
     } catch (e) {}
     return false;
   },
 
   /**
    * Return a value for a backoff interval.  Maximum is eight hours, unless
    * Status.backoffInterval is higher.