Backed out changeset c2d00a8b897b (bug 1368560)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Wed, 31 May 2017 22:52:14 +0200
changeset 412107 0e97e0db5f7769fd4215d64f9f23b9b1fed5c103
parent 412106 ab591336a1a372b8ff127757e2521403ac3ca07a
child 412108 61cc994f34d3ac8cf13536e479c864697ad3a2a5
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1368560
milestone55.0a1
backs outc2d00a8b897b7c48bc8526d0a754eb3570bac684
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
Backed out changeset c2d00a8b897b (bug 1368560)
services/sync/modules-testing/fakeservices.js
services/sync/modules/keys.js
services/sync/modules/main.js
services/sync/modules/record.js
services/sync/modules/service.js
services/sync/modules/util.js
services/sync/tests/unit/test_bookmark_order.js
services/sync/tests/unit/test_corrupt_keys.js
services/sync/tests/unit/test_keys.js
services/sync/tests/unit/test_syncengine_sync.js
--- a/services/sync/modules-testing/fakeservices.js
+++ b/services/sync/modules-testing/fakeservices.js
@@ -8,17 +8,16 @@ this.EXPORTED_SYMBOLS = [
   "FakeCryptoService",
   "FakeFilesystemService",
   "FakeGUIDService",
   "fakeSHA256HMAC",
 ];
 
 var {utils: Cu} = Components;
 
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/util.js");
 
 var btoa = Cu.import("resource://gre/modules/Log.jsm").btoa;
 
 this.FakeFilesystemService = function FakeFilesystemService(contents) {
   this.fakeContents = contents;
   let self = this;
@@ -91,18 +90,18 @@ this.FakeGUIDService = function FakeGUID
 
 /*
  * Mock implementation of WeaveCrypto. It does not encrypt or
  * decrypt, merely returning the input verbatim.
  */
 this.FakeCryptoService = function FakeCryptoService() {
   this.counter = 0;
 
-  delete Weave.Crypto;  // get rid of the getter first
-  Weave.Crypto = this;
+  delete Svc.Crypto;  // get rid of the getter first
+  Svc.Crypto = this;
 
   CryptoWrapper.prototype.ciphertextHMAC = function ciphertextHMAC(keyBundle) {
     return fakeSHA256HMAC(this.ciphertext);
   };
 }
 FakeCryptoService.prototype = {
 
   encrypt: function encrypt(clearText, symmetricKey, iv) {
--- a/services/sync/modules/keys.js
+++ b/services/sync/modules/keys.js
@@ -8,17 +8,16 @@ this.EXPORTED_SYMBOLS = [
   "BulkKeyBundle",
   "SyncKeyBundle"
 ];
 
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://gre/modules/Log.jsm");
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/util.js");
 
 /**
  * Represents a pair of keys.
  *
  * Each key stored in a key bundle is 256 bits. One key is used for symmetric
  * encryption. The other is used for HMAC.
  *
@@ -103,18 +102,18 @@ KeyBundle.prototype = {
   get sha256HMACHasher() {
     return this._sha256HMACHasher;
   },
 
   /**
    * Populate this key pair with 2 new, randomly generated keys.
    */
   generateRandom: function generateRandom() {
-    let generatedHMAC = Weave.Crypto.generateRandomKey();
-    let generatedEncr = Weave.Crypto.generateRandomKey();
+    let generatedHMAC = Svc.Crypto.generateRandomKey();
+    let generatedEncr = Svc.Crypto.generateRandomKey();
     this.keyPairB64 = [generatedEncr, generatedHMAC];
   },
 
 };
 
 /**
  * Represents a KeyBundle associated with a collection.
  *
--- a/services/sync/modules/main.js
+++ b/services/sync/modules/main.js
@@ -1,38 +1,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 this.EXPORTED_SYMBOLS = ["Weave"];
 
-const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
-
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-
 this.Weave = {};
-Cu.import("resource://services-sync/constants.js", Weave);
+Components.utils.import("resource://services-sync/constants.js", Weave);
 var lazies = {
   "service.js":           ["Service"],
   "status.js":            ["Status"],
   "util.js":              ["Utils", "Svc"]
 };
 
 function lazyImport(module, dest, props) {
   function getter(prop) {
     return function() {
       let ns = {};
-      Cu.import(module, ns);
+      Components.utils.import(module, ns);
       delete dest[prop];
       return dest[prop] = ns[prop];
     };
   }
   props.forEach(function(prop) { dest.__defineGetter__(prop, getter(prop)); });
 }
 
 for (let mod in lazies) {
   lazyImport("resource://services-sync/" + mod, Weave, lazies[mod]);
 }
-
-XPCOMUtils.defineLazyGetter(Weave, "Crypto", function() {
-  let { WeaveCrypto } = Cu.import("resource://services-crypto/WeaveCrypto.js", {});
-  return new WeaveCrypto();
-});
--- a/services/sync/modules/record.js
+++ b/services/sync/modules/record.js
@@ -16,17 +16,16 @@ var Cr = Components.results;
 var Cu = Components.utils;
 
 const CRYPTO_COLLECTION = "crypto";
 const KEYS_WBO = "keys";
 
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/keys.js");
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/resource.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-common/async.js");
 
 this.WBORecord = function WBORecord(collection, id) {
   this.data = {};
   this.payload = {};
   this.collection = collection;      // Optional.
@@ -135,19 +134,19 @@ CryptoWrapper.prototype = {
    *
    * Optional key bundle overrides the collection key lookup.
    */
   encrypt: function encrypt(keyBundle) {
     if (!keyBundle) {
       throw new Error("A key bundle must be supplied to encrypt.");
     }
 
-    this.IV = Weave.Crypto.generateRandomIV();
-    this.ciphertext = Weave.Crypto.encrypt(JSON.stringify(this.cleartext),
-                                           keyBundle.encryptionKeyB64, this.IV);
+    this.IV = Svc.Crypto.generateRandomIV();
+    this.ciphertext = Svc.Crypto.encrypt(JSON.stringify(this.cleartext),
+                                         keyBundle.encryptionKeyB64, this.IV);
     this.hmac = this.ciphertextHMAC(keyBundle);
     this.cleartext = null;
   },
 
   // Optional key bundle.
   decrypt: function decrypt(keyBundle) {
     if (!this.ciphertext) {
       throw "No ciphertext: nothing to decrypt?";
@@ -160,18 +159,18 @@ CryptoWrapper.prototype = {
     // Authenticate the encrypted blob with the expected HMAC
     let computedHMAC = this.ciphertextHMAC(keyBundle);
 
     if (computedHMAC != this.hmac) {
       Utils.throwHMACMismatch(this.hmac, computedHMAC);
     }
 
     // Handle invalid data here. Elsewhere we assume that cleartext is an object.
-    let cleartext = Weave.Crypto.decrypt(this.ciphertext,
-                                         keyBundle.encryptionKeyB64, this.IV);
+    let cleartext = Svc.Crypto.decrypt(this.ciphertext,
+                                       keyBundle.encryptionKeyB64, this.IV);
     let json_result = JSON.parse(cleartext);
 
     if (json_result && (json_result instanceof Object)) {
       this.cleartext = json_result;
       this.ciphertext = null;
     } else {
       throw "Decryption failed: result is <" + json_result + ">, not an object.";
     }
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -20,17 +20,16 @@ const KEYS_WBO = "keys";
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://services-common/async.js");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/engines/clients.js");
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/policies.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/resource.js");
 Cu.import("resource://services-sync/rest.js");
 Cu.import("resource://services-sync/stages/enginesync.js");
 Cu.import("resource://services-sync/stages/declined.js");
 Cu.import("resource://services-sync/status.js");
 Cu.import("resource://services-sync/telemetry.js");
@@ -149,17 +148,17 @@ Sync11Service.prototype = {
     this.metaURL = this.storageURL + "meta/global";
     this.cryptoKeysURL = this.storageURL + CRYPTO_COLLECTION + "/" + KEYS_WBO;
   },
 
   _checkCrypto: function _checkCrypto() {
     let ok = false;
 
     try {
-      let iv = Weave.Crypto.generateRandomIV();
+      let iv = Svc.Crypto.generateRandomIV();
       if (iv.length == 24)
         ok = true;
 
     } catch (e) {
       this._log.debug("Crypto check failed: " + e);
     }
 
     return ok;
--- a/services/sync/modules/util.js
+++ b/services/sync/modules/util.js
@@ -636,12 +636,21 @@ XPCOMUtils.defineLazyGetter(Utils, "_utf
 
 /*
  * Commonly-used services
  */
 this.Svc = {};
 Svc.Prefs = new Preferences(PREFS_BRANCH);
 Svc.Obs = Observers;
 
+Svc.__defineGetter__("Crypto", function() {
+  let cryptoSvc;
+  let ns = {};
+  Cu.import("resource://services-crypto/WeaveCrypto.js", ns);
+  cryptoSvc = new ns.WeaveCrypto();
+  delete Svc.Crypto;
+  return Svc.Crypto = cryptoSvc;
+});
+
 Svc.Obs.add("xpcom-shutdown", function() {
   for (let name in Svc)
     delete Svc[name];
 });
--- a/services/sync/tests/unit/test_bookmark_order.js
+++ b/services/sync/tests/unit/test_bookmark_order.js
@@ -1,15 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 _("Making sure after processing incoming bookmarks, they show up in the right order");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://services-sync/engines/bookmarks.js");
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://testing-common/services/sync/utils.js");
 
 function run_test() {
   Svc.Prefs.set("log.logger.engine.bookmarks", "Trace");
   initTestLogging("Trace");
   Log.repository.getLogger("Sqlite").level = Log.Level.Info;
@@ -39,18 +38,18 @@ function serverForFoo(engine) {
       },
     },
     crypto: {
       keys: encryptPayload({
         id: "keys",
         // Generate a fake default key bundle to avoid resetting the client
         // before the first sync.
         default: [
-          Weave.Crypto.generateRandomKey(),
-          Weave.Crypto.generateRandomKey(),
+          Svc.Crypto.generateRandomKey(),
+          Svc.Crypto.generateRandomKey(),
         ],
       }),
     },
     [engine.name]: {},
   });
 }
 
 async function resolveConflict(engine, collection, timestamp, buildTree,
--- a/services/sync/tests/unit/test_corrupt_keys.js
+++ b/services/sync/tests/unit/test_corrupt_keys.js
@@ -1,15 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/engines.js");
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/engines/tabs.js");
 Cu.import("resource://services-sync/engines/history.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/status.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://testing-common/services/sync/utils.js");
 
@@ -41,18 +40,18 @@ add_task(async function test_locally_cha
     await configureIdentity({ username: "johndoe" }, server);
     // We aren't doing a .login yet, so fudge the cluster URL.
     Service.clusterURL = Service.identity._token.endpoint;
 
     Service.engineManager.register(HistoryEngine);
     Service.engineManager.unregister("addons");
 
     function corrupt_local_keys() {
-      Service.collectionKeys._default.keyPair = [Weave.Crypto.generateRandomKey(),
-                                                 Weave.Crypto.generateRandomKey()];
+      Service.collectionKeys._default.keyPair = [Svc.Crypto.generateRandomKey(),
+                                                 Svc.Crypto.generateRandomKey()];
     }
 
     _("Setting meta.");
 
     // Bump version on the server.
     let m = new WBORecord("meta", "global");
     m.payload = {"syncID": "foooooooooooooooooooooooooo",
                  "storageVersion": STORAGE_VERSION};
--- a/services/sync/tests/unit/test_keys.js
+++ b/services/sync/tests/unit/test_keys.js
@@ -1,14 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/keys.js");
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-sync/browserid_identity.js");
 Cu.import("resource://testing-common/services/sync/utils.js");
 
 var collectionKeys = new CollectionKeyManager();
 
 function sha256HMAC(message, key) {
@@ -179,20 +178,20 @@ add_task(async function test_ensureLogge
   /*
    * Build a test version of storage/crypto/keys.
    * Encrypt it with the sync key.
    * Pass it into the CollectionKeyManager.
    */
 
   log.info("Building storage keys...");
   let storage_keys = new CryptoWrapper("crypto", "keys");
-  let default_key64 = Weave.Crypto.generateRandomKey();
-  let default_hmac64 = Weave.Crypto.generateRandomKey();
-  let bookmarks_key64 = Weave.Crypto.generateRandomKey();
-  let bookmarks_hmac64 = Weave.Crypto.generateRandomKey();
+  let default_key64 = Svc.Crypto.generateRandomKey();
+  let default_hmac64 = Svc.Crypto.generateRandomKey();
+  let bookmarks_key64 = Svc.Crypto.generateRandomKey();
+  let bookmarks_hmac64 = Svc.Crypto.generateRandomKey();
 
   storage_keys.cleartext = {
     "default": [default_key64, default_hmac64],
     "collections": {"bookmarks": [bookmarks_key64, bookmarks_hmac64]},
   };
   storage_keys.modified = Date.now() / 1000;
   storage_keys.id = "keys";
 
--- a/services/sync/tests/unit/test_syncengine_sync.js
+++ b/services/sync/tests/unit/test_syncengine_sync.js
@@ -1,14 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/engines.js");
-Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/policies.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/resource.js");
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://testing-common/services/sync/rotaryengine.js");
 Cu.import("resource://testing-common/services/sync/utils.js");
 
@@ -1083,18 +1082,18 @@ add_task(async function test_processInco
   collection._wbos.nojson2 = new ServerWBO("nojson2", "This is invalid JSON");
   collection._wbos.scotsman = new ServerWBO(
       "scotsman", encryptPayload({id: "scotsman",
                                   denomination: "Flying Scotsman"}));
   collection._wbos.nodecrypt = new ServerWBO("nodecrypt", "Decrypt this!");
   collection._wbos.nodecrypt2 = new ServerWBO("nodecrypt2", "Decrypt this!");
 
   // Patch the fake crypto service to throw on the record above.
-  Weave.Crypto._decrypt = Weave.Crypto.decrypt;
-  Weave.Crypto.decrypt = function(ciphertext) {
+  Svc.Crypto._decrypt = Svc.Crypto.decrypt;
+  Svc.Crypto.decrypt = function(ciphertext) {
     if (ciphertext == "Decrypt this!") {
       throw "Derp! Cipher finalized failed. Im ur crypto destroyin ur recordz.";
     }
     return this._decrypt.apply(this, arguments);
   };
 
   // Some broken records also exist locally.
   let engine = makeRotaryEngine();