Bug 1164821 - Remove previous workarounds for not having FxA keys in LoopRooms - remove old code to cope with unencrypted rooms. r=mikedeboer

This commit is contained in:
Mark Banner 2015-05-20 14:15:20 +01:00
parent 445e6ab9c5
commit 66e9730e7b
4 changed files with 28 additions and 57 deletions

View File

@ -29,6 +29,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "loopUtils",
"resource:///modules/loop/utils.js", "utils");
XPCOMUtils.defineLazyModuleGetter(this, "loopCrypto",
"resource:///modules/loop/crypto.js", "LoopCrypto");
XPCOMUtils.defineLazyModuleGetter(this, "ObjectUtils",
"resource://gre/modules/ObjectUtils.jsm");
this.EXPORTED_SYMBOLS = ["LoopRooms", "roomsPushNotification"];
@ -310,24 +312,12 @@ let LoopRoomsInternal = {
* any decrypted data.
* - all: The roomData with both encrypted and decrypted
* information.
* If rejected, encryption has failed. This could be due to
* missing keys for FxA, which this process can't manage. It
* is generally expected the panel will prompt the user for
* re-auth if the FxA keys are missing.
*/
promiseEncryptRoomData: Task.async(function* (roomData) {
// XXX We should only return unencrypted data whilst we're still working
// on context. Once bug 1115340 is fixed, this function should no longer be
// here.
function getUnencryptedData() {
var serverRoomData = extend({}, roomData);
delete serverRoomData.decryptedContext;
// We can only save roomName as non-encypted data for now.
serverRoomData.roomName = roomData.decryptedContext.roomName;
return {
all: roomData,
encrypted: serverRoomData
};
}
var newRoomData = extend({}, roomData);
if (!newRoomData.context) {
@ -337,17 +327,7 @@ let LoopRoomsInternal = {
// First get the room key.
let key = yield this.promiseGetOrCreateRoomKey(newRoomData);
try {
newRoomData.context.wrappedKey = yield this.promiseEncryptedRoomKey(key);
}
catch (ex) {
// XXX Bug 1153788 should remove this, then we can remove the whole
// try/catch.
if (ex.message == "FxA re-register not implemented") {
return getUnencryptedData();
}
return Promise.reject(ex);
}
newRoomData.context.wrappedKey = yield this.promiseEncryptedRoomKey(key);
// Now encrypt the actual data.
newRoomData.context.value = yield loopCrypto.encryptBytes(key,
@ -461,9 +441,7 @@ let LoopRoomsInternal = {
// We don't do anything with roomUrl here as it doesn't need a key
// string adding at this stage.
// No encrypted data, use the old roomName field.
// XXX Bug 1152764 will add functions for automatically encrypting the room
// name.
// No encrypted data yet, use the old roomName field.
room.decryptedContext = {
roomName: room.roomName
};
@ -475,7 +453,11 @@ let LoopRoomsInternal = {
this.saveAndNotifyUpdate(room, isUpdate);
} else {
// XXX Don't decrypt if same?
// We could potentially optimise this later by not decrypting if the
// encrypted context hasn't already changed. However perf doesn't seem
// to be too bigger an issue at the moment, so we just decrypt for now.
// If we do change this, then we need to make sure we get the new room
// data setup properly, as happens at the end of promiseDecryptRoomData.
try {
let roomData = yield this.promiseDecryptRoomData(room);
@ -851,17 +833,9 @@ let LoopRoomsInternal = {
context: encrypted.context
};
// If we're not encrypting currently, then only send the roomName.
// XXX This should go away once bug 1153788 is fixed.
if (!sendData.context) {
sendData = {
roomName: room.decryptedContext.roomName
};
} else {
// This might be an upgrade to encrypted rename, so store the key
// just in case.
yield this.roomsCache.setKey(this.sessionType, all.roomToken, all.roomKey);
}
// This might be an upgrade to encrypted rename, so store the key
// just in case.
yield this.roomsCache.setKey(this.sessionType, all.roomToken, all.roomKey);
let response = yield MozLoopService.hawkRequest(this.sessionType,
url, "PATCH", sendData);

View File

@ -1349,9 +1349,10 @@ this.MozLoopService = {
return;
}
// XXX If we don't have a key for FxA yet, then simply reject for now.
// We'll create some sign-in/sign-out UX in bug 1153788.
reject(new Error("FxA re-register not implemented"));
// This should generally never happen, but its not really possible
// for us to force reauth from here in a sensible way for the user.
// So we'll just have to flag it the best we can.
reject(new Error("No FxA key available"));
return;
}

View File

@ -13,14 +13,14 @@ timerHandlers.startTimer = callback => callback();
let openChatOrig = Chat.open;
const kGuestKey = "uGIs-kGbYt1hBBwjyW7MLQ";
const kKey = "uGIs-kGbYt1hBBwjyW7MLQ";
// Rooms details as responded by the server.
const kRoomsResponses = new Map([
["_nxD4V4FflQ", {
roomToken: "_nxD4V4FflQ",
// Encrypted with roomKey "FliIGLUolW-xkKZVWstqKw".
// roomKey is wrapped with kGuestKey.
// roomKey is wrapped with kKey.
context: {
wrappedKey: "F3V27oPB+FgjFbVPML2PupONYqoIZ53XRU4BqG46Lr3eyIGumgCEqgjSe/MXAXiQ//8=",
value: "df7B4SNxhOI44eJjQavCevADyCCxz6/DEZbkOkRUMVUxzS42FbzN6C2PqmCKDYUGyCJTwJ0jln8TLw==",
@ -306,12 +306,7 @@ add_task(function* setup_server() {
room.deleted = kRoomUpdates[qs.version].deleted;
res.write(JSON.stringify([room]));
} else {
// XXX Only return last 2 elements until FxA keys are implemented.
if (MozLoopServiceInternal.fxAOAuthTokenData) {
res.write(JSON.stringify([...kRoomsResponses.values()].slice(1, 3)));
} else {
res.write(JSON.stringify([...kRoomsResponses.values()]));
}
res.write(JSON.stringify([...kRoomsResponses.values()]));
}
}
@ -433,8 +428,7 @@ add_task(function* test_openRoom() {
// Test if the rooms cache is refreshed after FxA signin or signout.
add_task(function* test_refresh() {
// XXX Temporarily whilst FxA encryption isn't handled (bug 1153788).
Array.prototype.push.apply(gExpectedAdds, [...kExpectedRooms.values()].slice(1, 3));
gExpectedAdds.push(...kExpectedRooms.values());
gExpectedRefresh = true;
// Make the switch.
@ -443,6 +437,7 @@ add_task(function* test_refresh() {
email: "fake@invalid.com",
uid: "fake"
};
Services.prefs.setCharPref("loop.key.fxa", kKey);
yield waitForCondition(() => !gExpectedRefresh);
yield waitForCondition(() => gExpectedAdds.length === 0);
@ -641,7 +636,7 @@ add_task(function* () {
function run_test() {
setupFakeLoopServer();
Services.prefs.setCharPref("loop.key", kGuestKey);
Services.prefs.setCharPref("loop.key", kKey);
LoopRooms.on("add", onRoomAdded);
LoopRooms.on("update", onRoomUpdated);
@ -654,6 +649,7 @@ function run_test() {
// Revert original Chat.open implementation
Chat.open = openChatOrig;
Services.prefs.clearUserPref("loop.key");
Services.prefs.clearUserPref("loop.key.fxa");
MozLoopServiceInternal.fxAOAuthTokenData = null;
MozLoopServiceInternal.fxAOAuthProfile = null;

View File

@ -57,7 +57,7 @@ add_task(function* test_fxaGetKey() {
// Currently unimplemented, add a test when we implement the code.
yield Assert.rejects(MozLoopService.promiseProfileEncryptionKey(),
/not implemented/, "should reject as unimplemented");
/No FxA key available/, "should reject as not available");
});
add_task(function test_hasEncryptionKey() {