Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js index 4d3ba08..d5336be 100644 --- a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js +++ b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js | |||
@@ -1,536 +1,533 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer to http://www.clipperz.com. |
12 | 9 | ||
13 | * Javascript Crypto Library is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
14 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
15 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
16 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
17 | 14 | ||
18 | * Javascript Crypto Library is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
22 | 19 | ||
23 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
24 | License along with Javascript Crypto Library. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
25 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
26 | 23 | ||
27 | */ | 24 | */ |
28 | 25 | ||
29 | try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) { | 26 | try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) { |
30 | throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!"; | 27 | throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!"; |
31 | } | 28 | } |
32 | 29 | ||
33 | //============================================================================= | 30 | //============================================================================= |
34 | 31 | ||
35 | Clipperz.PM.Proxy.Offline.DataStore = function(args) { | 32 | Clipperz.PM.Proxy.Offline.DataStore = function(args) { |
36 | args = args || {}; | 33 | args = args || {}; |
37 | 34 | ||
38 | this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); | 35 | this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); |
39 | this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); | 36 | this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); |
40 | this._shouldPayTolls = args.shouldPayTolls || false; | 37 | this._shouldPayTolls = args.shouldPayTolls || false; |
41 | 38 | ||
42 | this._tolls = {}; | 39 | this._tolls = {}; |
43 | this._connections = {}; | 40 | this._connections = {}; |
44 | 41 | ||
45 | this._b = null; | 42 | this._b = null; |
46 | this._B = null; | 43 | this._B = null; |
47 | this._A = null; | 44 | this._A = null; |
48 | this._userData = null; | 45 | this._userData = null; |
49 | 46 | ||
50 | return this; | 47 | return this; |
51 | } | 48 | } |
52 | 49 | ||
53 | //Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | 50 | //Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { |
54 | Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, { | 51 | Clipperz.PM.Proxy.Offline.DataStore.prototype = MochiKit.Base.update(null, { |
55 | 52 | ||
56 | //------------------------------------------------------------------------- | 53 | //------------------------------------------------------------------------- |
57 | 54 | ||
58 | 'isReadOnly': function () { | 55 | 'isReadOnly': function () { |
59 | return this._isReadOnly; | 56 | return this._isReadOnly; |
60 | }, | 57 | }, |
61 | 58 | ||
62 | //------------------------------------------------------------------------- | 59 | //------------------------------------------------------------------------- |
63 | 60 | ||
64 | 'shouldPayTolls': function() { | 61 | 'shouldPayTolls': function() { |
65 | return this._shouldPayTolls; | 62 | return this._shouldPayTolls; |
66 | }, | 63 | }, |
67 | 64 | ||
68 | //------------------------------------------------------------------------- | 65 | //------------------------------------------------------------------------- |
69 | 66 | ||
70 | 'data': function () { | 67 | 'data': function () { |
71 | return this._data; | 68 | return this._data; |
72 | }, | 69 | }, |
73 | 70 | ||
74 | //------------------------------------------------------------------------- | 71 | //------------------------------------------------------------------------- |
75 | 72 | ||
76 | 'tolls': function () { | 73 | 'tolls': function () { |
77 | return this._tolls; | 74 | return this._tolls; |
78 | }, | 75 | }, |
79 | 76 | ||
80 | //------------------------------------------------------------------------- | 77 | //------------------------------------------------------------------------- |
81 | 78 | ||
82 | 'connections': function () { | 79 | 'connections': function () { |
83 | return this._connections; | 80 | return this._connections; |
84 | }, | 81 | }, |
85 | 82 | ||
86 | //========================================================================= | 83 | //========================================================================= |
87 | 84 | ||
88 | 'resetData': function() { | 85 | 'resetData': function() { |
89 | this._data = { | 86 | this._data = { |
90 | 'users': { | 87 | 'users': { |
91 | 'catchAllUser': { | 88 | 'catchAllUser': { |
92 | __masterkey_test_value__: 'masterkey', | 89 | __masterkey_test_value__: 'masterkey', |
93 | s: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00', | 90 | s: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00', |
94 | v: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00' | 91 | v: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00' |
95 | } | 92 | } |
96 | } | 93 | } |
97 | }; | 94 | }; |
98 | }, | 95 | }, |
99 | 96 | ||
100 | //------------------------------------------------------------------------- | 97 | //------------------------------------------------------------------------- |
101 | 98 | ||
102 | 'setupWithEncryptedData': function(someData) { | 99 | 'setupWithEncryptedData': function(someData) { |
103 | this._data = Clipperz.Base.deepClone(someData); | 100 | this._data = Clipperz.Base.deepClone(someData); |
104 | }, | 101 | }, |
105 | 102 | ||
106 | //------------------------------------------------------------------------- | 103 | //------------------------------------------------------------------------- |
107 | 104 | ||
108 | 'setupWithData': function(someData) { | 105 | 'setupWithData': function(someData) { |
109 | var deferredResult; | 106 | var deferredResult; |
110 | var resultData; | 107 | var resultData; |
111 | var i, c; | 108 | var i, c; |
112 | 109 | ||
113 | //Clipperz.log(">>> Proxy.Test.setupWithData"); | 110 | //Clipperz.log(">>> Proxy.Test.setupWithData"); |
114 | resultData = this._data; | 111 | resultData = this._data; |
115 | 112 | ||
116 | deferredResult = new MochiKit.Async.Deferred(); | 113 | deferredResult = new MochiKit.Async.Deferred(); |
117 | c = someData['users'].length; | 114 | c = someData['users'].length; |
118 | 115 | ||
119 | for (i=0; i<c; i++) { | 116 | for (i=0; i<c; i++) { |
120 | varnewConnection; | 117 | varnewConnection; |
121 | varrecordConfiguration; | 118 | varrecordConfiguration; |
122 | 119 | ||
123 | deferredResult.addCallback(MochiKit.Base.method(this, 'userSerializedEncryptedData', someData['users'][i])); | 120 | deferredResult.addCallback(MochiKit.Base.method(this, 'userSerializedEncryptedData', someData['users'][i])); |
124 | deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) { | 121 | deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) { |
125 | //console.log("SERIALIZED USER", aUserSerializationContext); | 122 | //console.log("SERIALIZED USER", aUserSerializationContext); |
126 | resultData['users'][aUserSerializationContext['credentials']['C']] = { | 123 | resultData['users'][aUserSerializationContext['credentials']['C']] = { |
127 | 's': aUserSerializationContext['credentials']['s'], | 124 | 's': aUserSerializationContext['credentials']['s'], |
128 | 'v': aUserSerializationContext['credentials']['v'], | 125 | 'v': aUserSerializationContext['credentials']['v'], |
129 | 'version': aUserSerializationContext['data']['connectionVersion'], | 126 | 'version': aUserSerializationContext['data']['connectionVersion'], |
130 | 'userDetails': aUserSerializationContext['encryptedData']['user']['header'], | 127 | 'userDetails': aUserSerializationContext['encryptedData']['user']['header'], |
131 | 'userDetailsVersion':aUserSerializationContext['encryptedData']['user']['version'], | 128 | 'userDetailsVersion':aUserSerializationContext['encryptedData']['user']['version'], |
132 | 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'], | 129 | 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'], |
133 | 'lock': aUserSerializationContext['encryptedData']['user']['lock'], | 130 | 'lock': aUserSerializationContext['encryptedData']['user']['lock'], |
134 | 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records']) | 131 | 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records']) |
135 | } | 132 | } |
136 | }, this)); | 133 | }, this)); |
137 | } | 134 | } |
138 | 135 | ||
139 | deferredResult.addCallback(MochiKit.Base.bind(function() { | 136 | deferredResult.addCallback(MochiKit.Base.bind(function() { |
140 | //console.log("this._data", resultData); | 137 | //console.log("this._data", resultData); |
141 | this._data = resultData; | 138 | this._data = resultData; |
142 | }, this)); | 139 | }, this)); |
143 | 140 | ||
144 | deferredResult.callback(); | 141 | deferredResult.callback(); |
145 | //Clipperz.log("<<< Proxy.Test.setupWithData"); | 142 | //Clipperz.log("<<< Proxy.Test.setupWithData"); |
146 | 143 | ||
147 | return deferredResult; | 144 | return deferredResult; |
148 | }, | 145 | }, |
149 | 146 | ||
150 | //========================================================================= | 147 | //========================================================================= |
151 | 148 | ||
152 | 'b': function() { | 149 | 'b': function() { |
153 | return this._b; | 150 | return this._b; |
154 | }, | 151 | }, |
155 | 152 | ||
156 | 'set_b': function(aValue) { | 153 | 'set_b': function(aValue) { |
157 | this._b = aValue; | 154 | this._b = aValue; |
158 | }, | 155 | }, |
159 | 156 | ||
160 | //------------------------------------------------------------------------- | 157 | //------------------------------------------------------------------------- |
161 | 158 | ||
162 | 'B': function() { | 159 | 'B': function() { |
163 | return this._B; | 160 | return this._B; |
164 | }, | 161 | }, |
165 | 162 | ||
166 | 'set_B': function(aValue) { | 163 | 'set_B': function(aValue) { |
167 | this._B = aValue; | 164 | this._B = aValue; |
168 | }, | 165 | }, |
169 | 166 | ||
170 | //------------------------------------------------------------------------- | 167 | //------------------------------------------------------------------------- |
171 | 168 | ||
172 | 'A': function() { | 169 | 'A': function() { |
173 | return this._A; | 170 | return this._A; |
174 | }, | 171 | }, |
175 | 172 | ||
176 | 'set_A': function(aValue) { | 173 | 'set_A': function(aValue) { |
177 | this._A = aValue; | 174 | this._A = aValue; |
178 | }, | 175 | }, |
179 | 176 | ||
180 | //------------------------------------------------------------------------- | 177 | //------------------------------------------------------------------------- |
181 | 178 | ||
182 | 'userData': function() { | 179 | 'userData': function() { |
183 | return this._userData; | 180 | return this._userData; |
184 | }, | 181 | }, |
185 | 182 | ||
186 | 'setUserData': function(aValue) { | 183 | 'setUserData': function(aValue) { |
187 | this._userData = aValue; | 184 | this._userData = aValue; |
188 | }, | 185 | }, |
189 | 186 | ||
190 | //========================================================================= | 187 | //========================================================================= |
191 | 188 | ||
192 | 'getTollForRequestType': function (aRequestType) { | 189 | 'getTollForRequestType': function (aRequestType) { |
193 | varresult; | 190 | varresult; |
194 | vartargetValue; | 191 | vartargetValue; |
195 | var cost; | 192 | var cost; |
196 | 193 | ||
197 | targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); | 194 | targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); |
198 | switch (aRequestType) { | 195 | switch (aRequestType) { |
199 | case 'REGISTER': | 196 | case 'REGISTER': |
200 | cost = 5; | 197 | cost = 5; |
201 | break; | 198 | break; |
202 | case 'CONNECT': | 199 | case 'CONNECT': |
203 | cost = 5; | 200 | cost = 5; |
204 | break; | 201 | break; |
205 | case 'MESSAGE': | 202 | case 'MESSAGE': |
206 | cost = 2; | 203 | cost = 2; |
207 | break; | 204 | break; |
208 | } | 205 | } |
209 | 206 | ||
210 | result = { | 207 | result = { |
211 | requestType: aRequestType, | 208 | requestType: aRequestType, |
212 | targetValue: targetValue, | 209 | targetValue: targetValue, |
213 | cost: cost | 210 | cost: cost |
214 | } | 211 | } |
215 | 212 | ||
216 | if (this.shouldPayTolls()) { | 213 | if (this.shouldPayTolls()) { |
217 | this.tolls()[targetValue] = result; | 214 | this.tolls()[targetValue] = result; |
218 | } | 215 | } |
219 | 216 | ||
220 | return result; | 217 | return result; |
221 | }, | 218 | }, |
222 | 219 | ||
223 | //------------------------------------------------------------------------- | 220 | //------------------------------------------------------------------------- |
224 | 221 | ||
225 | 'checkToll': function (aFunctionName, someParameters) { | 222 | 'checkToll': function (aFunctionName, someParameters) { |
226 | if (this.shouldPayTolls()) { | 223 | if (this.shouldPayTolls()) { |
227 | var localToll; | 224 | var localToll; |
228 | vartollParameters; | 225 | vartollParameters; |
229 | 226 | ||
230 | tollParameters = someParameters['toll']; | 227 | tollParameters = someParameters['toll']; |
231 | localToll = this.tolls()[tollParameters['targetValue']]; | 228 | localToll = this.tolls()[tollParameters['targetValue']]; |
232 | 229 | ||
233 | if (localToll != null) { | 230 | if (localToll != null) { |
234 | if (! Clipperz.PM.Toll.validate(tollParameters['targetValue'], tollParameters['toll'], localToll['cost'])) { | 231 | if (! Clipperz.PM.Toll.validate(tollParameters['targetValue'], tollParameters['toll'], localToll['cost'])) { |
235 | throw "Toll value too low."; | 232 | throw "Toll value too low."; |
236 | }; | 233 | }; |
237 | } else { | 234 | } else { |
238 | throw "Missing toll"; | 235 | throw "Missing toll"; |
239 | } | 236 | } |
240 | } | 237 | } |
241 | }, | 238 | }, |
242 | 239 | ||
243 | //========================================================================= | 240 | //========================================================================= |
244 | 241 | ||
245 | 'processMessage': function(aFunctionName, someParameters) { | 242 | 'processMessage': function(aFunctionName, someParameters) { |
246 | var result; | 243 | var result; |
247 | 244 | ||
248 | switch(aFunctionName) { | 245 | switch(aFunctionName) { |
249 | case 'knock': | 246 | case 'knock': |
250 | result = this._knock(someParameters); | 247 | result = this._knock(someParameters); |
251 | break; | 248 | break; |
252 | case 'registration': | 249 | case 'registration': |
253 | this.checkToll(aFunctionName, someParameters); | 250 | this.checkToll(aFunctionName, someParameters); |
254 | result = this._registration(someParameters.parameters); | 251 | result = this._registration(someParameters.parameters); |
255 | break; | 252 | break; |
256 | case 'handshake': | 253 | case 'handshake': |
257 | this.checkToll(aFunctionName, someParameters); | 254 | this.checkToll(aFunctionName, someParameters); |
258 | result = this._handshake(someParameters.parameters); | 255 | result = this._handshake(someParameters.parameters); |
259 | break; | 256 | break; |
260 | case 'message': | 257 | case 'message': |
261 | this.checkToll(aFunctionName, someParameters); | 258 | this.checkToll(aFunctionName, someParameters); |
262 | result = this._message(someParameters.parameters); | 259 | result = this._message(someParameters.parameters); |
263 | break; | 260 | break; |
264 | case 'logout': | 261 | case 'logout': |
265 | result = this._logout(someParameters.parameters); | 262 | result = this._logout(someParameters.parameters); |
266 | break; | 263 | break; |
267 | } | 264 | } |
268 | 265 | ||
269 | return result; | 266 | return result; |
270 | }, | 267 | }, |
271 | 268 | ||
272 | //========================================================================= | 269 | //========================================================================= |
273 | 270 | ||
274 | '_knock': function(someParameters) { | 271 | '_knock': function(someParameters) { |
275 | var result; | 272 | var result; |
276 | 273 | ||
277 | result = { | 274 | result = { |
278 | toll: this.getTollForRequestType(someParameters['requestType']) | 275 | toll: this.getTollForRequestType(someParameters['requestType']) |
279 | // toll: { | 276 | // toll: { |
280 | // requestType: someParameters['requestType'], | 277 | // requestType: someParameters['requestType'], |
281 | // targetValue: "3a1ba0be23580f902885c6c8a6b035e228ed1ca74d77de5f9bb0e0c899f07cfe", | 278 | // targetValue: "3a1ba0be23580f902885c6c8a6b035e228ed1ca74d77de5f9bb0e0c899f07cfe", |
282 | // cost: | 279 | // cost: |
283 | // } | 280 | // } |
284 | } | 281 | } |
285 | 282 | ||
286 | return result; | 283 | return result; |
287 | }, | 284 | }, |
288 | 285 | ||
289 | //------------------------------------------------------------------------- | 286 | //------------------------------------------------------------------------- |
290 | 287 | ||
291 | '_registration': function(someParameters) { | 288 | '_registration': function(someParameters) { |
292 | //console.log("_registration", someParameters); | 289 | //console.log("_registration", someParameters); |
293 | if (this.isReadOnly() == false) { | 290 | if (this.isReadOnly() == false) { |
294 | if (typeof(this.data()['users'][someParameters['credentials']['C']]) == 'undefined') { | 291 | if (typeof(this.data()['users'][someParameters['credentials']['C']]) == 'undefined') { |
295 | this.data()['users'][someParameters['credentials']['C']] = { | 292 | this.data()['users'][someParameters['credentials']['C']] = { |
296 | 's': someParameters['credentials']['s'], | 293 | 's': someParameters['credentials']['s'], |
297 | 'v': someParameters['credentials']['v'], | 294 | 'v': someParameters['credentials']['v'], |
298 | 'version':someParameters['credentials']['version'], | 295 | 'version':someParameters['credentials']['version'], |
299 | // 'lock': someParameters['user']['lock'], | 296 | // 'lock': someParameters['user']['lock'], |
300 | 'lock': Clipperz.Crypto.Base.generateRandomSeed(), | 297 | 'lock': Clipperz.Crypto.Base.generateRandomSeed(), |
301 | // 'maxNumberOfRecords':'100', | 298 | // 'maxNumberOfRecords':'100', |
302 | 'userDetails': someParameters['user']['header'], | 299 | 'userDetails': someParameters['user']['header'], |
303 | 'statistics': someParameters['user']['statistics'], | 300 | 'statistics': someParameters['user']['statistics'], |
304 | 'userDetailsVersion':someParameters['user']['version'], | 301 | 'userDetailsVersion':someParameters['user']['version'], |
305 | 'records':{} | 302 | 'records':{} |
306 | } | 303 | } |
307 | } else { | 304 | } else { |
308 | throw "user already exists"; | 305 | throw "user already exists"; |
309 | } | 306 | } |
310 | } else { | 307 | } else { |
311 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 308 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
312 | } | 309 | } |
313 | 310 | ||
314 | result = { | 311 | result = { |
315 | result: { | 312 | result: { |
316 | 'lock': this.data()['users'][someParameters['credentials']['C']]['lock'], | 313 | 'lock': this.data()['users'][someParameters['credentials']['C']]['lock'], |
317 | 'result':'done' | 314 | 'result':'done' |
318 | }, | 315 | }, |
319 | toll: this.getTollForRequestType('CONNECT') | 316 | toll: this.getTollForRequestType('CONNECT') |
320 | } | 317 | } |
321 | 318 | ||
322 | return MochiKit.Async.succeed(result); | 319 | return MochiKit.Async.succeed(result); |
323 | }, | 320 | }, |
324 | 321 | ||
325 | //------------------------------------------------------------------------- | 322 | //------------------------------------------------------------------------- |
326 | 323 | ||
327 | '_handshake': function(someParameters) { | 324 | '_handshake': function(someParameters) { |
328 | var result; | 325 | var result; |
329 | varnextTollRequestType; | 326 | varnextTollRequestType; |
330 | 327 | ||
331 | //Clipperz.log(">>> Proxy.Offline.DataStore._handshake"); | 328 | //Clipperz.log(">>> Proxy.Offline.DataStore._handshake"); |
332 | result = {}; | 329 | result = {}; |
333 | if (someParameters.message == "connect") { | 330 | if (someParameters.message == "connect") { |
334 | var userData; | 331 | var userData; |
335 | var randomBytes; | 332 | var randomBytes; |
336 | var b, B, v; | 333 | var b, B, v; |
337 | 334 | ||
338 | //console.log(">>> Proxy.Offline.DataStore._handshake.connect", someParameters); | 335 | //console.log(">>> Proxy.Offline.DataStore._handshake.connect", someParameters); |
339 | userData = this.data()['users'][someParameters.parameters.C]; | 336 | userData = this.data()['users'][someParameters.parameters.C]; |
340 | 337 | ||
341 | if ((typeof(userData) != 'undefined') && (userData['version'] == someParameters.version)) { | 338 | if ((typeof(userData) != 'undefined') && (userData['version'] == someParameters.version)) { |
342 | this.setUserData(userData); | 339 | this.setUserData(userData); |
343 | } else { | 340 | } else { |
344 | this.setUserData(this.data()['users']['catchAllUser']); | 341 | this.setUserData(this.data()['users']['catchAllUser']); |
345 | } | 342 | } |
346 | 343 | ||
347 | randomBytes = Clipperz.Crypto.Base.generateRandomSeed(); | 344 | randomBytes = Clipperz.Crypto.Base.generateRandomSeed(); |
348 | this.set_b(new Clipperz.Crypto.BigInt(randomBytes, 16)); | 345 | this.set_b(new Clipperz.Crypto.BigInt(randomBytes, 16)); |
349 | v = new Clipperz.Crypto.BigInt(this.userData()['v'], 16); | 346 | v = new Clipperz.Crypto.BigInt(this.userData()['v'], 16); |
350 | this.set_B(v.add(Clipperz.Crypto.SRP.g().powerModule(this.b(), Clipperz.Crypto.SRP.n()))); | 347 | this.set_B(v.add(Clipperz.Crypto.SRP.g().powerModule(this.b(), Clipperz.Crypto.SRP.n()))); |
351 | 348 | ||
352 | this.set_A(someParameters.parameters.A); | 349 | this.set_A(someParameters.parameters.A); |
353 | 350 | ||
354 | result['s'] = this.userData()['s']; | 351 | result['s'] = this.userData()['s']; |
355 | result['B'] = this.B().asString(16); | 352 | result['B'] = this.B().asString(16); |
356 | 353 | ||
357 | nextTollRequestType = 'CONNECT'; | 354 | nextTollRequestType = 'CONNECT'; |
358 | } else if (someParameters.message == "credentialCheck") { | 355 | } else if (someParameters.message == "credentialCheck") { |
359 | var v, u, S, A, K, M1; | 356 | var v, u, S, A, K, M1; |
360 | 357 | ||
361 | //console.log(">>> Proxy.Offline.DataStore._handshake.credentialCheck", someParameters); | 358 | //console.log(">>> Proxy.Offline.DataStore._handshake.credentialCheck", someParameters); |
362 | v = new Clipperz.Crypto.BigInt(this.userData()['v'], 16); | 359 | v = new Clipperz.Crypto.BigInt(this.userData()['v'], 16); |
363 | u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(this.B().asString(10))).toHexString(), 16); | 360 | u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(this.B().asString(10))).toHexString(), 16); |
364 | A = new Clipperz.Crypto.BigInt(this.A(), 16); | 361 | A = new Clipperz.Crypto.BigInt(this.A(), 16); |
365 | S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(this.b(), Clipperz.Crypto.SRP.n()); | 362 | S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(this.b(), Clipperz.Crypto.SRP.n()); |
366 | 363 | ||
367 | K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2); | 364 | K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2); |
368 | 365 | ||
369 | M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + this.B().asString(10) + K)).toHexString().slice(2); | 366 | M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + this.B().asString(10) + K)).toHexString().slice(2); |
370 | if (someParameters.parameters.M1 == M1) { | 367 | if (someParameters.parameters.M1 == M1) { |
371 | var M2; | 368 | var M2; |
372 | 369 | ||
373 | M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2); | 370 | M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2); |
374 | result['M2'] = M2; | 371 | result['M2'] = M2; |
375 | } else { | 372 | } else { |
376 | throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); | 373 | throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); |
377 | } | 374 | } |
378 | 375 | ||
379 | nextTollRequestType = 'MESSAGE'; | 376 | nextTollRequestType = 'MESSAGE'; |
380 | } else if (someParameters.message == "oneTimePassword") { | 377 | } else if (someParameters.message == "oneTimePassword") { |
381 | var otpData; | 378 | var otpData; |
382 | 379 | ||
383 | //console.log("HANDSHAKE WITH OTP", someParameters.parameters.oneTimePasswordKey); | 380 | //console.log("HANDSHAKE WITH OTP", someParameters.parameters.oneTimePasswordKey); |
384 | //console.log("someParameters", someParameters); | 381 | //console.log("someParameters", someParameters); |
385 | //console.log("data.OTP", Clipperz.Base.serializeJSON(this.data()['onetimePasswords'])); | 382 | //console.log("data.OTP", Clipperz.Base.serializeJSON(this.data()['onetimePasswords'])); |
386 | otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; | 383 | otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; |
387 | 384 | ||
388 | try { | 385 | try { |
389 | if (typeof(otpData) != 'undefined') { | 386 | if (typeof(otpData) != 'undefined') { |
390 | if (otpData['status'] == 'ACTIVE') { | 387 | if (otpData['status'] == 'ACTIVE') { |
391 | if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { | 388 | if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { |
392 | result = { | 389 | result = { |
393 | 'data': otpData['data'], | 390 | 'data': otpData['data'], |
394 | 'version':otpData['version'] | 391 | 'version':otpData['version'] |
395 | } | 392 | } |
396 | 393 | ||
397 | otpData['status'] = 'REQUESTED'; | 394 | otpData['status'] = 'REQUESTED'; |
398 | } else { | 395 | } else { |
399 | otpData['status'] = 'DISABLED'; | 396 | otpData['status'] = 'DISABLED'; |
400 | throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; | 397 | throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; |
401 | } | 398 | } |
402 | } else { | 399 | } else { |
403 | throw "The requested One Time Password was not active"; | 400 | throw "The requested One Time Password was not active"; |
404 | } | 401 | } |
405 | } else { | 402 | } else { |
406 | throw "The requested One Time Password has not been found" | 403 | throw "The requested One Time Password has not been found" |
407 | } | 404 | } |
408 | } catch (exception) { | 405 | } catch (exception) { |
409 | result = { | 406 | result = { |
410 | 'data': Clipperz.PM.Crypto.randomKey(), | 407 | 'data': Clipperz.PM.Crypto.randomKey(), |
411 | 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion | 408 | 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion |
412 | } | 409 | } |
413 | } | 410 | } |
414 | nextTollRequestType = 'CONNECT'; | 411 | nextTollRequestType = 'CONNECT'; |
415 | } else { | 412 | } else { |
416 | MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); | 413 | MochiKit.Logging.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); |
417 | } | 414 | } |
418 | //console.log("<<< Proxy.Offline._handshake", result); | 415 | //console.log("<<< Proxy.Offline._handshake", result); |
419 | 416 | ||
420 | result = { | 417 | result = { |
421 | result: result, | 418 | result: result, |
422 | toll: this.getTollForRequestType(nextTollRequestType) | 419 | toll: this.getTollForRequestType(nextTollRequestType) |
423 | } | 420 | } |
424 | 421 | ||
425 | return MochiKit.Async.succeed(result); | 422 | return MochiKit.Async.succeed(result); |
426 | }, | 423 | }, |
427 | 424 | ||
428 | //------------------------------------------------------------------------- | 425 | //------------------------------------------------------------------------- |
429 | 426 | ||
430 | '_message': function(someParameters) { | 427 | '_message': function(someParameters) { |
431 | var result; | 428 | var result; |
432 | 429 | ||
433 | result = {}; | 430 | result = {}; |
434 | 431 | ||
435 | //===================================================================== | 432 | //===================================================================== |
436 | // | 433 | // |
437 | // R E A D - O N L Y M e t h o d s | 434 | // R E A D - O N L Y M e t h o d s |
438 | // | 435 | // |
439 | //===================================================================== | 436 | //===================================================================== |
440 | if (someParameters.message == 'getUserDetails') { | 437 | if (someParameters.message == 'getUserDetails') { |
441 | var recordsStats; | 438 | var recordsStats; |
442 | var recordReference; | 439 | var recordReference; |
443 | 440 | ||
444 | //try { | 441 | //try { |
445 | recordsStats = {}; | 442 | recordsStats = {}; |
446 | for (recordReference in this.userData()['records']) { | 443 | for (recordReference in this.userData()['records']) { |
447 | recordsStats[recordReference] = { | 444 | recordsStats[recordReference] = { |
448 | 'updateDate': this.userData()['records'][recordReference]['updateDate'] | 445 | 'updateDate': this.userData()['records'][recordReference]['updateDate'] |
449 | } | 446 | } |
450 | } | 447 | } |
451 | 448 | ||
452 | result['header'] = this.userDetails(); | 449 | result['header'] = this.userDetails(); |
453 | result['statistics'] = this.statistics(); | 450 | result['statistics'] = this.statistics(); |
454 | result['maxNumberOfRecords'] = this.userData()['maxNumberOfRecords']; | 451 | result['maxNumberOfRecords'] = this.userData()['maxNumberOfRecords']; |
455 | result['version'] = this.userData()['userDetailsVersion']; | 452 | result['version'] = this.userData()['userDetailsVersion']; |
456 | result['recordsStats'] = recordsStats; | 453 | result['recordsStats'] = recordsStats; |
457 | 454 | ||
458 | if (this.isReadOnly() == false) { | 455 | if (this.isReadOnly() == false) { |
459 | varlock; | 456 | varlock; |
460 | 457 | ||
461 | if (typeof(this.userData()['lock']) == 'undefined') { | 458 | if (typeof(this.userData()['lock']) == 'undefined') { |
462 | this.userData()['lock'] = "<<LOCK>>"; | 459 | this.userData()['lock'] = "<<LOCK>>"; |
463 | } | 460 | } |
464 | 461 | ||
465 | result['lock'] = this.userData()['lock']; | 462 | result['lock'] = this.userData()['lock']; |
466 | } | 463 | } |
467 | //} catch (exception) { | 464 | //} catch (exception) { |
468 | //console.log("*#*#*#*#*#*#*", exception); | 465 | //console.log("*#*#*#*#*#*#*", exception); |
469 | //throw exception; | 466 | //throw exception; |
470 | //} | 467 | //} |
471 | //===================================================================== | 468 | //===================================================================== |
472 | } else if (someParameters.message == 'getRecordDetail') { | 469 | } else if (someParameters.message == 'getRecordDetail') { |
473 | recordData = this.userData()['records'][someParameters['parameters']['reference']]; | 470 | recordData = this.userData()['records'][someParameters['parameters']['reference']]; |
474 | 471 | ||
475 | result['reference'] = someParameters['parameters']['reference']; | 472 | result['reference'] = someParameters['parameters']['reference']; |
476 | result['data'] = recordData['data']; | 473 | result['data'] = recordData['data']; |
477 | result['version'] = recordData['version']; | 474 | result['version'] = recordData['version']; |
478 | result['creationData'] = recordData['creationDate']; | 475 | result['creationData'] = recordData['creationDate']; |
479 | result['updateDate'] = recordData['updateDate']; | 476 | result['updateDate'] = recordData['updateDate']; |
480 | result['accessDate'] = recordData['accessDate']; | 477 | result['accessDate'] = recordData['accessDate']; |
481 | 478 | ||
482 | currentVersionData = recordData['versions'][recordData['currentVersion']]; | 479 | currentVersionData = recordData['versions'][recordData['currentVersion']]; |
483 | 480 | ||
484 | result['currentVersion'] = {}; | 481 | result['currentVersion'] = {}; |
485 | result['currentVersion']['reference'] = recordData['currentVersion']; | 482 | result['currentVersion']['reference'] = recordData['currentVersion']; |
486 | result['currentVersion']['version'] = currentVersionData['version']; | 483 | result['currentVersion']['version'] = currentVersionData['version']; |
487 | result['currentVersion']['header'] = currentVersionData['header']; | 484 | result['currentVersion']['header'] = currentVersionData['header']; |
488 | result['currentVersion']['data'] = currentVersionData['data']; | 485 | result['currentVersion']['data'] = currentVersionData['data']; |
489 | result['currentVersion']['creationData'] = currentVersionData['creationDate']; | 486 | result['currentVersion']['creationData'] = currentVersionData['creationDate']; |
490 | result['currentVersion']['updateDate'] = currentVersionData['updateDate']; | 487 | result['currentVersion']['updateDate'] = currentVersionData['updateDate']; |
491 | result['currentVersion']['accessDate'] = currentVersionData['accessDate']; | 488 | result['currentVersion']['accessDate'] = currentVersionData['accessDate']; |
492 | if (typeof(currentVersionData['previousVersion']) != 'undefined') { | 489 | if (typeof(currentVersionData['previousVersion']) != 'undefined') { |
493 | result['currentVersion']['previousVersionKey'] = currentVersionData['previousVersionKey']; | 490 | result['currentVersion']['previousVersionKey'] = currentVersionData['previousVersionKey']; |
494 | result['currentVersion']['previousVersion'] = currentVersionData['previousVersion']; | 491 | result['currentVersion']['previousVersion'] = currentVersionData['previousVersion']; |
495 | } | 492 | } |
496 | 493 | ||
497 | //===================================================================== | 494 | //===================================================================== |
498 | // | 495 | // |
499 | // R E A D - W R I T E M e t h o d s | 496 | // R E A D - W R I T E M e t h o d s |
500 | // | 497 | // |
501 | //===================================================================== | 498 | //===================================================================== |
502 | } else if (someParameters.message == 'upgradeUserCredentials') { | 499 | } else if (someParameters.message == 'upgradeUserCredentials') { |
503 | if (this.isReadOnly() == false) { | 500 | if (this.isReadOnly() == false) { |
504 | var parameters; | 501 | var parameters; |
505 | parameters = someParameters.parameters; | 502 | parameters = someParameters.parameters; |
506 | 503 | ||
507 | if (parameters['C'] == null) { | 504 | if (parameters['C'] == null) { |
508 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; | 505 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; |
509 | } else if (parameters['s'] == null) { | 506 | } else if (parameters['s'] == null) { |
510 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; | 507 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; |
511 | } else if (parameters['v'] == null) { | 508 | } else if (parameters['v'] == null) { |
512 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; | 509 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; |
513 | } else if (parameters['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) { | 510 | } else if (parameters['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) { |
514 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; | 511 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; |
515 | } else { | 512 | } else { |
516 | result = {result:"done", parameters:parameters}; | 513 | result = {result:"done", parameters:parameters}; |
517 | } | 514 | } |
518 | } else { | 515 | } else { |
519 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 516 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
520 | } | 517 | } |
521 | //===================================================================== | 518 | //===================================================================== |
522 | /* } else if (someParameters.message == 'updateData') { | 519 | /* } else if (someParameters.message == 'updateData') { |
523 | if (this.isReadOnly() == false) { | 520 | if (this.isReadOnly() == false) { |
524 | var i, c; | 521 | var i, c; |
525 | 522 | ||
526 | //console.log("###==============================================================="); | 523 | //console.log("###==============================================================="); |
527 | //console.log("###>>>", Clipperz.Base.serializeJSON(someParameters)); | 524 | //console.log("###>>>", Clipperz.Base.serializeJSON(someParameters)); |
528 | //console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData())); | 525 | //console.log("###--- userData", Clipperz.Base.serializeJSON(this.userData())); |
529 | if (this.userData()['lock']!= someParameters['parameters']['user']['lock']) { | 526 | if (this.userData()['lock']!= someParameters['parameters']['user']['lock']) { |
530 | throw "the lock attribute is not processed correctly" | 527 | throw "the lock attribute is not processed correctly" |
531 | } | 528 | } |
532 | 529 | ||
533 | this.userData()['userDetails'] = someParameters['parameters']['user']['header']; | 530 | this.userData()['userDetails'] = someParameters['parameters']['user']['header']; |
534 | this.userData()['statistics'] = someParameters['parameters']['user']['statistics']; | 531 | this.userData()['statistics'] = someParameters['parameters']['user']['statistics']; |
535 | this.userData()['userDetailsVersions']= someParameters['parameters']['user']['version']; | 532 | this.userData()['userDetailsVersions']= someParameters['parameters']['user']['version']; |
536 | 533 | ||