summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js48
1 files changed, 14 insertions, 34 deletions
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 01ba122..326022c 100644
--- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
+++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
@@ -1,46 +1,44 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) { 24try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) {
27 throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!"; 25 throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!";
28} 26}
29 27
30//============================================================================= 28//=============================================================================
31 29
32Clipperz.PM.Proxy.Offline.DataStore = function(args) { 30Clipperz.PM.Proxy.Offline.DataStore = function(args) {
33 args = args || {}; 31 args = args || {};
34 32
35 this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); 33 this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null);
36 this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); 34 this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly);
37 this._shouldPayTolls = args.shouldPayTolls || false; 35 this._shouldPayTolls = args.shouldPayTolls || false;
38 36
39 this._tolls = {}; 37 this._tolls = {};
40 this._currentStaticConnection = null; 38 this._currentStaticConnection = null;
41 39
42 return this; 40 return this;
43} 41}
44 42
45Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { 43Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
46 44
@@ -86,64 +84,62 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
86 84
87 'setupWithEncryptedData': function(someData) { 85 'setupWithEncryptedData': function(someData) {
88 this._data = Clipperz.Base.deepClone(someData); 86 this._data = Clipperz.Base.deepClone(someData);
89 }, 87 },
90 88
91 //------------------------------------------------------------------------- 89 //-------------------------------------------------------------------------
92 90
93 'setupWithData': function(someData) { 91 'setupWithData': function(someData) {
94 var deferredResult; 92 var deferredResult;
95 var resultData; 93 var resultData;
96 var i, c; 94 var i, c;
97 95
98//Clipperz.log(">>> Proxy.Test.setupWithData"); 96//Clipperz.log(">>> Proxy.Test.setupWithData");
99 resultData = this._data; 97 resultData = this._data;
100 98
101 deferredResult = new Clipperz.Async.Deferred("Proxy.Test.seupWithData", {trace:false}); 99 deferredResult = new Clipperz.Async.Deferred("Proxy.Test.seupWithData", {trace:false});
102 c = someData['users'].length; 100 c = someData['users'].length;
103 101
104 for (i=0; i<c; i++) { 102 for (i=0; i<c; i++) {
105 varnewConnection; 103 varnewConnection;
106 varrecordConfiguration; 104 varrecordConfiguration;
107 105
108 deferredResult.addMethod(this, 'userSerializedEncryptedData', someData['users'][i]); 106 deferredResult.addMethod(this, 'userSerializedEncryptedData', someData['users'][i]);
109 deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) { 107 deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) {
110//console.log("SERIALIZED USER", aUserSerializationContext);
111 resultData['users'][aUserSerializationContext['credentials']['C']] = { 108 resultData['users'][aUserSerializationContext['credentials']['C']] = {
112 's': aUserSerializationContext['credentials']['s'], 109 's': aUserSerializationContext['credentials']['s'],
113 'v': aUserSerializationContext['credentials']['v'], 110 'v': aUserSerializationContext['credentials']['v'],
114 'version': aUserSerializationContext['data']['connectionVersion'], 111 'version': aUserSerializationContext['data']['connectionVersion'],
115 'userDetails': aUserSerializationContext['encryptedData']['user']['header'], 112 'userDetails': aUserSerializationContext['encryptedData']['user']['header'],
116 'userDetailsVersion':aUserSerializationContext['encryptedData']['user']['version'], 113 'userDetailsVersion':aUserSerializationContext['encryptedData']['user']['version'],
117 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'], 114 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'],
118 'lock': aUserSerializationContext['encryptedData']['user']['lock'], 115 'lock': aUserSerializationContext['encryptedData']['user']['lock'],
119 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records']) 116 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records'])
120 } 117 }
121 }, this)); 118 }, this));
122 } 119 }
123 120
124 deferredResult.addCallback(MochiKit.Base.bind(function() { 121 deferredResult.addCallback(MochiKit.Base.bind(function() {
125//console.log("this._data", resultData);
126 this._data = resultData; 122 this._data = resultData;
127 }, this)); 123 }, this));
128 124
129 deferredResult.callback(); 125 deferredResult.callback();
130//Clipperz.log("<<< Proxy.Test.setupWithData"); 126//Clipperz.log("<<< Proxy.Test.setupWithData");
131 127
132 return deferredResult; 128 return deferredResult;
133 }, 129 },
134 130
135 //========================================================================= 131 //=========================================================================
136 132
137 'getTollForRequestType': function (aRequestType) { 133 'getTollForRequestType': function (aRequestType) {
138 varresult; 134 varresult;
139 vartargetValue; 135 vartargetValue;
140 var cost; 136 var cost;
141 137
142 targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); 138 targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2);
143 switch (aRequestType) { 139 switch (aRequestType) {
144 case 'REGISTER': 140 case 'REGISTER':
145 cost = 5; 141 cost = 5;
146 break; 142 break;
147 case 'CONNECT': 143 case 'CONNECT':
148 cost = 5; 144 cost = 5;
149 break; 145 break;
@@ -374,49 +370,49 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
374 result = { 370 result = {
375 'data': otpData['data'], 371 'data': otpData['data'],
376 'version':otpData['version'] 372 'version':otpData['version']
377 } 373 }
378 374
379 otpData['status'] = 'REQUESTED'; 375 otpData['status'] = 'REQUESTED';
380 } else { 376 } else {
381 otpData['status'] = 'DISABLED'; 377 otpData['status'] = 'DISABLED';
382 throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; 378 throw "The requested One Time Password has been disabled, due to a wrong keyChecksum";
383 } 379 }
384 } else { 380 } else {
385 throw "The requested One Time Password was not active"; 381 throw "The requested One Time Password was not active";
386 } 382 }
387 } else { 383 } else {
388 throw "The requested One Time Password has not been found" 384 throw "The requested One Time Password has not been found"
389 } 385 }
390 } catch (exception) { 386 } catch (exception) {
391 result = { 387 result = {
392 'data': Clipperz.PM.Crypto.randomKey(), 388 'data': Clipperz.PM.Crypto.randomKey(),
393 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion 389 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion
394 } 390 }
395 } 391 }
396 nextTollRequestType = 'CONNECT'; 392 nextTollRequestType = 'CONNECT';
397 } else { 393 } else {
398 MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); 394 Clipperz.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message);
399 } 395 }
400 396
401 result = { 397 result = {
402 result: result, 398 result: result,
403 toll: this.getTollForRequestType(nextTollRequestType) 399 toll: this.getTollForRequestType(nextTollRequestType)
404 } 400 }
405 401
406 return result; 402 return result;
407 }, 403 },
408 404
409 //------------------------------------------------------------------------- 405 //-------------------------------------------------------------------------
410 406
411 '_message': function(aConnection, someParameters) { 407 '_message': function(aConnection, someParameters) {
412 var result; 408 var result;
413 409
414 result = {}; 410 result = {};
415 411
416 //===================================================================== 412 //=====================================================================
417 // 413 //
418 // R E A D - O N L Y M e t h o d s 414 // R E A D - O N L Y M e t h o d s
419 // 415 //
420 //===================================================================== 416 //=====================================================================
421 if (someParameters.message == 'getUserDetails') { 417 if (someParameters.message == 'getUserDetails') {
422 var recordsStats; 418 var recordsStats;
@@ -504,215 +500,201 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
504 aConnection['C'] = credentials['C']; 500 aConnection['C'] = credentials['C'];
505 501
506 aConnection['userData']['s'] = credentials['s']; 502 aConnection['userData']['s'] = credentials['s'];
507 aConnection['userData']['v'] = credentials['v']; 503 aConnection['userData']['v'] = credentials['v'];
508 aConnection['userData']['version'] = credentials['version']; 504 aConnection['userData']['version'] = credentials['version'];
509 505
510 aConnection['userData']['userDetails'] = parameters['user']['header']; 506 aConnection['userData']['userDetails'] = parameters['user']['header'];
511 aConnection['userData']['userDetailsVersion'] = parameters['user']['version']; 507 aConnection['userData']['userDetailsVersion'] = parameters['user']['version'];
512 aConnection['userData']['statistics'] = parameters['user']['statistics']; 508 aConnection['userData']['statistics'] = parameters['user']['statistics'];
513 509
514 aConnection['userData']['lock'] = parameters['user']['lock']; 510 aConnection['userData']['lock'] = parameters['user']['lock'];
515 511
516 delete this.data()['users'][oldCValue]; 512 delete this.data()['users'][oldCValue];
517 513
518 result = {result:"done", parameters:parameters}; 514 result = {result:"done", parameters:parameters};
519 } 515 }
520 } else { 516 } else {
521 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; 517 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly;
522 } 518 }
523 //===================================================================== 519 //=====================================================================
524 /* } else if (someParameters.message == 'updateData') { 520 /* } else if (someParameters.message == 'updateData') {
525 if (this.isReadOnly() == false) { 521 if (this.isReadOnly() == false) {
526 var i, c; 522 var i, c;
527 523
528//console.log("###===============================================================");
529//console.log("###>>>", Clipperz.Base.serializeJSON(someParameters));
530//console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData()));
531 if (this.userData()['lock']!= someParameters['parameters']['user']['lock']) { 524 if (this.userData()['lock']!= someParameters['parameters']['user']['lock']) {
532 throw "the lock attribute is not processed correctly" 525 throw "the lock attribute is not processed correctly"
533 } 526 }
534 527
535 this.userData()['userDetails'] = someParameters['parameters']['user']['header']; 528 this.userData()['userDetails'] = someParameters['parameters']['user']['header'];
536 this.userData()['statistics'] = someParameters['parameters']['user']['statistics']; 529 this.userData()['statistics'] = someParameters['parameters']['user']['statistics'];
537 this.userData()['userDetailsVersions']= someParameters['parameters']['user']['version']; 530 this.userData()['userDetailsVersions']= someParameters['parameters']['user']['version'];
538 531
539 c = someParameters['parameters']['records'].length; 532 c = someParameters['parameters']['records'].length;
540 for (i=0; i<c; i++) { 533 for (i=0; i<c; i++) {
541 var currentRecord; 534 var currentRecord;
542 var currentRecordData; 535 var currentRecordData;
543 536
544 currentRecordData = someParameters['parameters']['records'][i]; 537 currentRecordData = someParameters['parameters']['records'][i];
545 currentRecord = this.userData()['records'][currentRecordData['record']['reference']]; 538 currentRecord = this.userData()['records'][currentRecordData['record']['reference']];
546 539
547 if (currentRecord == null) { 540 if (currentRecord == null) {
548 } 541 }
549 542
550 currentRecord['data'] = currentRecordData['record']['data']; 543 currentRecord['data'] = currentRecordData['record']['data'];
551 currentRecord['version'] = currentRecordData['record']['version']; 544 currentRecord['version'] = currentRecordData['record']['version'];
552 currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; 545 currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference'];
553 546
554 currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { 547 currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = {
555 'data': currentRecordData['currentRecordVersion']['data'], 548 'data': currentRecordData['currentRecordVersion']['data'],
556 'version': currentRecordData['currentRecordVersion']['version'], 549 'version': currentRecordData['currentRecordVersion']['version'],
557 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], 550 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'],
558 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'] 551 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey']
559 } 552 }
560 } 553 }
561 554
562 this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); 555 this.userData()['lock'] = Clipperz.PM.Crypto.randomKey();
563 result['lock'] = this.userData()['lock']; 556 result['lock'] = this.userData()['lock'];
564 result['result'] = 'done'; 557 result['result'] = 'done';
565//console.log("###<<< userData", Clipperz.Base.serializeJSON(this.userData()));
566 } else { 558 } else {
567 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; 559 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly;
568 } 560 }
569 */ //===================================================================== 561 */ //=====================================================================
570 } else if (someParameters.message == 'saveChanges') { 562 } else if (someParameters.message == 'saveChanges') {
571 if (this.isReadOnly() == false) { 563 if (this.isReadOnly() == false) {
572 var i, c; 564 var i, c;
573 565
574//console.log("###===============================================================");
575//console.log("###>>>", someParameters);
576//console.log("###>>>", Clipperz.Base.serializeJSON(someParameters));
577//console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData()));
578//console.log("###===============================================================");
579//console.log("--- userData.lock ", this.userData()['lock']);
580//console.log("--- parameters.lock", someParameters['parameters']['user']['lock']);
581 if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) { 566 if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) {
582 throw "the lock attribute is not processed correctly" 567 throw "the lock attribute is not processed correctly"
583 } 568 }
584 569
585 aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; 570 aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header'];
586 aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; 571 aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics'];
587 aConnection['userData']['userDetailsVersions']= someParameters['parameters']['user']['version']; 572 aConnection['userData']['userDetailsVersions']= someParameters['parameters']['user']['version'];
588 573
589 c = someParameters['parameters']['records']['updated'].length; 574 c = someParameters['parameters']['records']['updated'].length;
590 for (i=0; i<c; i++) { 575 for (i=0; i<c; i++) {
591 var currentRecord; 576 var currentRecord;
592 var currentRecordData; 577 var currentRecordData;
593 578
594 currentRecordData = someParameters['parameters']['records']['updated'][i]; 579 currentRecordData = someParameters['parameters']['records']['updated'][i];
595 currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; 580 currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']];
596 581
597 if ( 582 if (
598 (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') 583 (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined')
599 && 584 &&
600 (typeof(currentRecordData['currentRecordVersion']) == 'undefined') 585 (typeof(currentRecordData['currentRecordVersion']) == 'undefined')
601 ) { 586 ) {
602//console.log("######## SHIT HAPPENS");
603 throw "Record added without a recordVersion"; 587 throw "Record added without a recordVersion";
604 } 588 }
605 589
606 if (currentRecord == null) { 590 if (currentRecord == null) {
607 currentRecord = {}; 591 currentRecord = {};
608 currentRecord['versions'] = {}; 592 currentRecord['versions'] = {};
609 currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); 593 currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date());
610 currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); 594 currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date());
611 595
612 aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; 596 aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord;
613 } 597 }
614 598
615 currentRecord['data'] = currentRecordData['record']['data']; 599 currentRecord['data'] = currentRecordData['record']['data'];
616 currentRecord['version']= currentRecordData['record']['version']; 600 currentRecord['version']= currentRecordData['record']['version'];
617 currentRecord['updateDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); 601 currentRecord['updateDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date());
618 602
619 if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') { 603 if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') {
620 currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; 604 currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference'];
621 currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { 605 currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = {
622 'data': currentRecordData['currentRecordVersion']['data'], 606 'data': currentRecordData['currentRecordVersion']['data'],
623 'version': currentRecordData['currentRecordVersion']['version'], 607 'version': currentRecordData['currentRecordVersion']['version'],
624 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], 608 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'],
625 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'], 609 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'],
626 'creationDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), 610 'creationDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()),
627 'updateDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), 611 'updateDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()),
628 'accessDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()) 612 'accessDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date())
629 } 613 }
630 } 614 }
631 } 615 }
632 616
633 c = someParameters['parameters']['records']['deleted'].length; 617 c = someParameters['parameters']['records']['deleted'].length;
634 for (i=0; i<c; i++) { 618 for (i=0; i<c; i++) {
635 var currentRecordReference; 619 var currentRecordReference;
636 620
637 currentRecordReference = someParameters['parameters']['records']['deleted'][i]; 621 currentRecordReference = someParameters['parameters']['records']['deleted'][i];
638//console.log("DELETING records", currentRecordReference);
639 delete aConnection['userData']['records'][currentRecordReference]; 622 delete aConnection['userData']['records'][currentRecordReference];
640 } 623 }
641 624
642 aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey(); 625 aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey();
643 result['lock'] = aConnection['userData']['lock']; 626 result['lock'] = aConnection['userData']['lock'];
644 result['result'] = 'done'; 627 result['result'] = 'done';
645//console.log("###<<< userData", Clipperz.Base.serializeJSON(this.userData()));
646 } else { 628 } else {
647 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; 629 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly;
648 } 630 }
649 631
650 //===================================================================== 632 //=====================================================================
651 // 633 //
652 // U N H A N D L E D M e t h o d 634 // U N H A N D L E D M e t h o d
653 // 635 //
654 //===================================================================== 636 //=====================================================================
655 } else { 637 } else {
656 MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message); 638 Clipperz.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message);
657 } 639 }
658 640
659 result = { 641 result = {
660 result: result, 642 result: result,
661 toll: this.getTollForRequestType('MESSAGE') 643 toll: this.getTollForRequestType('MESSAGE')
662 } 644 }
663 645
664 // return MochiKit.Async.succeed(result); 646 // return MochiKit.Async.succeed(result);
665 return result; 647 return result;
666 }, 648 },
667 649
668 //------------------------------------------------------------------------- 650 //-------------------------------------------------------------------------
669 651
670 '_logout': function(someParameters) { 652 '_logout': function(someParameters) {
671 // return MochiKit.Async.succeed({result: 'done'}); 653 // return MochiKit.Async.succeed({result: 'done'});
672 return {result: 'done'}; 654 return {result: 'done'};
673 }, 655 },
674 656
675 //========================================================================= 657 //=========================================================================
676 //######################################################################### 658 //#########################################################################
677 659
678 'isTestData': function(aConnection) { 660 'isTestData': function(aConnection) {
679 return (typeof(aConnection['userData']['__masterkey_test_value__']) != 'undefined'); 661 return (typeof(aConnection['userData']['__masterkey_test_value__']) != 'undefined');
680 }, 662 },
681 663
682 'userDetails': function(aConnection) { 664 'userDetails': function(aConnection) {
683 var result; 665 var result;
684 666
685 if (this.isTestData(aConnection)) { 667 if (this.isTestData(aConnection)) {
686 var serializedHeader; 668 var serializedHeader;
687 var version; 669 var version;
688 670
689//MochiKit.Logging.logDebug("### test data"); 671//Clipperz.logDebug("### test data");
690 version = aConnection['userData']['userDetailsVersion']; 672 version = aConnection['userData']['userDetailsVersion'];
691 serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']); 673 serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']);
692 result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader); 674 result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader);
693 } else { 675 } else {
694//MochiKit.Logging.logDebug("### NOT test data"); 676//Clipperz.logDebug("### NOT test data");
695 result = aConnection['userData']['userDetails']; 677 result = aConnection['userData']['userDetails'];
696 } 678 }
697 679
698 return result; 680 return result;
699 }, 681 },
700 682
701 'statistics': function(aConnection) { 683 'statistics': function(aConnection) {
702 var result; 684 var result;
703 685
704 if (aConnection['userData']['statistics'] != null) { 686 if (aConnection['userData']['statistics'] != null) {
705 if (this.isTestData(aConnection)) { 687 if (this.isTestData(aConnection)) {
706 var serializedStatistics; 688 var serializedStatistics;
707 var version; 689 var version;
708 690
709 version = aConnection['userData']['userDetailsVersion']; 691 version = aConnection['userData']['userDetailsVersion'];
710 serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']); 692 serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']);
711 result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics); 693 result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics);
712 } else { 694 } else {
713 result = aConnection['userData']['statistics']; 695 result = aConnection['userData']['statistics'];
714 } 696 }
715 } else { 697 } else {
716 result = null; 698 result = null;
717 } 699 }
718 700
@@ -728,53 +710,51 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
728 710
729 deferredResult = new Clipperz.Async.Deferred('Proxy.Test.serializeUserEncryptedData', {trace:false}); 711 deferredResult = new Clipperz.Async.Deferred('Proxy.Test.serializeUserEncryptedData', {trace:false});
730 deferredResult.addCallback(MochiKit.Base.bind(function(aDeferredContext) { 712 deferredResult.addCallback(MochiKit.Base.bind(function(aDeferredContext) {
731 aDeferredContext['user'] = this.createUserUsingConfigurationData(aDeferredContext['data']); 713 aDeferredContext['user'] = this.createUserUsingConfigurationData(aDeferredContext['data']);
732 return aDeferredContext; 714 return aDeferredContext;
733 }, this)); 715 }, this));
734 deferredResult.addCallback(function(aDeferredContext) { 716 deferredResult.addCallback(function(aDeferredContext) {
735 // return aDeferredContext['user'].encryptedDataUsingVersion(aDeferredContext['data']['version']); 717 // return aDeferredContext['user'].encryptedDataUsingVersion(aDeferredContext['data']['version']);
736 return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); 718 return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']);
737 }); 719 });
738 deferredResult.addCallback(function(aUserEncryptedData) { 720 deferredResult.addCallback(function(aUserEncryptedData) {
739 deferredContext['encryptedData'] = aUserEncryptedData; 721 deferredContext['encryptedData'] = aUserEncryptedData;
740 return deferredContext; 722 return deferredContext;
741 }); 723 });
742 deferredResult.addCallback(function(aDeferredContext) { 724 deferredResult.addCallback(function(aDeferredContext) {
743 var connection; 725 var connection;
744 726
745 connection = new Clipperz.PM.Connection.communicationProtocol.versions[aDeferredContext['data']['connectionVersion']]() 727 connection = new Clipperz.PM.Connection.communicationProtocol.versions[aDeferredContext['data']['connectionVersion']]()
746 aDeferredContext['credentials'] = connection.serverSideUserCredentials(aDeferredContext['user'].username(),aDeferredContext['user'].passphrase()); 728 aDeferredContext['credentials'] = connection.serverSideUserCredentials(aDeferredContext['user'].username(),aDeferredContext['user'].passphrase());
747 729
748 return aDeferredContext; 730 return aDeferredContext;
749 }); 731 });
750 732
751 // deferredResult.addCallback(function(aDeferredContext) { 733 // deferredResult.addCallback(function(aDeferredContext) {
752//console.log("#-#-#-#-#", aDeferredContext);
753 // return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); 734 // return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']);
754 // }, deferredContext); 735 // }, deferredContext);
755 // deferredResult.addCallback(function(aUserSerializedData) { 736 // deferredResult.addCallback(function(aUserSerializedData) {
756//console.log("USER SERIALIZED DATA", aUserSerializedData);
757 // }); 737 // });
758// 738//
759 // deferredResult.addCallback(MochiKit.Async.succeed, deferredContext); 739 // deferredResult.addCallback(MochiKit.Async.succeed, deferredContext);
760 deferredResult.callback(deferredContext); 740 deferredResult.callback(deferredContext);
761 741
762 return deferredResult; 742 return deferredResult;
763 }, 743 },
764 744
765 'createUserUsingConfigurationData': function(someData) { 745 'createUserUsingConfigurationData': function(someData) {
766 var result; 746 var result;
767 var user; 747 var user;
768 var recordLabel; 748 var recordLabel;
769 749
770 user = new Clipperz.PM.DataModel.User(); 750 user = new Clipperz.PM.DataModel.User();
771 user.initForTests(); 751 user.initForTests();
772 user.setUsername(someData['username']); 752 user.setUsername(someData['username']);
773 user.setPassphrase(someData['passphrase']); 753 user.setPassphrase(someData['passphrase']);
774 754
775 for (recordLabel in someData['records']) { 755 for (recordLabel in someData['records']) {
776 var recordData; 756 var recordData;
777 var record; 757 var record;
778 var i, c; 758 var i, c;
779 759
780 recordData = someData['records'][recordLabel]; 760 recordData = someData['records'][recordLabel];