author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /frontend/beta/js/Clipperz/PM/Connection.js | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Connection.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Connection.js | 584 |
1 files changed, 584 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Connection.js b/frontend/beta/js/Clipperz/PM/Connection.js new file mode 100644 index 0000000..cf37ccc --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Connection.js | |||
@@ -0,0 +1,584 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
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 | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | 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 | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | |||
32 | //----------------------------------------------------------------------------- | ||
33 | // | ||
34 | // Abstract C O N N E C T I O N class | ||
35 | // | ||
36 | //----------------------------------------------------------------------------- | ||
37 | |||
38 | Clipperz.PM.Connection = function (args) { | ||
39 | args = args || {}; | ||
40 | |||
41 | this._user = args.user; | ||
42 | this._clipperz_pm_crypto_version = null; | ||
43 | this._connectionId = null; | ||
44 | this._oneTimePassword = null; | ||
45 | |||
46 | return this; | ||
47 | } | ||
48 | |||
49 | Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { | ||
50 | |||
51 | 'user': function() { | ||
52 | return this._user; | ||
53 | }, | ||
54 | |||
55 | 'toString': function() { | ||
56 | return "Connection [" + this.version() + "] - user: " + this.user(); | ||
57 | }, | ||
58 | |||
59 | //========================================================================= | ||
60 | |||
61 | 'version': function() { | ||
62 | throw Clipperz.Base.exception.AbstractMethod; | ||
63 | }, | ||
64 | |||
65 | 'clipperz_pm_crypto_version': function() { | ||
66 | if (this._clipperz_pm_crypto_version == null) { | ||
67 | var connectionVersions; | ||
68 | varversions; | ||
69 | varversion; | ||
70 | var i, c; | ||
71 | |||
72 | version = null; | ||
73 | connectionVersions = Clipperz.PM.Crypto.communicationProtocol.versions; | ||
74 | versions = MochiKit.Base.keys(connectionVersions); | ||
75 | c = versions.length; | ||
76 | for (i=0; i<c; i++) { | ||
77 | if (! (versions[i] == 'current')) { | ||
78 | if (this instanceof connectionVersions[versions[i]]) { | ||
79 | version = versions[i]; | ||
80 | }; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | this._clipperz_pm_crypto_version = version; | ||
85 | } | ||
86 | |||
87 | return this._clipperz_pm_crypto_version; | ||
88 | }, | ||
89 | |||
90 | //------------------------------------------------------------------------- | ||
91 | |||
92 | 'defaultErrorHandler': function(anErrorString, anException) { | ||
93 | MochiKit.Logging.logError("### Connection.defaultErrorHandler: " + anErrorString + " (" + anException + ")"); | ||
94 | }, | ||
95 | |||
96 | //------------------------------------------------------------------------- | ||
97 | |||
98 | 'login': function(someArguments, aCallback) { | ||
99 | throw Clipperz.Base.exception.AbstractMethod; | ||
100 | }, | ||
101 | |||
102 | //------------------------------------------------------------------------- | ||
103 | |||
104 | 'message': function(someArguments, aCallback) { | ||
105 | throw Clipperz.Base.exception.AbstractMethod; | ||
106 | }, | ||
107 | |||
108 | //------------------------------------------------------------------------- | ||
109 | |||
110 | 'sharedSecret': function() { | ||
111 | throw Clipperz.Base.exception.AbstractMethod; | ||
112 | }, | ||
113 | |||
114 | 'serverSideUserCredentials': function() { | ||
115 | throw Clipperz.Base.exception.AbstractMethod; | ||
116 | }, | ||
117 | |||
118 | //========================================================================= | ||
119 | |||
120 | 'connectionId': function() { | ||
121 | return this._connectionId; | ||
122 | }, | ||
123 | |||
124 | 'setConnectionId': function(aValue) { | ||
125 | this._connectionId = aValue; | ||
126 | }, | ||
127 | |||
128 | //========================================================================= | ||
129 | |||
130 | 'oneTimePassword': function() { | ||
131 | return this._oneTimePassword; | ||
132 | }, | ||
133 | |||
134 | 'setOneTimePassword': function(aValue) { | ||
135 | this._oneTimePassword = aValue; | ||
136 | }, | ||
137 | |||
138 | //========================================================================= | ||
139 | __syntaxFix__: "syntax fix" | ||
140 | |||
141 | } | ||
142 | ); | ||
143 | |||
144 | |||
145 | if (typeof(Clipperz.PM.Connection.SRP) == 'undefined') { Clipperz.PM.Connection.SRP = {}; } | ||
146 | //----------------------------------------------------------------------------- | ||
147 | // | ||
148 | // S R P [ 1 . 0 ] C O N N E C T I O N class | ||
149 | // | ||
150 | //----------------------------------------------------------------------------- | ||
151 | |||
152 | Clipperz.PM.Connection.SRP['1.0'] = function (args) { | ||
153 | args = args || {}; | ||
154 | Clipperz.PM.Connection.call(this, args); | ||
155 | |||
156 | this._C = null; | ||
157 | this._P = null; | ||
158 | this._srpConnection = null; | ||
159 | |||
160 | return this; | ||
161 | } | ||
162 | |||
163 | Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection(), { | ||
164 | |||
165 | 'version': function() { | ||
166 | return '1.0'; | ||
167 | }, | ||
168 | |||
169 | //========================================================================= | ||
170 | |||
171 | 'register': function(anInvitationCode) { | ||
172 | var deferredResult; | ||
173 | varparameters; | ||
174 | |||
175 | //MochiKit.Logging.logError(">>> Connection.register: " + this); | ||
176 | parameters = {}; | ||
177 | deferredResult = new MochiKit.Async.Deferred(); | ||
178 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 1: " + res); return res;}); | ||
179 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_verify'); | ||
180 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 2: " + res); return res;}); | ||
181 | deferredResult.addCallback(function(aConnection, anInvitationCode) { | ||
182 | var args; | ||
183 | |||
184 | args = {}; | ||
185 | args.message = 'register'; | ||
186 | args.version = aConnection.clipperz_pm_crypto_version(); | ||
187 | args.invitationCode = anInvitationCode; | ||
188 | |||
189 | return args; | ||
190 | }, this); | ||
191 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 3: " + res); return res;}); | ||
192 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'registration_sendingCredentials'); | ||
193 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 4: " + res); return res;}); | ||
194 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); | ||
195 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 5: " + res); return res;}); | ||
196 | deferredResult.addCallback(function(someParameters, anUser, anEncryptedData) { | ||
197 | var currentVersionConnection; | ||
198 | var args; | ||
199 | |||
200 | currentVersionConnection = new Clipperz.PM.Crypto.communicationProtocol.versions['current']({user:anUser}); | ||
201 | |||
202 | args = someParameters | ||
203 | args.credentials = currentVersionConnection.serverSideUserCredentials(); | ||
204 | args.user = anEncryptedData; | ||
205 | args.version = args.credentials.version; | ||
206 | args.message = "completeRegistration"; | ||
207 | |||
208 | return args; | ||
209 | }, parameters, this.user()); | ||
210 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 6: " + res); return res;}); | ||
211 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'registration')); | ||
212 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.register - 7: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
213 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | ||
214 | this.user().setLock(res['lock']); | ||
215 | |||
216 | return res; | ||
217 | }, this)); | ||
218 | deferredResult.callback(anInvitationCode); | ||
219 | //MochiKit.Logging.logError("<<< Connection.register"); | ||
220 | |||
221 | return deferredResult; | ||
222 | }, | ||
223 | |||
224 | //========================================================================= | ||
225 | |||
226 | 'login': function(isReconnecting) { | ||
227 | vardeferredResult; | ||
228 | |||
229 | //MochiKit.Logging.logDebug(">>> Connection.login: "/* + this*/); | ||
230 | //MochiKit.Logging.logDebug("--- Connection.login - isReconnecting: " + (isReconnecting == true)); | ||
231 | deferredResult = new MochiKit.Async.Deferred(); | ||
232 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.1 - Connection.login - 1: "/* + res*/); return res;}); | ||
233 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
234 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_sendingCredentials'); | ||
235 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.2 - Connection.login - 2: "/* + res*/); return res;}); | ||
236 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
237 | deferredResult.addCallback(function(aConnection) { | ||
238 | var args; | ||
239 | |||
240 | args = {}; | ||
241 | args.message = 'connect'; | ||
242 | args.version = aConnection.clipperz_pm_crypto_version(); | ||
243 | args.parameters = {}; | ||
244 | //MochiKit.Logging.logDebug("=== Connection.login - username: " + aConnection.srpConnection().C()); | ||
245 | args.parameters['C'] = aConnection.srpConnection().C(); | ||
246 | args.parameters['A'] = aConnection.srpConnection().A().asString(16); | ||
247 | |||
248 | if (isReconnecting == true) { | ||
249 | //MochiKit.Logging.logDebug("--- Connection.login - reconnecting"); | ||
250 | //# args.parameters['reconnecting'] = "yes"; | ||
251 | args.parameters['reconnecting'] = aConnection.connectionId(); | ||
252 | } | ||
253 | //MochiKit.Logging.logDebug("--- Connection.login - args: " + Clipperz.Base.serializeJSON(args)); | ||
254 | //MochiKit.Logging.logDebug("--- Connection.login - srp.a: " + aConnection.srpConnection().a().asString(16)); | ||
255 | |||
256 | return args; | ||
257 | }); | ||
258 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.3 - Connection.login - 3: "/* + res*/); return res;}); | ||
259 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
260 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); | ||
261 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.4 - Connection.login - 4: "/* + res*/); return res;}); | ||
262 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
263 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_credentialVerification'); | ||
264 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.5 - Connection.login - 5: "/* + res*/); return res;}); | ||
265 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
266 | deferredResult.addErrback(MochiKit.Base.bind(function(res) {MochiKit.Logging.logDebug("ERROR - c: " + this.srpConnection().C() + " # version: " + this.clipperz_pm_crypto_version()); return res;}, this)); | ||
267 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { | ||
268 | var args; | ||
269 | |||
270 | this.srpConnection().set_s(new Clipperz.Crypto.BigInt(someParameters['s'], 16)); | ||
271 | this.srpConnection().set_B(new Clipperz.Crypto.BigInt(someParameters['B'], 16)); | ||
272 | |||
273 | if (typeof(someParameters['oneTimePassword']) != 'undefined') { | ||
274 | this.setOneTimePassword(someParameters['oneTimePassword']); | ||
275 | } | ||
276 | |||
277 | args = {}; | ||
278 | args.message = 'credentialCheck'; | ||
279 | args.version = this.clipperz_pm_crypto_version(); | ||
280 | args.parameters = {}; | ||
281 | args.parameters['M1'] = this.srpConnection().M1(); | ||
282 | |||
283 | return args; | ||
284 | }, this)); | ||
285 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.6 - Connection.login - 6: "/* + res*/); return res;}); | ||
286 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
287 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); | ||
288 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.7 - Connection.login - 7: "/* + res*/); return res;}); | ||
289 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
290 | //# deferredResult.addCallback(MochiKit.Base.method(this, 'loginDone')); | ||
291 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { | ||
292 | var result; | ||
293 | |||
294 | //MochiKit.Logging.logDebug(">>> Connection.loginDone: " + this + " (M2: " + this.srpConnection().M2() + ")"); | ||
295 | if (someParameters['M2'] == this.srpConnection().M2()) { | ||
296 | result = new MochiKit.Async.Deferred(); | ||
297 | |||
298 | //MochiKit.Logging.logDebug("--- Connection.loginDone - someParameters: " + Clipperz.Base.serializeJSON(someParameters)); | ||
299 | this.setConnectionId(someParameters['connectionId']); | ||
300 | this.user().setLoginInfo(someParameters['loginInfo']); | ||
301 | this.user().setShouldDownloadOfflineCopy(someParameters['offlineCopyNeeded']); | ||
302 | this.user().setLock(someParameters['lock']); | ||
303 | |||
304 | if (this.oneTimePassword() != null) { | ||
305 | result.addCallback(MochiKit.Base.method(this.user().oneTimePasswordManager(), 'archiveOneTimePassword', this.oneTimePassword())); | ||
306 | } | ||
307 | result.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_loggedIn'); | ||
308 | result.addCallback(MochiKit.Async.succeed, someParameters); | ||
309 | |||
310 | result.callback(); | ||
311 | //MochiKit.Logging.logDebug("--- Connection.loginDone - 1 - result: "/* + Clipperz.Base.serializeJSON(result)*/); | ||
312 | } else { | ||
313 | //MochiKit.Logging.logDebug("--- Connection.loginDone - 2 - ERROR"); | ||
314 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
315 | result = MochiKit.Async.fail(Clipperz.PM.Connection.exception.WrongChecksum); | ||
316 | } | ||
317 | //MochiKit.Logging.logDebug("<<< Connection.loginDone - result: " + Clipperz.Base.serializeJSON(result)); | ||
318 | |||
319 | return result; | ||
320 | }, this)); | ||
321 | |||
322 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.3.8 - Connection.login - 8: "/* + res*/); return res;}); | ||
323 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | ||
324 | deferredResult.callback(this); | ||
325 | //MochiKit.Logging.logDebug("<<< Connection.login"); | ||
326 | |||
327 | return deferredResult; | ||
328 | }, | ||
329 | |||
330 | //========================================================================= | ||
331 | |||
332 | 'logout': function() { | ||
333 | var deferredResult; | ||
334 | |||
335 | //MochiKit.Logging.logDebug(">>> Connection.logout: " + this); | ||
336 | deferredResult = new MochiKit.Async.Deferred(); | ||
337 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 1: " + res); return res;}); | ||
338 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'logout'), {}); | ||
339 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 2: " + res); return res;}); | ||
340 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection')); | ||
341 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.logout - 3: " + res); return res;}); | ||
342 | deferredResult.callback(); | ||
343 | //MochiKit.Logging.logDebug("<<< Connection.logout"); | ||
344 | |||
345 | return deferredResult; | ||
346 | }, | ||
347 | |||
348 | //========================================================================= | ||
349 | |||
350 | 'message': function(aMessageName, someParameters) { | ||
351 | var args; | ||
352 | var deferredResult; | ||
353 | |||
354 | //MochiKit.Logging.logDebug(">>> Connection.message: " + this); | ||
355 | args = {} | ||
356 | args['message'] = aMessageName; | ||
357 | args['srpSharedSecret'] = this.srpConnection().K(); | ||
358 | // args['lock'] = this.user().lock(); | ||
359 | |||
360 | if (someParameters != null) { | ||
361 | args['parameters'] = someParameters; | ||
362 | } else { | ||
363 | args['parameters'] = {}; | ||
364 | } | ||
365 | //MochiKit.Logging.logDebug("--- Connection.message - args: " + Clipperz.Base.serializeJSON(args)); | ||
366 | |||
367 | // deferredResult = new MochiKit.Async.Deferred(); //### ????????????? | ||
368 | |||
369 | return this.sendMessage(args); | ||
370 | }, | ||
371 | |||
372 | //------------------------------------------------------------------------- | ||
373 | |||
374 | 'sendMessage': function(someArguments) { | ||
375 | vardeferredResult; | ||
376 | |||
377 | //MochiKit.Logging.logDebug(">>> Connection.sendMessage: " + this); | ||
378 | deferredResult = new MochiKit.Async.Deferred(); | ||
379 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 1: " + res); return res;}); | ||
380 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'message'), someArguments); | ||
381 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 2: " + res); return res;}); | ||
382 | |||
383 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | ||
384 | if (typeof(res['lock']) != 'undefined') { | ||
385 | this.user().setLock(res['lock']); | ||
386 | } | ||
387 | return res; | ||
388 | }, this)); | ||
389 | |||
390 | deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments); | ||
391 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + res); return res;}); | ||
392 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.sendMessage - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
393 | deferredResult.callback(); | ||
394 | //MochiKit.Logging.logDebug("<<< Connection.sendMessage"); | ||
395 | |||
396 | return deferredResult | ||
397 | }, | ||
398 | |||
399 | //------------------------------------------------------------------------- | ||
400 | |||
401 | 'messageExceptionHandler': function(anOriginalMessageArguments, anError) { | ||
402 | var result; | ||
403 | |||
404 | //MochiKit.Logging.logDebug(">>> Connection.messageExceptionHandler - this: " + this + ", anError: " + anError); | ||
405 | if (anError instanceof MochiKit.Async.CancelledError) { | ||
406 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 1"); | ||
407 | result = anError; | ||
408 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 2"); | ||
409 | } else { | ||
410 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 3 - anError.name: " + anError.name + ", message: " + anError.message); | ||
411 | if ((anError.message == 'Trying to communicate without an active connection')|| | ||
412 | (anError.message == 'No tollManager available for current session') | ||
413 | ) { | ||
414 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 4"); | ||
415 | result = this.reestablishConnection(anOriginalMessageArguments); | ||
416 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5"); | ||
417 | } else if (anError.message == 'Session with stale data') { | ||
418 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.1"); | ||
419 | Clipperz.NotificationCenter.notify(this, 'EXCEPTION'); | ||
420 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 5.2"); | ||
421 | } else { | ||
422 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 6"); | ||
423 | result = anError; | ||
424 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 7"); | ||
425 | } | ||
426 | //MochiKit.Logging.logDebug("--- Connection.messageExceptionHandler - 8"); | ||
427 | } | ||
428 | //MochiKit.Logging.logDebug("<<< Connection.messageExceptionHandler"); | ||
429 | |||
430 | return result;; | ||
431 | }, | ||
432 | |||
433 | //========================================================================= | ||
434 | |||
435 | 'reestablishConnection': function(anOriginalMessageArguments) { | ||
436 | var deferredResult; | ||
437 | |||
438 | //MochiKit.Logging.logDebug("+++ Connection.reestablishConnection: " + Clipperz.Base.serializeJSON(anOriginalMessageArguments)); | ||
439 | |||
440 | //MochiKit.Logging.logDebug(">>> Connection.reestablishConnection: " + this); | ||
441 | deferredResult = new MochiKit.Async.Deferred(); | ||
442 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 1: " + res); return res;}); | ||
443 | deferredResult.addCallback(MochiKit.Base.method(this, 'resetSrpConnection')); | ||
444 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 2: " + res); return res;}); | ||
445 | deferredResult.addCallback(MochiKit.Base.method(this, 'login'), true); | ||
446 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 3: " + res); return res;}); | ||
447 | deferredResult.addCallback(MochiKit.Base.bind(function(aMessage) { | ||
448 | aMessage['srpSharedSecret'] = this.srpConnection().K(); | ||
449 | return aMessage; | ||
450 | }, this), anOriginalMessageArguments); | ||
451 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 4: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
452 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage')); | ||
453 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 5: " + res); return res;}); | ||
454 | deferredResult.addErrback(Clipperz.NotificationCenter.deferredNotification, this, 'EXCEPTION', null); | ||
455 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Connection.reestablishConnection 6: " + res); return res;}); | ||
456 | deferredResult.callback(); | ||
457 | //MochiKit.Logging.logDebug("<<< Connection.reestablishConnection"); | ||
458 | |||
459 | return deferredResult; | ||
460 | }, | ||
461 | |||
462 | //========================================================================= | ||
463 | |||
464 | 'sharedSecret': function() { | ||
465 | return this.srpConnection().K(); | ||
466 | }, | ||
467 | |||
468 | //========================================================================= | ||
469 | |||
470 | 'serverSideUserCredentials': function() { | ||
471 | varresult; | ||
472 | varnewSrpConnection; | ||
473 | |||
474 | //MochiKit.Logging.logDebug(">>> Connection.serverSideUserCredentials"); | ||
475 | newSrpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() }); | ||
476 | result = newSrpConnection.serverSideCredentials(); | ||
477 | result['version'] = this.clipperz_pm_crypto_version(); | ||
478 | |||
479 | //MochiKit.Logging.logDebug("<<< Connection.serverSideUserCredentials - result: " + Clipperz.Base.serializeJSON(result)); | ||
480 | return result; | ||
481 | }, | ||
482 | |||
483 | //========================================================================= | ||
484 | |||
485 | 'C': function() { | ||
486 | if (this._C == null) { | ||
487 | this._C = this.hash()(new Clipperz.ByteArray(this.user().username())).toHexString().substring(2); | ||
488 | } | ||
489 | |||
490 | return this._C; | ||
491 | }, | ||
492 | |||
493 | //----------------------------------------------------------------------------- | ||
494 | |||
495 | 'P': function() { | ||
496 | if (this._P == null) { | ||
497 | this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2); | ||
498 | } | ||
499 | |||
500 | return this._P; | ||
501 | }, | ||
502 | |||
503 | //----------------------------------------------------------------------------- | ||
504 | |||
505 | 'hash': function() { | ||
506 | return Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].hash; | ||
507 | }, | ||
508 | |||
509 | //----------------------------------------------------------------------------- | ||
510 | |||
511 | 'srpConnection': function() { | ||
512 | if (this._srpConnection == null) { | ||
513 | this._srpConnection = new Clipperz.Crypto.SRP.Connection({ C:this.C(), P:this.P(), hash:this.hash() }); | ||
514 | } | ||
515 | |||
516 | return this._srpConnection; | ||
517 | }, | ||
518 | |||
519 | 'resetSrpConnection': function() { | ||
520 | this._C = null; | ||
521 | this._P = null; | ||
522 | this._srpConnection = null; | ||
523 | }, | ||
524 | |||
525 | //----------------------------------------------------------------------------- | ||
526 | __syntaxFix__: "syntax fix" | ||
527 | |||
528 | }); | ||
529 | |||
530 | |||
531 | |||
532 | //----------------------------------------------------------------------------- | ||
533 | // | ||
534 | // S R P [ 1 . 1 ] C O N N E C T I O N class | ||
535 | // | ||
536 | //----------------------------------------------------------------------------- | ||
537 | |||
538 | Clipperz.PM.Connection.SRP['1.1'] = function (args) { | ||
539 | args = args || {}; | ||
540 | Clipperz.PM.Connection.SRP['1.0'].call(this, args); | ||
541 | |||
542 | return this; | ||
543 | } | ||
544 | |||
545 | Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection.SRP['1.0'](), { | ||
546 | |||
547 | 'version': function() { | ||
548 | return '1.1'; | ||
549 | }, | ||
550 | |||
551 | //----------------------------------------------------------------------------- | ||
552 | |||
553 | 'C': function() { | ||
554 | if (this._C == null) { | ||
555 | this._C = this.hash()(new Clipperz.ByteArray(this.user().username() + this.user().passphrase())).toHexString().substring(2); | ||
556 | } | ||
557 | |||
558 | return this._C; | ||
559 | }, | ||
560 | |||
561 | //----------------------------------------------------------------------------- | ||
562 | |||
563 | 'P': function() { | ||
564 | if (this._P == null) { | ||
565 | this._P = this.hash()(new Clipperz.ByteArray(this.user().passphrase() + this.user().username())).toHexString().substring(2); | ||
566 | } | ||
567 | |||
568 | return this._P; | ||
569 | }, | ||
570 | |||
571 | //----------------------------------------------------------------------------- | ||
572 | |||
573 | 'hash': function() { | ||
574 | return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash; | ||
575 | }, | ||
576 | |||
577 | //----------------------------------------------------------------------------- | ||
578 | __syntaxFix__: "syntax fix" | ||
579 | |||
580 | }); | ||
581 | |||
582 | Clipperz.PM.Connection.exception = { | ||
583 | WrongChecksum: new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.InvalidValue") | ||
584 | }; | ||