author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-19 15:09:28 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-19 15:09:28 (UTC) |
commit | 074e70457c90344b3c1cb236105638d692a0066b (patch) (unidiff) | |
tree | c5ffabd3eaf74cbeb69974beacdb5a5f8c235adc /frontend/gamma/js/Clipperz/PM | |
parent | 48c9280c9a255f2a85ad5729830df884e64a9c5d (diff) | |
download | clipperz-074e70457c90344b3c1cb236105638d692a0066b.zip clipperz-074e70457c90344b3c1cb236105638d692a0066b.tar.gz clipperz-074e70457c90344b3c1cb236105638d692a0066b.tar.bz2 |
Fixed an issue on the AES-CTR block mode
The previous version of the CTR encoding was incrementing the counter in a weird way, mixing up data from the previous block.
The current fix can correctly decrypt data encoded with AES-CTR using other libraries/languages (currently tested only with Python).
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM') (more/less context) (ignore whitespace changes)
4 files changed, 81 insertions, 38 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Crypto.js b/frontend/gamma/js/Clipperz/PM/Crypto.js index cd10e33..7edf17f 100644 --- a/frontend/gamma/js/Clipperz/PM/Crypto.js +++ b/frontend/gamma/js/Clipperz/PM/Crypto.js | |||
@@ -39,49 +39,49 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
39 | //------------------------------------------------------------------------- | 39 | //------------------------------------------------------------------------- |
40 | 40 | ||
41 | 'toString': function () { | 41 | 'toString': function () { |
42 | return this.__repr__(); | 42 | return this.__repr__(); |
43 | }, | 43 | }, |
44 | 44 | ||
45 | //------------------------------------------------------------------------- | 45 | //------------------------------------------------------------------------- |
46 | /* | 46 | /* |
47 | 'communicationProtocol': { | 47 | 'communicationProtocol': { |
48 | 'currentVersion': '0.2', | 48 | 'currentVersion': '0.2', |
49 | 'versions': { | 49 | 'versions': { |
50 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, | 50 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, |
51 | '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection | 51 | '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection |
52 | }, | 52 | }, |
53 | 'fallbackVersions': { | 53 | 'fallbackVersions': { |
54 | 'current':'0.1', | 54 | 'current':'0.1', |
55 | '0.2': '0.1', | 55 | '0.2': '0.1', |
56 | '0.1': null | 56 | '0.1': null |
57 | } | 57 | } |
58 | }, | 58 | }, |
59 | */ | 59 | */ |
60 | //------------------------------------------------------------------------- | 60 | //------------------------------------------------------------------------- |
61 | 61 | ||
62 | 'encryptingFunctions': { | 62 | 'encryptingFunctions': { |
63 | 'currentVersion': '0.3', | 63 | 'currentVersion': '0.4', |
64 | 'versions': { | 64 | 'versions': { |
65 | 65 | ||
66 | //##################################################################### | 66 | //##################################################################### |
67 | 67 | ||
68 | '0.1': { | 68 | '0.1': { |
69 | 'encrypt': function(aKey, aValue) { | 69 | 'encrypt': function(aKey, aValue) { |
70 | return Clipperz.Crypto.Base.encryptUsingSecretKey(aKey, Clipperz.Base.serializeJSON(aValue)); | 70 | return Clipperz.Crypto.Base.encryptUsingSecretKey(aKey, Clipperz.Base.serializeJSON(aValue)); |
71 | }, | 71 | }, |
72 | 72 | ||
73 | 'deferredEncrypt': function(aKey, aValue) { | 73 | 'deferredEncrypt': function(aKey, aValue) { |
74 | var deferredResult; | 74 | var deferredResult; |
75 | 75 | ||
76 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.1].deferredEncrypt"); | 76 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.1].deferredEncrypt"); |
77 | deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].encrypt, aKey, aValue); | 77 | deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].encrypt, aKey, aValue); |
78 | deferredResult.callback(); | 78 | deferredResult.callback(); |
79 | 79 | ||
80 | return deferredResult; | 80 | return deferredResult; |
81 | }, | 81 | }, |
82 | 82 | ||
83 | 'decrypt': function(aKey, aValue) { | 83 | 'decrypt': function(aKey, aValue) { |
84 | var result; | 84 | var result; |
85 | 85 | ||
86 | if (aValue != null) { | 86 | if (aValue != null) { |
87 | result = Clipperz.Base.evalJSON(Clipperz.Crypto.Base.decryptUsingSecretKey(aKey, aValue)); | 87 | result = Clipperz.Base.evalJSON(Clipperz.Crypto.Base.decryptUsingSecretKey(aKey, aValue)); |
@@ -299,149 +299,187 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
299 | return result; | 299 | return result; |
300 | }, | 300 | }, |
301 | 301 | ||
302 | 'deferredDecrypt': function(aKey, aValue) { | 302 | 'deferredDecrypt': function(aKey, aValue) { |
303 | var deferredResult; | 303 | var deferredResult; |
304 | 304 | ||
305 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredDecrypt", {trace: false}); | 305 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredDecrypt", {trace: false}); |
306 | // now = new Date; | 306 | // now = new Date; |
307 | 307 | ||
308 | if (aValue != null) { | 308 | if (aValue != null) { |
309 | var key, value; | 309 | var key, value; |
310 | // var decryptedData; | 310 | // var decryptedData; |
311 | 311 | ||
312 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 312 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
313 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 313 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
314 | 314 | ||
315 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); | 315 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); |
316 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | 316 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); |
317 | deferredResult.addCallback(function(aResult) { | 317 | deferredResult.addCallback(function(aResult) { |
318 | return aResult.asString(); | 318 | return aResult.asString(); |
319 | }); | 319 | }); |
320 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | 320 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); |
321 | deferredResult.addCallback(Clipperz.Base.evalJSON); | 321 | deferredResult.addCallback(Clipperz.Base.evalJSON); |
322 | deferredResult.addErrback(function(anError) { | 322 | deferredResult.addErrback(function(anError) { |
323 | console.log("PIPPO_1", anError) | ||
323 | Clipperz.logError("Error while decrypting data [4]"); | 324 | Clipperz.logError("Error while decrypting data [4]"); |
324 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 325 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
325 | }) | 326 | }) |
326 | } else { | 327 | } else { |
327 | deferredResult.addCallback(function() { | 328 | deferredResult.addCallback(function() { |
328 | return null; | 329 | return null; |
329 | }); | 330 | }); |
330 | } | 331 | } |
331 | deferredResult.callback(); | 332 | deferredResult.callback(); |
332 | 333 | ||
333 | return deferredResult; | 334 | return deferredResult; |
334 | }, | 335 | }, |
335 | 336 | ||
336 | 'hash': Clipperz.Crypto.SHA.sha_d256, | 337 | 'hash': Clipperz.Crypto.SHA.sha_d256, |
337 | 338 | ||
338 | 'deriveKey': function(aStringValue) { | 339 | 'deriveKey': function(aStringValue) { |
339 | varbyteData; | 340 | varbyteData; |
340 | var result; | 341 | var result; |
341 | 342 | ||
342 | byteData = new Clipperz.ByteArray(aStringValue); | 343 | byteData = new Clipperz.ByteArray(aStringValue); |
343 | result = Clipperz.Crypto.SHA.sha_d256(byteData); | 344 | result = Clipperz.Crypto.SHA.sha_d256(byteData); |
344 | 345 | ||
345 | return result; | 346 | return result; |
346 | } | 347 | } |
347 | |||
348 | }, | 348 | }, |
349 | 349 | ||
350 | //##################################################################### | 350 | //##################################################################### |
351 | /* | 351 | |
352 | '0.4': { | 352 | '0.4': { |
353 | 'encrypt': function(aKey, aValue, aNonce) { | 353 | 'encrypt': function(aKey, aValue, aNonce) { |
354 | var result; | 354 | var result; |
355 | varkey, value; | 355 | varkey, value; |
356 | var data; | 356 | var data; |
357 | var dataToEncrypt; | 357 | var dataToEncrypt; |
358 | var encryptedData; | 358 | var encryptedData; |
359 | 359 | ||
360 | //Clipperz.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | ||
361 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 360 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
362 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1"); | ||
363 | value = Clipperz.Base.serializeJSON(aValue); | 361 | value = Clipperz.Base.serializeJSON(aValue); |
364 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2"); | ||
365 | / * | ||
366 | //Clipperz.logDebug("--> encrypt.fullSize: " + value.length); | ||
367 | value = value.replace(/":{"label":"/g, '":{l:"'); | ||
368 | value = value.replace(/":{"key":"/g, '":{k:"'); | ||
369 | value = value.replace(/":{"notes":"/g, '":{n:"'); | ||
370 | value = value.replace(/":{"record":"/g, '":{r:"'); | ||
371 | value = value.replace(/", "label":"/g, '",l:"'); | ||
372 | value = value.replace(/", "favicon":"/g,'",f:"'); | ||
373 | //Clipperz.logDebug("<-- encrypt.compressed: " + value.length); | ||
374 | * / | ||
375 | data = new Clipperz.ByteArray(value); | 362 | data = new Clipperz.ByteArray(value); |
376 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3"); | 363 | encryptedData = Clipperz.Crypto.AES_2.encrypt(key, data, aNonce); |
377 | encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); | ||
378 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4"); | ||
379 | result = encryptedData.toBase64String(); | 364 | result = encryptedData.toBase64String(); |
380 | //Clipperz.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | ||
381 | 365 | ||
382 | return result; | 366 | return result; |
383 | }, | 367 | }, |
368 | |||
369 | 'deferredEncrypt': function(aKey, aValue, aNonce) { | ||
370 | var deferredResult; | ||
371 | varkey, value; | ||
372 | var data; | ||
373 | var dataToEncrypt; | ||
374 | var encryptedData; | ||
375 | |||
376 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | ||
377 | value = Clipperz.Base.serializeJSON(aValue); | ||
378 | data = new Clipperz.ByteArray(value); | ||
379 | |||
380 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredEncrypt") | ||
381 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncrypt, key, data, aNonce); | ||
382 | deferredResult.addCallback(function(aResult) { | ||
383 | return aResult.toBase64String(); | ||
384 | }) | ||
385 | deferredResult.callback(); | ||
386 | |||
387 | return deferredResult; | ||
388 | }, | ||
384 | 389 | ||
385 | 'decrypt': function(aKey, aValue) { | 390 | 'decrypt': function(aKey, aValue) { |
386 | var result; | 391 | var result; |
387 | 392 | ||
388 | if (aValue != null) { | 393 | if (aValue != null) { |
389 | var key, value; | 394 | var key, value; |
390 | var decryptedData; | 395 | var decryptedData; |
391 | 396 | ||
392 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 397 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
393 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 398 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
394 | 399 | ||
395 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); | 400 | decryptedData = Clipperz.Crypto.AES_2.decrypt(key, value); |
396 | 401 | ||
397 | value = decryptedData.asString(); | 402 | value = decryptedData.asString(); |
398 | / * | ||
399 | value = value.replace(/":{l:"/g,'":{"label":"'); | ||
400 | value = value.replace(/":{k:"/g,'":{"key":"'); | ||
401 | value = value.replace(/":{n:"/g,'":{"notes":"'); | ||
402 | value = value.replace(/":{r:"/g,'":{"record":"'); | ||
403 | value = value.replace(/",l:"/g, '", "label":"'); | ||
404 | value = value.replace(/",f:"/g, '", "favicon":"'); | ||
405 | * / | ||
406 | try { | 403 | try { |
407 | result = Clipperz.Base.evalJSON(value); | 404 | result = Clipperz.Base.evalJSON(value); |
408 | } catch (exception) { | 405 | } catch (exception) { |
409 | Clipperz.logError("Error while decrypting data"); | 406 | console.log("PIPPO_2", anError) |
407 | Clipperz.logError("Error while decrypting data [4]"); | ||
410 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 408 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
411 | } | 409 | } |
412 | |||
413 | |||
414 | } else { | 410 | } else { |
415 | result = null; | 411 | result = null; |
416 | } | 412 | } |
417 | 413 | ||
418 | return result; | 414 | return result; |
419 | }, | 415 | }, |
420 | 416 | ||
421 | 'hash': Clipperz.Crypto.SHA.sha_d256 | 417 | 'deferredDecrypt': function(aKey, aValue) { |
418 | var deferredResult; | ||
419 | |||
420 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredDecrypt", {trace: false}); | ||
421 | |||
422 | if (aValue != null) { | ||
423 | var key, value; | ||
424 | |||
425 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | ||
426 | value = new Clipperz.ByteArray().appendBase64String(aValue); | ||
427 | |||
428 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value); | ||
429 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | ||
430 | deferredResult.addCallback(function(aResult) { | ||
431 | return aResult.asString(); | ||
432 | }); | ||
433 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | ||
434 | deferredResult.addCallback(Clipperz.Base.evalJSON); | ||
435 | deferredResult.addErrback(function(anError) { | ||
436 | Clipperz.logError("Error while decrypting data [4]"); | ||
437 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | ||
438 | }) | ||
439 | } else { | ||
440 | deferredResult.addCallback(function() { | ||
441 | return null; | ||
442 | }); | ||
443 | } | ||
444 | deferredResult.callback(); | ||
445 | |||
446 | return deferredResult; | ||
447 | }, | ||
448 | |||
449 | 'hash': Clipperz.Crypto.SHA.sha_d256, | ||
450 | |||
451 | 'deriveKey': function(aStringValue) { | ||
452 | varbyteData; | ||
453 | var result; | ||
454 | |||
455 | byteData = new Clipperz.ByteArray(aStringValue); | ||
456 | result = Clipperz.Crypto.SHA.sha_d256(byteData); | ||
457 | |||
458 | return result; | ||
459 | } | ||
422 | }, | 460 | }, |
423 | */ | 461 | |
424 | //##################################################################### | 462 | //##################################################################### |
425 | __syntaxFix__: "syntax fix" | 463 | __syntaxFix__: "syntax fix" |
426 | } | 464 | } |
427 | }, | 465 | }, |
428 | 466 | ||
429 | //------------------------------------------------------------------------- | 467 | //------------------------------------------------------------------------- |
430 | 468 | ||
431 | 'encrypt': function(aKey, aValue, aVersion) { | 469 | 'encrypt': function(aKey, aValue, aVersion) { |
432 | return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].encrypt(aKey, aValue); | 470 | return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].encrypt(aKey, aValue); |
433 | }, | 471 | }, |
434 | 472 | ||
435 | 'deferredEncrypt': function(someParameters) { | 473 | 'deferredEncrypt': function(someParameters) { |
436 | return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredEncrypt(someParameters['key'], someParameters['value']); | 474 | return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredEncrypt(someParameters['key'], someParameters['value']); |
437 | }, | 475 | }, |
438 | 476 | ||
439 | //......................................................................... | 477 | //......................................................................... |
440 | 478 | ||
441 | 'decrypt': function(aKey, aValue, aVersion) { | 479 | 'decrypt': function(aKey, aValue, aVersion) { |
442 | return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].decrypt(aKey, aValue); | 480 | return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].decrypt(aKey, aValue); |
443 | }, | 481 | }, |
444 | 482 | ||
445 | 'deferredDecrypt': function(someParameters) { | 483 | 'deferredDecrypt': function(someParameters) { |
446 | return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredDecrypt(someParameters['key'], someParameters['value']); | 484 | return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredDecrypt(someParameters['key'], someParameters['value']); |
447 | }, | 485 | }, |
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.js index fd18faf..b94fe4c 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.js | |||
@@ -705,50 +705,50 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { | |||
705 | return MochiKit.Async.succeed(MochiKit.Base.keys(this.transientState()).length != 0); | 705 | return MochiKit.Async.succeed(MochiKit.Base.keys(this.transientState()).length != 0); |
706 | }, this) | 706 | }, this) |
707 | }); | 707 | }); |
708 | deferredResult.addCallback(Clipperz.Async.or); | 708 | deferredResult.addCallback(Clipperz.Async.or); |
709 | deferredResult.callback(); | 709 | deferredResult.callback(); |
710 | 710 | ||
711 | return deferredResult; | 711 | return deferredResult; |
712 | }, | 712 | }, |
713 | 713 | ||
714 | //========================================================================= | 714 | //========================================================================= |
715 | 715 | ||
716 | 'prepareRemoteDataWithKey': function (aKey /*, aCurrentKey*/) { | 716 | 'prepareRemoteDataWithKey': function (aKey /*, aCurrentKey*/) { |
717 | var deferredResult; | 717 | var deferredResult; |
718 | varresult; | 718 | varresult; |
719 | 719 | ||
720 | result = {}; | 720 | result = {}; |
721 | deferredResult = new Clipperz.Async.Deferred("User.prepareRemoteDataWithKey", {trace:false}); | 721 | deferredResult = new Clipperz.Async.Deferred("User.prepareRemoteDataWithKey", {trace:false}); |
722 | deferredResult.addMethod(this, 'invokeMethodNamedOnHeader', 'prepareRemoteDataWithKey', aKey /*, aCurrentKey*/); | 722 | deferredResult.addMethod(this, 'invokeMethodNamedOnHeader', 'prepareRemoteDataWithKey', aKey /*, aCurrentKey*/); |
723 | deferredResult.addCallback(MochiKit.Base.bind(function (aResult, someHeaderPackedData) { | 723 | deferredResult.addCallback(MochiKit.Base.bind(function (aResult, someHeaderPackedData) { |
724 | var header; | 724 | var header; |
725 | 725 | ||
726 | header = {}; | 726 | header = {}; |
727 | header['records'] = someHeaderPackedData['recordIndex']['records']; | 727 | header['records'] = someHeaderPackedData['recordIndex']['records']; |
728 | header['directLogins'] = someHeaderPackedData['recordIndex']['directLogins']; | 728 | header['directLogins'] = someHeaderPackedData['recordIndex']['directLogins']; |
729 | header['preferences'] = {'data': someHeaderPackedData['preferences']['data']}; // this._serverData['header']['preferences']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['preferences']; //??????????? | 729 | header['preferences'] = {'data': someHeaderPackedData['preferences']['data']}; |
730 | header['oneTimePasswords'] = {'data': someHeaderPackedData['oneTimePasswords']['data']}; // this._serverData['header']['oneTimePasswords']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['oneTimePasswords']; //??????????? | 730 | header['oneTimePasswords']= {'data': someHeaderPackedData['oneTimePasswords']['data']}; |
731 | header['version'] = '0.1'; | 731 | header['version'] = '0.1'; |
732 | 732 | ||
733 | aResult['header'] = Clipperz.Base.serializeJSON(header); | 733 | aResult['header'] = Clipperz.Base.serializeJSON(header); |
734 | aResult['statistics'] = this._serverData['statistics']; //"someHeaderPackedData['statistics']['data']"; | 734 | aResult['statistics'] = this._serverData['statistics']; //"someHeaderPackedData['statistics']['data']"; |
735 | 735 | ||
736 | return aResult; | 736 | return aResult; |
737 | }, this), result); | 737 | }, this), result); |
738 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'version', Clipperz.PM.Crypto.encryptingFunctions.currentVersion); | 738 | deferredResult.addCallback(Clipperz.Async.setItem, result, 'version', Clipperz.PM.Crypto.encryptingFunctions.currentVersion); |
739 | // deferredResult.addCallback(Clipperz.Async.setItem, result, 'lock', this.serverLockValue()); | 739 | // deferredResult.addCallback(Clipperz.Async.setItem, result, 'lock', this.serverLockValue()); |
740 | deferredResult.callback(); | 740 | deferredResult.callback(); |
741 | 741 | ||
742 | return deferredResult; | 742 | return deferredResult; |
743 | }, | 743 | }, |
744 | 744 | ||
745 | //========================================================================= | 745 | //========================================================================= |
746 | 746 | ||
747 | 'saveChanges': function () { | 747 | 'saveChanges': function () { |
748 | vardeferredResult; | 748 | vardeferredResult; |
749 | var messageParameters; | 749 | var messageParameters; |
750 | 750 | ||
751 | messageParameters = {}; | 751 | messageParameters = {}; |
752 | 752 | ||
753 | deferredResult = new Clipperz.Async.Deferred("User.saveChangaes", {trace:false}); | 753 | deferredResult = new Clipperz.Async.Deferred("User.saveChangaes", {trace:false}); |
754 | 754 | ||
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js index 326022c..b806cb7 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js | |||
@@ -260,49 +260,49 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | |||
260 | return MochiKit.Async.succeed(result); | 260 | return MochiKit.Async.succeed(result); |
261 | }, | 261 | }, |
262 | 262 | ||
263 | //========================================================================= | 263 | //========================================================================= |
264 | 264 | ||
265 | '_knock': function(aConnection, someParameters) { | 265 | '_knock': function(aConnection, someParameters) { |
266 | var result; | 266 | var result; |
267 | 267 | ||
268 | result = { | 268 | result = { |
269 | toll: this.getTollForRequestType(someParameters['requestType']) | 269 | toll: this.getTollForRequestType(someParameters['requestType']) |
270 | } | 270 | } |
271 | 271 | ||
272 | return result; | 272 | return result; |
273 | }, | 273 | }, |
274 | 274 | ||
275 | //------------------------------------------------------------------------- | 275 | //------------------------------------------------------------------------- |
276 | 276 | ||
277 | '_registration': function(aConnection, someParameters) { | 277 | '_registration': function(aConnection, someParameters) { |
278 | if (this.isReadOnly() == false) { | 278 | if (this.isReadOnly() == false) { |
279 | if (typeof(this.data()['users'][someParameters['credentials']['C']]) == 'undefined') { | 279 | if (typeof(this.data()['users'][someParameters['credentials']['C']]) == 'undefined') { |
280 | this.data()['users'][someParameters['credentials']['C']] = { | 280 | this.data()['users'][someParameters['credentials']['C']] = { |
281 | 's': someParameters['credentials']['s'], | 281 | 's': someParameters['credentials']['s'], |
282 | 'v': someParameters['credentials']['v'], | 282 | 'v': someParameters['credentials']['v'], |
283 | 'version':someParameters['credentials']['version'], | 283 | 'version':someParameters['credentials']['version'], |
284 | 'lock': Clipperz.Crypto.Base.generateRandomSeed(), | 284 | // 'lock': Clipperz.Crypto.Base.generateRandomSeed(), |
285 | 'userDetails': someParameters['user']['header'], | 285 | 'userDetails': someParameters['user']['header'], |
286 | 'statistics': someParameters['user']['statistics'], | 286 | 'statistics': someParameters['user']['statistics'], |
287 | 'userDetailsVersion':someParameters['user']['version'], | 287 | 'userDetailsVersion':someParameters['user']['version'], |
288 | 'records':{} | 288 | 'records':{} |
289 | } | 289 | } |
290 | } else { | 290 | } else { |
291 | throw "user already exists"; | 291 | throw "user already exists"; |
292 | } | 292 | } |
293 | } else { | 293 | } else { |
294 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 294 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
295 | } | 295 | } |
296 | 296 | ||
297 | result = { | 297 | result = { |
298 | result: { | 298 | result: { |
299 | 'lock': this.data()['users'][someParameters['credentials']['C']]['lock'], | 299 | 'lock': this.data()['users'][someParameters['credentials']['C']]['lock'], |
300 | 'result':'done' | 300 | 'result':'done' |
301 | }, | 301 | }, |
302 | toll: this.getTollForRequestType('CONNECT') | 302 | toll: this.getTollForRequestType('CONNECT') |
303 | } | 303 | } |
304 | 304 | ||
305 | return result; | 305 | return result; |
306 | }, | 306 | }, |
307 | 307 | ||
308 | //------------------------------------------------------------------------- | 308 | //------------------------------------------------------------------------- |
@@ -548,49 +548,49 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | |||
548 | 'data': currentRecordData['currentRecordVersion']['data'], | 548 | 'data': currentRecordData['currentRecordVersion']['data'], |
549 | 'version': currentRecordData['currentRecordVersion']['version'], | 549 | 'version': currentRecordData['currentRecordVersion']['version'], |
550 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], | 550 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], |
551 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'] | 551 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'] |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
555 | this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); | 555 | this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); |
556 | result['lock'] = this.userData()['lock']; | 556 | result['lock'] = this.userData()['lock']; |
557 | result['result'] = 'done'; | 557 | result['result'] = 'done'; |
558 | } else { | 558 | } else { |
559 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 559 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
560 | } | 560 | } |
561 | */ //===================================================================== | 561 | */ //===================================================================== |
562 | } else if (someParameters.message == 'saveChanges') { | 562 | } else if (someParameters.message == 'saveChanges') { |
563 | if (this.isReadOnly() == false) { | 563 | if (this.isReadOnly() == false) { |
564 | var i, c; | 564 | var i, c; |
565 | 565 | ||
566 | if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) { | 566 | if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) { |
567 | throw "the lock attribute is not processed correctly" | 567 | throw "the lock attribute is not processed correctly" |
568 | } | 568 | } |
569 | 569 | ||
570 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; | 570 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; |
571 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; | 571 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; |
572 | aConnection['userData']['userDetailsVersions']= someParameters['parameters']['user']['version']; | 572 | aConnection['userData']['userDetailsVersion']= someParameters['parameters']['user']['version']; |
573 | 573 | ||
574 | c = someParameters['parameters']['records']['updated'].length; | 574 | c = someParameters['parameters']['records']['updated'].length; |
575 | for (i=0; i<c; i++) { | 575 | for (i=0; i<c; i++) { |
576 | var currentRecord; | 576 | var currentRecord; |
577 | var currentRecordData; | 577 | var currentRecordData; |
578 | 578 | ||
579 | currentRecordData = someParameters['parameters']['records']['updated'][i]; | 579 | currentRecordData = someParameters['parameters']['records']['updated'][i]; |
580 | currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; | 580 | currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; |
581 | 581 | ||
582 | if ( | 582 | if ( |
583 | (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') | 583 | (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') |
584 | && | 584 | && |
585 | (typeof(currentRecordData['currentRecordVersion']) == 'undefined') | 585 | (typeof(currentRecordData['currentRecordVersion']) == 'undefined') |
586 | ) { | 586 | ) { |
587 | throw "Record added without a recordVersion"; | 587 | throw "Record added without a recordVersion"; |
588 | } | 588 | } |
589 | 589 | ||
590 | if (currentRecord == null) { | 590 | if (currentRecord == null) { |
591 | currentRecord = {}; | 591 | currentRecord = {}; |
592 | currentRecord['versions'] = {}; | 592 | currentRecord['versions'] = {}; |
593 | currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 593 | currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
594 | currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 594 | currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
595 | 595 | ||
596 | aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; | 596 | aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; |
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js index d459726..1a860c5 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js | |||
@@ -122,35 +122,40 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Test, Clipperz.PM.Proxy.Offline, { | |||
122 | } | 122 | } |
123 | 123 | ||
124 | try { | 124 | try { |
125 | if (aFunctionName != expectedRequest.functionName) { | 125 | if (aFunctionName != expectedRequest.functionName) { |
126 | throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'"; | 126 | throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'"; |
127 | } | 127 | } |
128 | 128 | ||
129 | this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters); | 129 | this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters); |
130 | } catch(exception) { | 130 | } catch(exception) { |
131 | throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception; | 131 | throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception; |
132 | } | 132 | } |
133 | } | 133 | } |
134 | }, | 134 | }, |
135 | 135 | ||
136 | //========================================================================= | 136 | //========================================================================= |
137 | 137 | ||
138 | 'sendMessage': function(aFunctionName, someParameters) { | 138 | 'sendMessage': function(aFunctionName, someParameters) { |
139 | var result; | 139 | var result; |
140 | 140 | ||
141 | if (this.isExpectingRequests() == false) { | 141 | if (this.isExpectingRequests() == false) { |
142 | // throw Clipperz.PM.Connection.exception.UnexpectedRequest; | 142 | // throw Clipperz.PM.Connection.exception.UnexpectedRequest; |
143 | Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */); | 143 | Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */); |
144 | this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); | 144 | this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); |
145 | }; | 145 | }; |
146 | //if (aFunctionName == 'knock') { | ||
147 | //console.log(">>> send message - " + aFunctionName, someParameters); | ||
148 | //} else { | ||
149 | //console.log(">>> SEND MESSAGE - " + aFunctionName + " [" + someParameters['parameters']['message'] + "]", someParameters['parameters']['parameters']); | ||
150 | //} | ||
146 | this.checkRequest(aFunctionName, someParameters); | 151 | this.checkRequest(aFunctionName, someParameters); |
147 | result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); | 152 | result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); |
148 | 153 | ||
149 | return result; | 154 | return result; |
150 | }, | 155 | }, |
151 | 156 | ||
152 | //========================================================================= | 157 | //========================================================================= |
153 | __syntaxFix__: "syntax fix" | 158 | __syntaxFix__: "syntax fix" |
154 | 159 | ||
155 | }); | 160 | }); |
156 | 161 | ||