diff options
author | Pale Moon <git-repo@palemoon.org> | 2016-09-01 13:39:08 +0200 |
---|---|---|
committer | Pale Moon <git-repo@palemoon.org> | 2016-09-01 13:39:08 +0200 |
commit | 3d8ce1a11a7347cc94a937719c4bc8df46fb8d14 (patch) | |
tree | 8c26ca375a6312751c00a27e1653fb6f189f0463 /services/sync/modules/identity.js | |
parent | e449bdb1ec3a82f204bffdd9c3c54069d086eee3 (diff) | |
download | palemoon-gre-3d8ce1a11a7347cc94a937719c4bc8df46fb8d14.tar.gz |
Base import of Tycho code (warning: huge commit)
Diffstat (limited to 'services/sync/modules/identity.js')
-rw-r--r-- | services/sync/modules/identity.js | 125 |
1 files changed, 117 insertions, 8 deletions
diff --git a/services/sync/modules/identity.js b/services/sync/modules/identity.js index e3ecd7635..2bee13b5b 100644 --- a/services/sync/modules/identity.js +++ b/services/sync/modules/identity.js @@ -9,8 +9,9 @@ this.EXPORTED_SYMBOLS = ["IdentityManager"]; const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://services-sync/constants.js"); -Cu.import("resource://services-common/log4moz.js"); +Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-sync/util.js"); // Lazy import to prevent unnecessary load on startup. @@ -21,7 +22,8 @@ for (let symbol of ["BulkKeyBundle", "SyncKeyBundle"]) { } /** - * Manages identity and authentication for Sync. + * Manages "legacy" identity and authentication for Sync. + * See browserid_identity for the Firefox Accounts based identity manager. * * The following entities are managed: * @@ -57,8 +59,8 @@ for (let symbol of ["BulkKeyBundle", "SyncKeyBundle"]) { * and any other function that involves the built-in functionality. */ this.IdentityManager = function IdentityManager() { - this._log = Log4Moz.repository.getLogger("Sync.Identity"); - this._log.Level = Log4Moz.Level[Svc.Prefs.get("log.logger.identity")]; + this._log = Log.repository.getLogger("Sync.Identity"); + this._log.Level = Log.Level[Svc.Prefs.get("log.logger.identity")]; this._basicPassword = null; this._basicPasswordAllowLookup = true; @@ -81,6 +83,45 @@ IdentityManager.prototype = { _syncKeyBundle: null, + /** + * Initialize the identity provider. Returns a promise that is resolved + * when initialization is complete and the provider can be queried for + * its state + */ + initialize: function() { + // Nothing to do for this identity provider. + return Promise.resolve(); + }, + + finalize: function() { + // Nothing to do for this identity provider. + return Promise.resolve(); + }, + + /** + * Called whenever Service.logout() is called. + */ + logout: function() { + // nothing to do for this identity provider. + }, + + /** + * Ensure the user is logged in. Returns a promise that resolves when + * the user is logged in, or is rejected if the login attempt has failed. + */ + ensureLoggedIn: function() { + // nothing to do for this identity provider + return Promise.resolve(); + }, + + /** + * Indicates if the identity manager is still initializing + */ + get readyToAuthenticate() { + // We initialize in a fully sync manner, so we are always finished. + return true; + }, + get account() { return Svc.Prefs.get("account", this.username); }, @@ -133,7 +174,21 @@ IdentityManager.prototype = { // If we change the username, we interpret this as a major change event // and wipe out the credentials. this._log.info("Username changed. Removing stored credentials."); + this.resetCredentials(); + }, + + /** + * Resets/Drops all credentials we hold for the current user. + */ + resetCredentials: function() { this.basicPassword = null; + this.resetSyncKey(); + }, + + /** + * Resets/Drops the sync key we hold for the current user. + */ + resetSyncKey: function() { this.syncKey = null; // syncKeyBundle cleared as a result of setting syncKey. }, @@ -323,6 +378,25 @@ IdentityManager.prototype = { }, /** + * Verify the current auth state, unlocking the master-password if necessary. + * + * Returns a promise that resolves with the current auth state after + * attempting to unlock. + */ + unlockAndVerifyAuthState: function() { + // Try to fetch the passphrase - this will prompt for MP unlock as a + // side-effect... + try { + this.syncKey; + } catch (ex) { + this._log.debug("Fetching passphrase threw " + ex + + "; assuming master password locked."); + return Promise.resolve(MASTER_PASSWORD_LOCKED); + } + return Promise.resolve(STATUS_OK); + }, + + /** * Persist credentials to password store. * * When credentials are updated, they are changed in memory only. This will @@ -373,6 +447,22 @@ IdentityManager.prototype = { }, /** + * Pre-fetches any information that might help with migration away from this + * identity. Called after every sync and is really just an optimization that + * allows us to avoid a network request for when we actually need the + * migration info. + */ + prefetchMigrationSentinel: function(service) { + // Try and fetch the migration sentinel - it will end up in the recordManager + // cache. + try { + service.recordManager.get(service.storageURL + "meta/fxa_credentials"); + } catch (ex) { + this._log.warn("Failed to pre-fetch the migration sentinel", ex); + } + }, + + /** * Obtains the array of basic logins from nsiPasswordManager. */ _getLogins: function _getLogins(realm) { @@ -411,12 +501,21 @@ IdentityManager.prototype = { }, /** + * Return credentials hosts for this identity only. + */ + _getSyncCredentialsHosts: function() { + return Utils.getSyncCredentialsHostsLegacy(); + }, + + /** * Deletes Sync credentials from the password manager. */ deleteSyncCredentials: function deleteSyncCredentials() { - let logins = Services.logins.findLogins({}, PWDMGR_HOST, "", ""); - for each (let login in logins) { - Services.logins.removeLogin(login); + for (let host of this._getSyncCredentialsHosts()) { + let logins = Services.logins.findLogins({}, host, "", ""); + for each (let login in logins) { + Services.logins.removeLogin(login); + } } // Wait until after store is updated in case it fails. @@ -491,5 +590,15 @@ IdentityManager.prototype = { onRESTRequestBasic: function onRESTRequestBasic(request) { let up = this.username + ":" + this.basicPassword; request.setHeader("authorization", "Basic " + btoa(up)); - } + }, + + createClusterManager: function(service) { + Cu.import("resource://services-sync/stages/cluster.js"); + return new ClusterManager(service); + }, + + offerSyncOptions: function () { + // Do nothing for Sync 1.1. + return {accepted: true}; + }, }; |