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
--- 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";
}
@@ -474,45 +478,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.