summaryrefslogtreecommitdiff
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2013-04-26 09:18:23 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2013-04-26 09:18:23 (UTC)
commit108dd23db8fdc9512446be708d2694f3050b1d8f (patch) (unidiff)
treefeff31a273898aa20d13673947457a87024e457e
parent65f064cb6c99dde320d49e6c4157607c25e2d092 (diff)
downloadclipperz-108dd23db8fdc9512446be708d2694f3050b1d8f.zip
clipperz-108dd23db8fdc9512446be708d2694f3050b1d8f.tar.gz
clipperz-108dd23db8fdc9512446be708d2694f3050b1d8f.tar.bz2
Fixed a bug that would "corrupt" header data when upgrading the crypto version used to process an account data
The problem being that only part of the header section would be re-encrypted, thus ending up with different sections encrypted using different crypto function versions. And this would break when loading data back on next login.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/Header.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Header.js b/frontend/beta/js/Clipperz/PM/DataModel/Header.js
index 908d9f4..d577830 100644
--- a/frontend/beta/js/Clipperz/PM/DataModel/Header.js
+++ b/frontend/beta/js/Clipperz/PM/DataModel/Header.js
@@ -52,65 +52,66 @@ Clipperz.PM.DataModel.Header = function(args) {
52 52
53Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { 53Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, {
54 54
55 //------------------------------------------------------------------------- 55 //-------------------------------------------------------------------------
56 56
57 'user': function() { 57 'user': function() {
58 return this._user; 58 return this._user;
59 }, 59 },
60 60
61 //------------------------------------------------------------------------- 61 //-------------------------------------------------------------------------
62 //------------------------------------------------------------------------- 62 //-------------------------------------------------------------------------
63 //------------------------------------------------------------------------- 63 //-------------------------------------------------------------------------
64 //------------------------------------------------------------------------- 64 //-------------------------------------------------------------------------
65 //------------------------------------------------------------------------- 65 //-------------------------------------------------------------------------
66 //------------------------------------------------------------------------- 66 //-------------------------------------------------------------------------
67 //------------------------------------------------------------------------- 67 //-------------------------------------------------------------------------
68 //------------------------------------------------------------------------- 68 //-------------------------------------------------------------------------
69 //------------------------------------------------------------------------- 69 //-------------------------------------------------------------------------
70 70
71 'updatedSections': function() { 71 'updatedSections': function() {
72 return this._updatedSections; 72 return this._updatedSections;
73 }, 73 },
74 74
75 'markSectionAsUpdated': function(aSectionName) { 75 'markSectionAsUpdated': function(aSectionName) {
76 this.updatedSections().push(aSectionName); 76 this.updatedSections().push(aSectionName);
77 }, 77 },
78 78
79 'resetUpdatedSections': function() { 79 'resetUpdatedSections': function() {
80 this._updatedSections = [] 80 this._updatedSections = []
81 }, 81 },
82 82
83 'hasSectionBeenUpdated': function(aSectionName) { 83 'hasSectionBeenUpdated': function(aSectionName) {
84 return (this.updatedSections().join().indexOf(aSectionName) != -1); 84 return(this.updatedSections().join().indexOf(aSectionName) != -1)
85 ||(this.serverDataVersion() != Clipperz.PM.Crypto.encryptingFunctions.currentVersion);
85 }, 86 },
86 87
87 'cachedServerDataSection': function(aSectionName) { 88 'cachedServerDataSection': function(aSectionName) {
88 return (this.hasSectionBeenUpdated(aSectionName)) ? {} : this.jsonEvaledServerData()[aSectionName]; 89 return (this.hasSectionBeenUpdated(aSectionName)) ? {} : this.jsonEvaledServerData()[aSectionName];
89 }, 90 },
90 91
91 'updateAllSections': function() { 92 'updateAllSections': function() {
92 this.resetUpdatedSections(); 93 this.resetUpdatedSections();
93 this.markSectionAsUpdated('records'); 94 this.markSectionAsUpdated('records');
94 this.markSectionAsUpdated('directLogins'); 95 this.markSectionAsUpdated('directLogins');
95 this.markSectionAsUpdated('preferences'); 96 this.markSectionAsUpdated('preferences');
96 this.markSectionAsUpdated('oneTimePasswords'); 97 this.markSectionAsUpdated('oneTimePasswords');
97 98
98 return MochiKit.Async.succeed(this); 99 return MochiKit.Async.succeed(this);
99 }, 100 },
100 101
101 'updatedSectionHandler': function(anEvent) { 102 'updatedSectionHandler': function(anEvent) {
102 this.markSectionAsUpdated(anEvent.parameters()); 103 this.markSectionAsUpdated(anEvent.parameters());
103 }, 104 },
104 105
105 //------------------------------------------------------------------------- 106 //-------------------------------------------------------------------------
106 107
107 'getObjectKeyIndex': function(anObject) { 108 'getObjectKeyIndex': function(anObject) {
108 var result; 109 var result;
109 varitemReference; 110 varitemReference;
110 var index; 111 var index;
111 112
112 result = {}; 113 result = {};
113 index = 0; 114 index = 0;
114 115
115 for (itemReference in anObject) { 116 for (itemReference in anObject) {
116 result[itemReference] = index.toString(); 117 result[itemReference] = index.toString();
@@ -383,64 +384,65 @@ Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, {
383 384
384 //------------------------------------------------------------------------- 385 //-------------------------------------------------------------------------
385 386
386 'extractDataWithKey': function(aKey) { 387 'extractDataWithKey': function(aKey) {
387 var deferredResult; 388 var deferredResult;
388 389
389//MochiKit.Logging.logDebug(">>> Header.extractDataWithKey"); 390//MochiKit.Logging.logDebug(">>> Header.extractDataWithKey");
390 deferredResult = new MochiKit.Async.Deferred(); 391 deferredResult = new MochiKit.Async.Deferred();
391 392
392 switch (this.serverDataFormat()) { 393 switch (this.serverDataFormat()) {
393 case 'LEGACY': 394 case 'LEGACY':
394//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 1: "/* + res*/); return res;}); 395//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 1: "/* + res*/); return res;});
395//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); 396//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
396 deferredResult.addCallback(MochiKit.Base.method(this, 'decryptedLegacyServerData')); 397 deferredResult.addCallback(MochiKit.Base.method(this, 'decryptedLegacyServerData'));
397//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 2: "/* + res*/); return res;}); 398//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 2: "/* + res*/); return res;});
398//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); 399//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
399 deferredResult.addCallback(function(someDecryptedValues) { 400 deferredResult.addCallback(function(someDecryptedValues) {
400 return someDecryptedValues[aKey] || {}; 401 return someDecryptedValues[aKey] || {};
401 }) 402 })
402//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 3: "/* + res*/); return res;}); 403//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 3: "/* + res*/); return res;});
403//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); 404//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
404 break; 405 break;
405 case '0.1': 406 case '0.1':
406 var data; 407 var data;
407 408
408 //# data = Clipperz.Base.evalJSON(this.serverData()); 409 //# data = Clipperz.Base.evalJSON(this.serverData());
409 data = this.jsonEvaledServerData(); 410 data = this.jsonEvaledServerData();
410 if (typeof(data[aKey]) != 'undefined') { 411 if (typeof(data[aKey]) != 'undefined') {
411//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 4: "/* + res*/); return res;}); 412//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 4: "/* + res*/); return res;});
412//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); 413//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
413 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_decryptingUserData'); 414 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_decryptingUserData');
414//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 5: "/* + res*/); return res;}); 415//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 5: "/* + res*/); return res;});
416//deferredResult.addBoth(function(res) {console.log("aKey: " + aKey); return res;});
415//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); 417//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
416 deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.user().passphrase(), data[aKey]['data'], this.serverDataVersion()); 418 deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.user().passphrase(), data[aKey]['data'], this.serverDataVersion());
417//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;}); 419//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;});
418//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); 420//deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;});
419 deferredResult.addCallback(function(/*anHeader,*/ aKey, aData, aRecordIndex, aValue) { 421 deferredResult.addCallback(function(/*anHeader,*/ aKey, aData, aRecordIndex, aValue) {
420 var result; 422 var result;
421//MochiKit.Logging.logDebug(">>> [start] ==============================================="); 423//MochiKit.Logging.logDebug(">>> [start] ===============================================");
422//MochiKit.Logging.logDebug("--- extractDataWithKey - 0 [" + aKey + "]: " + Clipperz.Base.serializeJSON(aValue)); 424//MochiKit.Logging.logDebug("--- extractDataWithKey - 0 [" + aKey + "]: " + Clipperz.Base.serializeJSON(aValue));
423//MochiKit.Logging.logDebug("<<< [end] ================================================="); 425//MochiKit.Logging.logDebug("<<< [end] =================================================");
424 if (aKey == 'records') { 426 if (aKey == 'records') {
425 var recordKey; 427 var recordKey;
426 428
427 result = {}; 429 result = {};
428 for (recordKey in aData['index']) { 430 for (recordKey in aData['index']) {
429 result[recordKey] = aValue[aData['index'][recordKey]]; 431 result[recordKey] = aValue[aData['index'][recordKey]];
430 } 432 }
431 } else if (aKey == 'directLogins') { 433 } else if (aKey == 'directLogins') {
432 varrecordKeyReversedIndex; 434 varrecordKeyReversedIndex;
433 var recordKey; 435 var recordKey;
434 var directLoginKey; 436 var directLoginKey;
435 437
436 result = {}; 438 result = {};
437 recordKeyReversedIndex = {}; 439 recordKeyReversedIndex = {};
438 440
439 for (recordKey in aRecordIndex) { 441 for (recordKey in aRecordIndex) {
440 recordKeyReversedIndex[aRecordIndex[recordKey]] = recordKey; 442 recordKeyReversedIndex[aRecordIndex[recordKey]] = recordKey;
441 } 443 }
442 444
443//MochiKit.Logging.logDebug("--- extractDataWithKey - 1 - aData['index']: " + Clipperz.Base.serializeJSON(aData['index'])); 445//MochiKit.Logging.logDebug("--- extractDataWithKey - 1 - aData['index']: " + Clipperz.Base.serializeJSON(aData['index']));
444 for (directLoginKey in aData['index']) { 446 for (directLoginKey in aData['index']) {
445try { 447try {
446 if ((aData['index'][directLoginKey] != null) && (aValue[aData['index'][directLoginKey]] != null)) { 448 if ((aData['index'][directLoginKey] != null) && (aValue[aData['index'][directLoginKey]] != null)) {