summaryrefslogtreecommitdiff
path: root/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
Unidiff
Diffstat (limited to 'frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js793
1 files changed, 793 insertions, 0 deletions
diff --git a/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
new file mode 100644
index 0000000..5711742
--- a/dev/null
+++ b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
@@ -0,0 +1,793 @@
1/*
2
3Copyright 2008-2013 Clipperz Srl
4
5This file is part of Clipperz, the online password manager.
6For further information about its features and functionalities please
7refer to http://www.clipperz.com.
8
9* Clipperz is free software: you can redistribute it and/or modify it
10 under the terms of the GNU Affero General Public License as published
11 by the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14* Clipperz is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU Affero General Public License for more details.
18
19* You should have received a copy of the GNU Affero General Public
20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
21
22*/
23
24try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) {
25 throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!";
26}
27
28//=============================================================================
29
30Clipperz.PM.Proxy.Offline.DataStore = function(args) {
31 args = args || {};
32
33 this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null);
34 this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly);
35 this._shouldPayTolls = args.shouldPayTolls || false;
36
37 this._tolls = {};
38 this._currentStaticConnection = null;
39
40 return this;
41}
42
43Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
44
45 //-------------------------------------------------------------------------
46
47 'isReadOnly': function () {
48 return this._isReadOnly;
49 },
50
51 'canRegisterNewUsers': function () {
52 return false;
53 },
54
55
56 //-------------------------------------------------------------------------
57
58 'shouldPayTolls': function() {
59 return this._shouldPayTolls;
60 },
61
62 //-------------------------------------------------------------------------
63
64 'data': function () {
65 return this._data;
66 },
67
68 //-------------------------------------------------------------------------
69
70 'tolls': function () {
71 return this._tolls;
72 },
73
74 //=========================================================================
75
76 'resetData': function() {
77 this._data = {
78 'users': {
79 'catchAllUser': {
80 __masterkey_test_value__: 'masterkey',
81 s: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00',
82 v: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00'
83 }
84 }
85 };
86 },
87
88 //-------------------------------------------------------------------------
89
90 'setupWithEncryptedData': function(someData) {
91 this._data = Clipperz.Base.deepClone(someData);
92 },
93
94 //-------------------------------------------------------------------------
95
96 'setupWithData': function(someData) {
97 var deferredResult;
98 var resultData;
99 var i, c;
100
101//Clipperz.log(">>> Proxy.Test.setupWithData");
102 resultData = this._data;
103
104 deferredResult = new Clipperz.Async.Deferred("Proxy.Test.seupWithData", {trace:false});
105 c = someData['users'].length;
106
107 for (i=0; i<c; i++) {
108 varnewConnection;
109 varrecordConfiguration;
110
111 deferredResult.addMethod(this, 'userSerializedEncryptedData', someData['users'][i]);
112 deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) {
113 resultData['users'][aUserSerializationContext['credentials']['C']] = {
114 's': aUserSerializationContext['credentials']['s'],
115 'v': aUserSerializationContext['credentials']['v'],
116 'version': aUserSerializationContext['data']['connectionVersion'],
117 'userDetails': aUserSerializationContext['encryptedData']['user']['header'],
118 'userDetailsVersion':aUserSerializationContext['encryptedData']['user']['version'],
119 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'],
120 'lock': aUserSerializationContext['encryptedData']['user']['lock'],
121 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records'])
122 }
123 }, this));
124 }
125
126 deferredResult.addCallback(MochiKit.Base.bind(function() {
127 this._data = resultData;
128 }, this));
129
130 deferredResult.callback();
131//Clipperz.log("<<< Proxy.Test.setupWithData");
132
133 return deferredResult;
134 },
135
136 //=========================================================================
137
138 'getTollForRequestType': function (aRequestType) {
139 varresult;
140 vartargetValue;
141 var cost;
142
143 targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2);
144 switch (aRequestType) {
145 case 'REGISTER':
146 cost = 5;
147 break;
148 case 'CONNECT':
149 cost = 5;
150 break;
151 case 'MESSAGE':
152 cost = 2;
153 break;
154 }
155
156 result = {
157 requestType: aRequestType,
158 targetValue: targetValue,
159 cost: cost
160 }
161
162 if (this.shouldPayTolls()) {
163 this.tolls()[targetValue] = result;
164 }
165
166 return result;
167 },
168
169 //-------------------------------------------------------------------------
170
171 'checkToll': function (aFunctionName, someParameters) {
172 if (this.shouldPayTolls()) {
173 var localToll;
174 vartollParameters;
175
176 tollParameters = someParameters['toll'];
177 localToll = this.tolls()[tollParameters['targetValue']];
178
179 if (localToll != null) {
180 if (! Clipperz.PM.Toll.validate(tollParameters['targetValue'], tollParameters['toll'], localToll['cost'])) {
181 throw "Toll value too low.";
182 };
183 } else {
184 throw "Missing toll";
185 }
186 }
187 },
188
189 //=========================================================================
190
191 'currentStaticConnection': function () {
192 if (this._currentStaticConnection == null) {
193 this._currentStaticConnection = {};
194 }
195
196 return this._currentStaticConnection;
197 },
198
199 //-------------------------------------------------------------------------
200
201 'getConnectionForRequest': function (aFunctionName, someParameters) {
202 varresult;
203
204 if (this.shouldPayTolls()) {
205 if ((typeof(someParameters['toll']) != 'undefined') && (typeof(someParameters['toll']['targetValue']) != 'undefined')) {
206 result = this.tolls()[someParameters['toll']['targetValue']]['connection'];
207 if (typeof(result) == 'undefined') {
208 result = {};
209 }
210 } else {
211 result = {};
212 }
213 } else {
214 result = this.currentStaticConnection();
215 }
216
217 return result;
218 },
219
220 //-------------------------------------------------------------------------
221
222 'storeConnectionForRequestWithConnectionAndResponse': function (aFunctionName, someParameters, aConnection, aResponse) {
223 if (this.shouldPayTolls()) {
224 if ((typeof(aResponse['toll']) != 'undefined')
225 &&(typeof(aResponse['toll']['targetValue']) != 'undefined')
226 &&(typeof(this.tolls()[aResponse['toll']['targetValue']]) != 'undefined')
227 ) {
228 this.tolls()[aResponse['toll']['targetValue']]['connection'] = aConnection;
229 }
230 }
231 },
232
233 //=========================================================================
234
235 'processMessage': function (aFunctionName, someParameters) {
236 var result;
237 varconnection;
238
239 connection = this.getConnectionForRequest(aFunctionName, someParameters);
240
241 switch(aFunctionName) {
242 case 'knock':
243 result = this._knock(connection, someParameters);
244 break;
245 case 'registration':
246 this.checkToll(aFunctionName, someParameters);
247 result = this._registration(connection, someParameters.parameters);
248 break;
249 case 'handshake':
250 this.checkToll(aFunctionName, someParameters);
251 result = this._handshake(connection, someParameters.parameters);
252 break;
253 case 'message':
254 this.checkToll(aFunctionName, someParameters);
255 result = this._message(connection, someParameters.parameters);
256 break;
257 case 'logout':
258 this._currentStaticConnection = null;
259 result = this._logout(connection, someParameters.parameters);
260 break;
261 }
262
263 this.storeConnectionForRequestWithConnectionAndResponse(aFunctionName, someParameters, connection, result);
264
265 return MochiKit.Async.succeed(result);
266 },
267
268 //=========================================================================
269
270 '_knock': function(aConnection, someParameters) {
271 var result;
272
273 result = {
274 toll: this.getTollForRequestType(someParameters['requestType'])
275 }
276
277 return result;
278 },
279
280 //-------------------------------------------------------------------------
281
282 '_registration': function(aConnection, someParameters) {
283 if (this.isReadOnly() == false) {
284 if (typeof(this.data()['users'][someParameters['credentials']['C']]) == 'undefined') {
285 this.data()['users'][someParameters['credentials']['C']] = {
286 's': someParameters['credentials']['s'],
287 'v': someParameters['credentials']['v'],
288 'version':someParameters['credentials']['version'],
289 // 'lock': Clipperz.Crypto.Base.generateRandomSeed(),
290 'userDetails': someParameters['user']['header'],
291 'statistics': someParameters['user']['statistics'],
292 'userDetailsVersion':someParameters['user']['version'],
293 'records':{}
294 }
295 } else {
296 throw "user already exists";
297 }
298 } else {
299 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly;
300 }
301
302 result = {
303 result: {
304 'lock': this.data()['users'][someParameters['credentials']['C']]['lock'],
305 'result':'done'
306 },
307 toll: this.getTollForRequestType('CONNECT')
308 }
309
310 return result;
311 },
312
313 //-------------------------------------------------------------------------
314
315 '_handshake': function(aConnection, someParameters) {
316 var result;
317 varnextTollRequestType;
318
319 result = {};
320 if (someParameters.message == "connect") {
321 var userData;
322 var randomBytes;
323 var v;
324
325 userData = this.data()['users'][someParameters.parameters.C];
326
327 if ((typeof(userData) != 'undefined') && (userData['version'] == someParameters.version)) {
328 aConnection['userData'] = userData;
329 aConnection['C'] = someParameters.parameters.C;
330 } else {
331 aConnection['userData'] = this.data()['users']['catchAllUser'];
332 }
333
334 randomBytes = Clipperz.Crypto.Base.generateRandomSeed();
335 aConnection['b'] = new Clipperz.Crypto.BigInt(randomBytes, 16);
336 v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16);
337 aConnection['B'] = v.add(Clipperz.Crypto.SRP.g().powerModule(aConnection['b'], Clipperz.Crypto.SRP.n()));
338
339 aConnection['A'] = someParameters.parameters.A;
340
341 result['s'] = aConnection['userData']['s'];
342 result['B'] = aConnection['B'].asString(16);
343
344 nextTollRequestType = 'CONNECT';
345 } else if (someParameters.message == "credentialCheck") {
346 var v, u, S, A, K, M1;
347
348 v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16);
349 u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(aConnection['B'].asString(10))).toHexString(), 16);
350 A = new Clipperz.Crypto.BigInt(aConnection['A'], 16);
351 S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(aConnection['b'], Clipperz.Crypto.SRP.n());
352
353 K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2);
354
355 M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + aConnection['B'].asString(10) + K)).toHexString().slice(2);
356 if (someParameters.parameters.M1 == M1) {
357 var M2;
358
359 M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2);
360 result['M2'] = M2;
361 } else {
362 throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error");
363 }
364
365 nextTollRequestType = 'MESSAGE';
366 } else if (someParameters.message == "oneTimePassword") {
367 var otpData;
368
369 otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey];
370
371 try {
372 if (typeof(otpData) != 'undefined') {
373 if (otpData['status'] == 'ACTIVE') {
374 if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) {
375 result = {
376 'data': otpData['data'],
377 'version':otpData['version']
378 }
379
380 otpData['status'] = 'REQUESTED';
381 } else {
382 otpData['status'] = 'DISABLED';
383 throw "The requested One Time Password has been disabled, due to a wrong keyChecksum";
384 }
385 } else {
386 throw "The requested One Time Password was not active";
387 }
388 } else {
389 throw "The requested One Time Password has not been found"
390 }
391 } catch (exception) {
392 result = {
393 'data': Clipperz.PM.Crypto.randomKey(),
394 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion
395 }
396 }
397 nextTollRequestType = 'CONNECT';
398 } else {
399 Clipperz.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message);
400 }
401
402 result = {
403 result: result,
404 toll: this.getTollForRequestType(nextTollRequestType)
405 }
406
407 return result;
408 },
409
410 //-------------------------------------------------------------------------
411
412 '_message': function(aConnection, someParameters) {
413 var result;
414
415 result = {};
416
417 //=====================================================================
418 //
419 // R E A D - O N L Y M e t h o d s
420 //
421 //=====================================================================
422 if (someParameters.message == 'getUserDetails') {
423 var recordsStats;
424 var recordReference;
425
426 recordsStats = {};
427 for (recordReference in aConnection['userData']['records']) {
428 recordsStats[recordReference] = {
429 'updateDate': aConnection['userData']['records'][recordReference]['updateDate']
430 }
431 }
432
433 result['header'] = this.userDetails(aConnection);
434 result['statistics'] = this.statistics(aConnection);
435 result['maxNumberOfRecords'] = aConnection['userData']['maxNumberOfRecords'];
436 result['version'] = aConnection['userData']['userDetailsVersion'];
437 result['recordsStats'] = recordsStats;
438
439 if (this.isReadOnly() == false) {
440 varlock;
441
442 if (typeof(aConnection['userData']['lock']) == 'undefined') {
443 aConnection['userData']['lock'] = "<<LOCK>>";
444 }
445
446 result['lock'] = aConnection['userData']['lock'];
447 }
448
449 //=====================================================================
450 } else if (someParameters.message == 'getRecordDetail') {
451/*
452 varrecordData;
453 var currentVersionData;
454
455 recordData = this.userData()['records'][someParameters['parameters']['reference']];
456 result['reference'] = someParameters['parameters']['reference'];
457 result['data'] = recordData['data'];
458 result['version'] = recordData['version'];
459 result['creationData'] = recordData['creationDate'];
460 result['updateDate'] = recordData['updateDate'];
461 result['accessDate'] = recordData['accessDate'];
462
463 currentVersionData = recordData['versions'][recordData['currentVersion']];
464
465 result['currentVersion'] = {};
466 result['currentVersion']['reference'] = recordData['currentVersion'];
467 result['currentVersion']['version'] = currentVersionData['version'];
468 result['currentVersion']['header'] = currentVersionData['header'];
469 result['currentVersion']['data'] = currentVersionData['data'];
470 result['currentVersion']['creationData'] = currentVersionData['creationDate'];
471 result['currentVersion']['updateDate'] = currentVersionData['updateDate'];
472 result['currentVersion']['accessDate'] = currentVersionData['accessDate'];
473 if (typeof(currentVersionData['previousVersion']) != 'undefined') {
474 result['currentVersion']['previousVersionKey'] = currentVersionData['previousVersionKey'];
475 result['currentVersion']['previousVersion'] = currentVersionData['previousVersion'];
476 }
477*/
478 MochiKit.Base.update(result, aConnection['userData']['records'][someParameters['parameters']['reference']]);
479 result['reference'] = someParameters['parameters']['reference'];
480
481 //=====================================================================
482 //
483 // R E A D - W R I T E M e t h o d s
484 //
485 //=====================================================================
486 } else if (someParameters.message == 'upgradeUserCredentials') {
487 if (this.isReadOnly() == false) {
488 var parameters;
489 var credentials;
490
491 parameters = someParameters['parameters'];
492 credentials = parameters['credentials'];
493
494 if ((credentials['C'] == null)
495 ||(credentials['s'] == null)
496 ||(credentials['v'] == null)
497 ||(credentials['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion)
498 ) {
499 result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed;
500 } else {
501 varoldCValue;
502 oldCValue = aConnection['C'];
503
504 this.data()['users'][credentials['C']] = aConnection['userData'];
505 aConnection['C'] = credentials['C'];
506
507 aConnection['userData']['s'] = credentials['s'];
508 aConnection['userData']['v'] = credentials['v'];
509 aConnection['userData']['version'] = credentials['version'];
510
511 aConnection['userData']['userDetails'] = parameters['user']['header'];
512 aConnection['userData']['userDetailsVersion'] = parameters['user']['version'];
513 aConnection['userData']['statistics'] = parameters['user']['statistics'];
514
515 aConnection['userData']['lock'] = parameters['user']['lock'];
516
517 delete this.data()['users'][oldCValue];
518
519 result = {result:"done", parameters:parameters};
520 }
521 } else {
522 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly;
523 }
524 //=====================================================================
525 /* } else if (someParameters.message == 'updateData') {
526 if (this.isReadOnly() == false) {
527 var i, c;
528
529 if (this.userData()['lock']!= someParameters['parameters']['user']['lock']) {
530 throw "the lock attribute is not processed correctly"
531 }
532
533 this.userData()['userDetails'] = someParameters['parameters']['user']['header'];
534 this.userData()['statistics'] = someParameters['parameters']['user']['statistics'];
535 this.userData()['userDetailsVersions']= someParameters['parameters']['user']['version'];
536
537 c = someParameters['parameters']['records'].length;
538 for (i=0; i<c; i++) {
539 var currentRecord;
540 var currentRecordData;
541
542 currentRecordData = someParameters['parameters']['records'][i];
543 currentRecord = this.userData()['records'][currentRecordData['record']['reference']];
544
545 if (currentRecord == null) {
546 }
547
548 currentRecord['data'] = currentRecordData['record']['data'];
549 currentRecord['version'] = currentRecordData['record']['version'];
550 currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference'];
551
552 currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = {
553 'data': currentRecordData['currentRecordVersion']['data'],
554 'version': currentRecordData['currentRecordVersion']['version'],
555 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'],
556 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey']
557 }
558 }
559
560 this.userData()['lock'] = Clipperz.PM.Crypto.randomKey();
561 result['lock'] = this.userData()['lock'];
562 result['result'] = 'done';
563 } else {
564 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly;
565 }
566 */ //=====================================================================
567 } else if (someParameters.message == 'saveChanges') {
568 if (this.isReadOnly() == false) {
569 var i, c;
570
571 if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) {
572 throw "the lock attribute is not processed correctly"
573 }
574
575 aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header'];
576 aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics'];
577 aConnection['userData']['userDetailsVersion']= someParameters['parameters']['user']['version'];
578
579 c = someParameters['parameters']['records']['updated'].length;
580 for (i=0; i<c; i++) {
581 var currentRecord;
582 var currentRecordData;
583
584 currentRecordData = someParameters['parameters']['records']['updated'][i];
585 currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']];
586
587 if (
588 (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined')
589 &&
590 (typeof(currentRecordData['currentRecordVersion']) == 'undefined')
591 ) {
592 throw "Record added without a recordVersion";
593 }
594
595 if (currentRecord == null) {
596 currentRecord = {};
597 currentRecord['versions'] = {};
598 currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date());
599 currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date());
600
601 aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord;
602 }
603
604 currentRecord['data'] = currentRecordData['record']['data'];
605 currentRecord['version']= currentRecordData['record']['version'];
606 currentRecord['updateDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date());
607
608 if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') {
609 currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference'];
610 currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = {
611 'data': currentRecordData['currentRecordVersion']['data'],
612 'version': currentRecordData['currentRecordVersion']['version'],
613 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'],
614 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'],
615 'creationDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()),
616 'updateDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()),
617 'accessDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date())
618 }
619 }
620 }
621
622 c = someParameters['parameters']['records']['deleted'].length;
623 for (i=0; i<c; i++) {
624 var currentRecordReference;
625
626 currentRecordReference = someParameters['parameters']['records']['deleted'][i];
627 delete aConnection['userData']['records'][currentRecordReference];
628 }
629
630 aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey();
631 result['lock'] = aConnection['userData']['lock'];
632 result['result'] = 'done';
633 } else {
634 throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly;
635 }
636
637 //=====================================================================
638 //
639 // U N H A N D L E D M e t h o d
640 //
641 //=====================================================================
642 } else {
643 Clipperz.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message);
644 }
645
646 result = {
647 result: result,
648 toll: this.getTollForRequestType('MESSAGE')
649 }
650
651 // return MochiKit.Async.succeed(result);
652 return result;
653 },
654
655 //-------------------------------------------------------------------------
656
657 '_logout': function(someParameters) {
658 // return MochiKit.Async.succeed({result: 'done'});
659 return {result: 'done'};
660 },
661
662 //=========================================================================
663 //#########################################################################
664
665 'isTestData': function(aConnection) {
666 return (typeof(aConnection['userData']['__masterkey_test_value__']) != 'undefined');
667 },
668
669 'userDetails': function(aConnection) {
670 var result;
671
672 if (this.isTestData(aConnection)) {
673 var serializedHeader;
674 var version;
675
676//Clipperz.logDebug("### test data");
677 version = aConnection['userData']['userDetailsVersion'];
678 serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']);
679 result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader);
680 } else {
681//Clipperz.logDebug("### NOT test data");
682 result = aConnection['userData']['userDetails'];
683 }
684
685 return result;
686 },
687
688 'statistics': function(aConnection) {
689 var result;
690
691 if (aConnection['userData']['statistics'] != null) {
692 if (this.isTestData(aConnection)) {
693 var serializedStatistics;
694 var version;
695
696 version = aConnection['userData']['userDetailsVersion'];
697 serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']);
698 result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics);
699 } else {
700 result = aConnection['userData']['statistics'];
701 }
702 } else {
703 result = null;
704 }
705
706 return result;
707 },
708
709/*
710 'userSerializedEncryptedData': function(someData) {
711 var deferredResult;
712 var deferredContext;
713
714 deferredContext = { 'data': someData };
715
716 deferredResult = new Clipperz.Async.Deferred('Proxy.Test.serializeUserEncryptedData', {trace:false});
717 deferredResult.addCallback(MochiKit.Base.bind(function(aDeferredContext) {
718 aDeferredContext['user'] = this.createUserUsingConfigurationData(aDeferredContext['data']);
719 return aDeferredContext;
720 }, this));
721 deferredResult.addCallback(function(aDeferredContext) {
722 // return aDeferredContext['user'].encryptedDataUsingVersion(aDeferredContext['data']['version']);
723 return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']);
724 });
725 deferredResult.addCallback(function(aUserEncryptedData) {
726 deferredContext['encryptedData'] = aUserEncryptedData;
727 return deferredContext;
728 });
729 deferredResult.addCallback(function(aDeferredContext) {
730 var connection;
731
732 connection = new Clipperz.PM.Connection.communicationProtocol.versions[aDeferredContext['data']['connectionVersion']]()
733 aDeferredContext['credentials'] = connection.serverSideUserCredentials(aDeferredContext['user'].username(),aDeferredContext['user'].passphrase());
734
735 return aDeferredContext;
736 });
737
738 // deferredResult.addCallback(function(aDeferredContext) {
739 // return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']);
740 // }, deferredContext);
741 // deferredResult.addCallback(function(aUserSerializedData) {
742 // });
743//
744 // deferredResult.addCallback(MochiKit.Async.succeed, deferredContext);
745 deferredResult.callback(deferredContext);
746
747 return deferredResult;
748 },
749
750 'createUserUsingConfigurationData': function(someData) {
751 var result;
752 var user;
753 var recordLabel;
754
755 user = new Clipperz.PM.DataModel.User();
756 user.initForTests();
757 user.setUsername(someData['username']);
758 user.setPassphrase(someData['passphrase']);
759
760 for (recordLabel in someData['records']) {
761 var recordData;
762 var record;
763 var i, c;
764
765 recordData = someData['records'][recordLabel];
766 record = new Clipperz.PM.DataModel.Record({user:user, label:recordLabel});
767 record.setNotes(recordData['notes']);
768
769 c = recordData['fields'].length;
770 for (i=0; i<c; i++) {
771 var recordField;
772
773 recordField = new Clipperz.PM.DataModel.RecordField();
774 recordField.setLabel(recordData['fields'][i]['name']);
775 recordField.setValue(recordData['fields'][i]['value']);
776 recordField.setType(recordData['fields'][i]['type']);
777 record.addField(recordField);
778 }
779 user.addRecord(record, true);
780 }
781
782 result = user;
783
784 return result;
785 },
786*/
787 //=========================================================================
788 __syntaxFix__: "syntax fix"
789});
790
791Clipperz.PM.Proxy.Offline.DataStore['exception'] = {
792 'ReadOnly': new MochiKit.Base.NamedError("Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly")
793}; \ No newline at end of file