зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1368560 part 2 - Move Svc.Crypto to Weave.Crypto. r=markh
MozReview-Commit-ID: 74IFsVjZSgz --HG-- extra : rebase_source : 29833856a9cca178a2b508b6401cdb6bd8ca1bb9
This commit is contained in:
Родитель
198e8ab1d1
Коммит
275b48a53e
|
@ -13,6 +13,7 @@ this.EXPORTED_SYMBOLS = [
|
|||
|
||||
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");
|
||||
|
||||
|
@ -95,8 +96,8 @@ this.FakeGUIDService = function FakeGUIDService() {
|
|||
this.FakeCryptoService = function FakeCryptoService() {
|
||||
this.counter = 0;
|
||||
|
||||
delete Svc.Crypto; // get rid of the getter first
|
||||
Svc.Crypto = this;
|
||||
delete Weave.Crypto; // get rid of the getter first
|
||||
Weave.Crypto = this;
|
||||
|
||||
CryptoWrapper.prototype.ciphertextHMAC = function ciphertextHMAC(keyBundle) {
|
||||
return fakeSHA256HMAC(this.ciphertext);
|
||||
|
|
|
@ -13,6 +13,7 @@ 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");
|
||||
|
||||
/**
|
||||
|
@ -107,8 +108,8 @@ KeyBundle.prototype = {
|
|||
* Populate this key pair with 2 new, randomly generated keys.
|
||||
*/
|
||||
generateRandom: function generateRandom() {
|
||||
let generatedHMAC = Svc.Crypto.generateRandomKey();
|
||||
let generatedEncr = Svc.Crypto.generateRandomKey();
|
||||
let generatedHMAC = Weave.Crypto.generateRandomKey();
|
||||
let generatedEncr = Weave.Crypto.generateRandomKey();
|
||||
this.keyPairB64 = [generatedEncr, generatedHMAC];
|
||||
},
|
||||
|
||||
|
|
|
@ -4,8 +4,12 @@
|
|||
|
||||
this.EXPORTED_SYMBOLS = ["Weave"];
|
||||
|
||||
const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
this.Weave = {};
|
||||
Components.utils.import("resource://services-sync/constants.js", Weave);
|
||||
Cu.import("resource://services-sync/constants.js", Weave);
|
||||
var lazies = {
|
||||
"service.js": ["Service"],
|
||||
"status.js": ["Status"],
|
||||
|
@ -16,7 +20,7 @@ function lazyImport(module, dest, props) {
|
|||
function getter(prop) {
|
||||
return function() {
|
||||
let ns = {};
|
||||
Components.utils.import(module, ns);
|
||||
Cu.import(module, ns);
|
||||
delete dest[prop];
|
||||
return dest[prop] = ns[prop];
|
||||
};
|
||||
|
@ -27,3 +31,8 @@ function lazyImport(module, dest, props) {
|
|||
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();
|
||||
});
|
||||
|
|
|
@ -21,6 +21,7 @@ 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");
|
||||
|
@ -139,9 +140,9 @@ CryptoWrapper.prototype = {
|
|||
throw new Error("A key bundle must be supplied to encrypt.");
|
||||
}
|
||||
|
||||
this.IV = Svc.Crypto.generateRandomIV();
|
||||
this.ciphertext = Svc.Crypto.encrypt(JSON.stringify(this.cleartext),
|
||||
keyBundle.encryptionKeyB64, this.IV);
|
||||
this.IV = Weave.Crypto.generateRandomIV();
|
||||
this.ciphertext = Weave.Crypto.encrypt(JSON.stringify(this.cleartext),
|
||||
keyBundle.encryptionKeyB64, this.IV);
|
||||
this.hmac = this.ciphertextHMAC(keyBundle);
|
||||
this.cleartext = null;
|
||||
},
|
||||
|
@ -164,8 +165,8 @@ CryptoWrapper.prototype = {
|
|||
}
|
||||
|
||||
// Handle invalid data here. Elsewhere we assume that cleartext is an object.
|
||||
let cleartext = Svc.Crypto.decrypt(this.ciphertext,
|
||||
keyBundle.encryptionKeyB64, this.IV);
|
||||
let cleartext = Weave.Crypto.decrypt(this.ciphertext,
|
||||
keyBundle.encryptionKeyB64, this.IV);
|
||||
let json_result = JSON.parse(cleartext);
|
||||
|
||||
if (json_result && (json_result instanceof Object)) {
|
||||
|
|
|
@ -25,6 +25,7 @@ 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");
|
||||
|
@ -153,7 +154,7 @@ Sync11Service.prototype = {
|
|||
let ok = false;
|
||||
|
||||
try {
|
||||
let iv = Svc.Crypto.generateRandomIV();
|
||||
let iv = Weave.Crypto.generateRandomIV();
|
||||
if (iv.length == 24)
|
||||
ok = true;
|
||||
|
||||
|
|
|
@ -641,15 +641,6 @@ 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];
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
_("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");
|
||||
|
@ -43,8 +44,8 @@ function serverForFoo(engine) {
|
|||
// Generate a fake default key bundle to avoid resetting the client
|
||||
// before the first sync.
|
||||
default: [
|
||||
Svc.Crypto.generateRandomKey(),
|
||||
Svc.Crypto.generateRandomKey(),
|
||||
Weave.Crypto.generateRandomKey(),
|
||||
Weave.Crypto.generateRandomKey(),
|
||||
],
|
||||
}),
|
||||
},
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
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");
|
||||
|
@ -45,8 +46,8 @@ add_task(async function test_locally_changed_keys() {
|
|||
Service.engineManager.unregister("addons");
|
||||
|
||||
function corrupt_local_keys() {
|
||||
Service.collectionKeys._default.keyPair = [Svc.Crypto.generateRandomKey(),
|
||||
Svc.Crypto.generateRandomKey()];
|
||||
Service.collectionKeys._default.keyPair = [Weave.Crypto.generateRandomKey(),
|
||||
Weave.Crypto.generateRandomKey()];
|
||||
}
|
||||
|
||||
_("Setting meta.");
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
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");
|
||||
|
@ -183,10 +184,10 @@ add_task(async function test_ensureLoggedIn() {
|
|||
|
||||
log.info("Building storage keys...");
|
||||
let storage_keys = new CryptoWrapper("crypto", "keys");
|
||||
let default_key64 = Svc.Crypto.generateRandomKey();
|
||||
let default_hmac64 = Svc.Crypto.generateRandomKey();
|
||||
let bookmarks_key64 = Svc.Crypto.generateRandomKey();
|
||||
let bookmarks_hmac64 = Svc.Crypto.generateRandomKey();
|
||||
let default_key64 = Weave.Crypto.generateRandomKey();
|
||||
let default_hmac64 = Weave.Crypto.generateRandomKey();
|
||||
let bookmarks_key64 = Weave.Crypto.generateRandomKey();
|
||||
let bookmarks_hmac64 = Weave.Crypto.generateRandomKey();
|
||||
|
||||
storage_keys.cleartext = {
|
||||
"default": [default_key64, default_hmac64],
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
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");
|
||||
|
@ -1087,8 +1088,8 @@ add_task(async function test_processIncoming_decrypt_failed() {
|
|||
collection._wbos.nodecrypt2 = new ServerWBO("nodecrypt2", "Decrypt this!");
|
||||
|
||||
// Patch the fake crypto service to throw on the record above.
|
||||
Svc.Crypto._decrypt = Svc.Crypto.decrypt;
|
||||
Svc.Crypto.decrypt = function(ciphertext) {
|
||||
Weave.Crypto._decrypt = Weave.Crypto.decrypt;
|
||||
Weave.Crypto.decrypt = function(ciphertext) {
|
||||
if (ciphertext == "Decrypt this!") {
|
||||
throw "Derp! Cipher finalized failed. Im ur crypto destroyin ur recordz.";
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче