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,280 +1,277 @@ | |||
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'], |