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,482 +1,497 @@
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) {