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