mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 547048 - Only allow clients to issue delete records [r=mconnor]
Don't specially serialize/not encrypt delete records and store the deleted flag as part of the cleartext payload.
This commit is contained in:
parent
e057d3a639
commit
6e5b14f642
@ -56,10 +56,6 @@ CryptoWrapper.prototype = {
|
||||
_logName: "Record.CryptoWrapper",
|
||||
|
||||
encrypt: function CryptoWrapper_encrypt(passphrase) {
|
||||
// No need to encrypt deleted records
|
||||
if (this.deleted)
|
||||
return;
|
||||
|
||||
let pubkey = PubKeys.getDefaultKey();
|
||||
let privkey = PrivKeys.get(pubkey.privateKeyUri);
|
||||
|
||||
@ -72,10 +68,6 @@ CryptoWrapper.prototype = {
|
||||
},
|
||||
|
||||
decrypt: function CryptoWrapper_decrypt(passphrase) {
|
||||
// Deleted records aren't encrypted
|
||||
if (this.deleted)
|
||||
return;
|
||||
|
||||
let pubkey = PubKeys.getDefaultKey();
|
||||
let privkey = PrivKeys.get(pubkey.privateKeyUri);
|
||||
|
||||
@ -111,6 +103,7 @@ CryptoWrapper.prototype = {
|
||||
};
|
||||
|
||||
Utils.deferGetSet(CryptoWrapper, "payload", ["encryption", "ciphertext"]);
|
||||
Utils.deferGetSet(CryptoWrapper, "cleartext", "deleted");
|
||||
|
||||
function CryptoMeta(uri) {
|
||||
WBORecord.call(this, uri);
|
||||
|
@ -52,7 +52,6 @@ function WBORecord(uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
WBORecord.prototype = {
|
||||
deleted: false,
|
||||
_logName: "Record.WBO",
|
||||
|
||||
// NOTE: baseUri must have a trailing slash, or baseUri.resolve() will omit
|
||||
@ -77,20 +76,18 @@ WBORecord.prototype = {
|
||||
deserialize: function deserialize(json) {
|
||||
this.data = json.constructor.toString() == String ? JSON.parse(json) : json;
|
||||
|
||||
// Empty string payloads are deleted records
|
||||
if (this.payload === "")
|
||||
this.deleted = true;
|
||||
else
|
||||
try {
|
||||
// The payload is likely to be JSON, but if not, keep it as a string
|
||||
this.payload = JSON.parse(this.payload);
|
||||
}
|
||||
catch(ex) {}
|
||||
},
|
||||
|
||||
toJSON: function toJSON() {
|
||||
// Copy fields from data to except payload which needs to be a string
|
||||
// Copy fields from data to be stringified, making sure payload is a string
|
||||
let obj = {};
|
||||
for (let [key, val] in Iterator(this.data))
|
||||
if (key != "payload")
|
||||
obj[key] = val;
|
||||
obj.payload = this.deleted ? "" : JSON.stringify(this.payload);
|
||||
obj[key] = key == "payload" ? JSON.stringify(val) : val;
|
||||
return obj;
|
||||
},
|
||||
|
||||
@ -98,7 +95,7 @@ WBORecord.prototype = {
|
||||
"id: " + this.id,
|
||||
"index: " + this.sortindex,
|
||||
"modified: " + this.modified,
|
||||
"payload: " + (this.deleted ? "DELETED" : JSON.stringify(this.payload))
|
||||
"payload: " + JSON.stringify(this.payload)
|
||||
].join("\n ") + " }",
|
||||
};
|
||||
|
||||
|
@ -514,8 +514,7 @@ SyncEngine.prototype = {
|
||||
let local = this._createRecord(item.id);
|
||||
if (this._log.level <= Log4Moz.Level.Trace)
|
||||
this._log.trace("Local record: " + local);
|
||||
if (item.deleted == local.deleted &&
|
||||
Utils.deepEquals(item.cleartext, local.cleartext)) {
|
||||
if (Utils.deepEquals(item.cleartext, local.cleartext)) {
|
||||
this._log.trace("Local record is the same");
|
||||
return true;
|
||||
} else {
|
||||
|
@ -7,13 +7,13 @@ function run_test() {
|
||||
let stream = { _data: "" };
|
||||
let called, recCount, sum;
|
||||
|
||||
_("Parse empty string payload as deleted");
|
||||
_("Not-JSON, string payloads are strings");
|
||||
called = false;
|
||||
stream._data = '{"payload":""}\n';
|
||||
stream._data = '{"payload":"hello"}\n';
|
||||
coll.recordHandler = function(rec) {
|
||||
called = true;
|
||||
_("Got record:", JSON.stringify(rec));
|
||||
do_check_true(rec.deleted);
|
||||
do_check_eq(rec.payload, "hello");
|
||||
};
|
||||
coll._onProgress.call(stream);
|
||||
do_check_eq(stream._data, '');
|
||||
|
Loading…
Reference in New Issue
Block a user