author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/PM/Connection.js | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Connection.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Connection.js | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Connection.js b/frontend/gamma/js/Clipperz/PM/Connection.js index a05a310..6a8f15e 100644 --- a/frontend/gamma/js/Clipperz/PM/Connection.js +++ b/frontend/gamma/js/Clipperz/PM/Connection.js | |||
@@ -1,137 +1,136 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * 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 |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | 26 | ||
29 | //----------------------------------------------------------------------------- | 27 | //----------------------------------------------------------------------------- |
30 | // | 28 | // |
31 | // Abstract C O N N E C T I O N class | 29 | // Abstract C O N N E C T I O N class |
32 | // | 30 | // |
33 | //----------------------------------------------------------------------------- | 31 | //----------------------------------------------------------------------------- |
34 | 32 | ||
35 | Clipperz.PM.Connection = function (args) { | 33 | Clipperz.PM.Connection = function (args) { |
36 | args = args || {}; | 34 | args = args || {}; |
37 | 35 | ||
38 | this._proxy = args.proxy || Clipperz.PM.Proxy.defaultProxy; | 36 | this._proxy = args.proxy || Clipperz.PM.Proxy.defaultProxy; |
39 | this._getCredentialsFunction = args.getCredentialsFunction; | 37 | this._getCredentialsFunction = args.getCredentialsFunction; |
40 | 38 | ||
41 | this._clipperz_pm_crypto_version = null; | 39 | this._clipperz_pm_crypto_version = null; |
42 | this._connectionId = null; | 40 | this._connectionId = null; |
43 | this._sharedSecret = null; | 41 | this._sharedSecret = null; |
44 | this._serverLockValue = null; | 42 | this._serverLockValue = null; |
45 | 43 | ||
46 | return this; | 44 | return this; |
47 | } | 45 | } |
48 | 46 | ||
49 | Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { | 47 | Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { |
50 | 48 | ||
51 | 'toString': function() { | 49 | 'toString': function() { |
52 | return "Connection [" + this.version() + "]"; | 50 | return "Connection [" + this.version() + "]"; |
53 | }, | 51 | }, |
54 | 52 | ||
55 | //========================================================================= | 53 | //========================================================================= |
56 | 54 | ||
57 | 'version': function() { | 55 | 'version': function() { |
58 | throw Clipperz.Base.exception.AbstractMethod; | 56 | throw Clipperz.Base.exception.AbstractMethod; |
59 | }, | 57 | }, |
60 | 58 | ||
61 | 'clipperz_pm_crypto_version': function() { | 59 | 'clipperz_pm_crypto_version': function() { |
62 | if (this._clipperz_pm_crypto_version == null) { | 60 | if (this._clipperz_pm_crypto_version == null) { |
63 | var connectionVersions; | 61 | var connectionVersions; |
64 | varversions; | 62 | varversions; |
65 | varversion; | 63 | varversion; |
66 | var i, c; | 64 | var i, c; |
67 | 65 | ||
68 | version = null; | 66 | version = null; |
69 | connectionVersions = Clipperz.PM.Connection.communicationProtocol.versions; | 67 | connectionVersions = Clipperz.PM.Connection.communicationProtocol.versions; |
70 | versions = MochiKit.Base.keys(connectionVersions); | 68 | versions = MochiKit.Base.keys(connectionVersions); |
71 | c = versions.length; | 69 | c = versions.length; |
72 | for (i=0; i<c; i++) { | 70 | for (i=0; i<c; i++) { |
73 | if (! (versions[i] == 'current')) { | 71 | if (! (versions[i] == 'current')) { |
74 | if (this instanceof connectionVersions[versions[i]]) { | 72 | if (this instanceof connectionVersions[versions[i]]) { |
75 | version = versions[i]; | 73 | version = versions[i]; |
76 | }; | 74 | }; |
77 | } | 75 | } |
78 | } | 76 | } |
79 | 77 | ||
80 | this._clipperz_pm_crypto_version = version; | 78 | this._clipperz_pm_crypto_version = version; |
81 | } | 79 | } |
82 | 80 | ||
83 | return this._clipperz_pm_crypto_version; | 81 | return this._clipperz_pm_crypto_version; |
84 | }, | 82 | }, |
85 | 83 | ||
86 | //------------------------------------------------------------------------- | 84 | //------------------------------------------------------------------------- |
87 | 85 | ||
88 | 'defaultErrorHandler': function(anErrorString, anException) { | 86 | 'defaultErrorHandler': function(anErrorString, anException) { |
89 | MochiKit.Logging.logError("### Connection.defaultErrorHandler: " + anErrorString + " (" + anException + ")"); | 87 | // Clipperz.logError("### Connection.defaultErrorHandler: " + anErrorString, anException); |
88 | Clipperz.logError("### Connection.defaultErrorHandler: " + anErrorString + " (" + anException + ")"); | ||
90 | }, | 89 | }, |
91 | 90 | ||
92 | //------------------------------------------------------------------------- | 91 | //------------------------------------------------------------------------- |
93 | 92 | ||
94 | 'getCredentialsFunction': function () { | 93 | 'getCredentialsFunction': function () { |
95 | return this._getCredentialsFunction; | 94 | return this._getCredentialsFunction; |
96 | }, | 95 | }, |
97 | 96 | ||
98 | 'normalizedCredentials': function(someValues) { | 97 | 'normalizedCredentials': function(someValues) { |
99 | throw Clipperz.Base.exception.AbstractMethod; | 98 | throw Clipperz.Base.exception.AbstractMethod; |
100 | }, | 99 | }, |
101 | 100 | ||
102 | //========================================================================= | 101 | //========================================================================= |
103 | 102 | ||
104 | 'proxy': function () { | 103 | 'proxy': function () { |
105 | return this._proxy; | 104 | return this._proxy; |
106 | }, | 105 | }, |
107 | 106 | ||
108 | //========================================================================= | 107 | //========================================================================= |
109 | 108 | ||
110 | 'register': function () { | 109 | 'register': function () { |
111 | throw Clipperz.Base.exception.AbstractMethod; | 110 | throw Clipperz.Base.exception.AbstractMethod; |
112 | }, | 111 | }, |
113 | 112 | ||
114 | 'login': function() { | 113 | 'login': function() { |
115 | throw Clipperz.Base.exception.AbstractMethod; | 114 | throw Clipperz.Base.exception.AbstractMethod; |
116 | }, | 115 | }, |
117 | 116 | ||
118 | //------------------------------------------------------------------------- | 117 | //------------------------------------------------------------------------- |
119 | 118 | ||
120 | 'message': function(someArguments, aCallback) { | 119 | 'message': function(someArguments, aCallback) { |
121 | throw Clipperz.Base.exception.AbstractMethod; | 120 | throw Clipperz.Base.exception.AbstractMethod; |
122 | }, | 121 | }, |
123 | 122 | ||
124 | //------------------------------------------------------------------------- | 123 | //------------------------------------------------------------------------- |
125 | 124 | ||
126 | 'serverSideUserCredentials': function() { | 125 | 'serverSideUserCredentials': function() { |
127 | throw Clipperz.Base.exception.AbstractMethod; | 126 | throw Clipperz.Base.exception.AbstractMethod; |
128 | }, | 127 | }, |
129 | 128 | ||
130 | //========================================================================= | 129 | //========================================================================= |
131 | 130 | ||
132 | 'sharedSecret': function () { | 131 | 'sharedSecret': function () { |
133 | return this._sharedSecret; | 132 | return this._sharedSecret; |
134 | }, | 133 | }, |
135 | 134 | ||
136 | 'setSharedSecret': function (aValue) { | 135 | 'setSharedSecret': function (aValue) { |
137 | this._sharedSecret = aValue; | 136 | this._sharedSecret = aValue; |
@@ -228,97 +227,96 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz. | |||
228 | ], | 227 | ], |
229 | 'user': MochiKit.Base.partial(MochiKit.Async.succeed, someUserData), | 228 | 'user': MochiKit.Base.partial(MochiKit.Async.succeed, someUserData), |
230 | 'version':MochiKit.Base.partial(MochiKit.Async.succeed, Clipperz.PM.Connection.communicationProtocol.currentVersion), | 229 | 'version':MochiKit.Base.partial(MochiKit.Async.succeed, Clipperz.PM.Connection.communicationProtocol.currentVersion), |
231 | 'message':MochiKit.Base.partial(MochiKit.Async.succeed, 'completeRegistration') | 230 | 'message':MochiKit.Base.partial(MochiKit.Async.succeed, 'completeRegistration') |
232 | }); | 231 | }); |
233 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); | 232 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); |
234 | deferredResult.addMethod(this.proxy(), 'registration'); | 233 | deferredResult.addMethod(this.proxy(), 'registration'); |
235 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); | 234 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); |
236 | 235 | ||
237 | deferredResult.callback(); | 236 | deferredResult.callback(); |
238 | 237 | ||
239 | return deferredResult; | 238 | return deferredResult; |
240 | }, | 239 | }, |
241 | 240 | ||
242 | //------------------------------------------------------------------------- | 241 | //------------------------------------------------------------------------- |
243 | 242 | ||
244 | 'updateCredentials': function (aUsername, aPassphrase, someUserData) { | 243 | 'updateCredentials': function (aUsername, aPassphrase, someUserData) { |
245 | vardeferredResult; | 244 | vardeferredResult; |
246 | 245 | ||
247 | deferredResult = new Clipperz.Async.Deferred("Connection.updateCredentials", {trace:false}); | 246 | deferredResult = new Clipperz.Async.Deferred("Connection.updateCredentials", {trace:false}); |
248 | deferredResult.collectResults({ | 247 | deferredResult.collectResults({ |
249 | 'credentials': [ | 248 | 'credentials': [ |
250 | MochiKit.Base.method(this, 'normalizedCredentials', {username:aUsername, password:aPassphrase}), | 249 | MochiKit.Base.method(this, 'normalizedCredentials', {username:aUsername, password:aPassphrase}), |
251 | MochiKit.Base.bind(function(someCredentials) { | 250 | MochiKit.Base.bind(function(someCredentials) { |
252 | var srpConnection; | 251 | var srpConnection; |
253 | var result; | 252 | var result; |
254 | 253 | ||
255 | srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() }); | 254 | srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() }); |
256 | result = srpConnection.serverSideCredentials(); | 255 | result = srpConnection.serverSideCredentials(); |
257 | result['version'] = Clipperz.PM.Connection.communicationProtocol.currentVersion; | 256 | result['version'] = Clipperz.PM.Connection.communicationProtocol.currentVersion; |
258 | 257 | ||
259 | return result; | 258 | return result; |
260 | }, this) | 259 | }, this) |
261 | ], | 260 | ], |
262 | 'user': MochiKit.Base.partial(MochiKit.Async.succeed, someUserData) | 261 | 'user': MochiKit.Base.partial(MochiKit.Async.succeed, someUserData) |
263 | }); | 262 | }); |
264 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); | 263 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); |
265 | deferredResult.addMethod(this, 'message', 'upgradeUserCredentials'); | 264 | deferredResult.addMethod(this, 'message', 'upgradeUserCredentials'); |
266 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); | 265 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); |
267 | deferredResult.callback(); | 266 | deferredResult.callback(); |
268 | 267 | ||
269 | return deferredResult; | 268 | return deferredResult; |
270 | 269 | ||
271 | }, | 270 | }, |
272 | 271 | ||
273 | //========================================================================= | 272 | //========================================================================= |
274 | 273 | ||
275 | 'redeemOneTimePassword': function (someParameters) { | 274 | 'redeemOneTimePassword': function (someParameters) { |
276 | //console.log("Connections.redeemOneTimePassword", someParameters['username'], someParameters['password']); | ||
277 | /* | 275 | /* |
278 | //========================================================================= | 276 | //========================================================================= |
279 | //LOGIN WITH PASSPHRASE, extracted from the TRUNK version (LoginPanel.js) | 277 | //LOGIN WITH PASSPHRASE, extracted from the TRUNK version (LoginPanel.js) |
280 | deferredResult.addCallback(function(anUsername, aOneTimePassword) { | 278 | deferredResult.addCallback(function(anUsername, aOneTimePassword) { |
281 | var args; | 279 | var args; |
282 | 280 | ||
283 | args = { | 281 | args = { |
284 | 'message': 'oneTimePassword', | 282 | 'message': 'oneTimePassword', |
285 | 'version': Clipperz.PM.Crypto.communicationProtocol.currentVersion, | 283 | 'version': Clipperz.PM.Crypto.communicationProtocol.currentVersion, |
286 | 'parameters': { | 284 | 'parameters': { |
287 | 'oneTimePasswordKey': Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(anUsername, aOneTimePassword), | 285 | 'oneTimePasswordKey': Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(anUsername, aOneTimePassword), |
288 | 'oneTimePasswordKeyChecksum': Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(anUsername, aOneTimePassword) | 286 | 'oneTimePasswordKeyChecksum': Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(anUsername, aOneTimePassword) |
289 | } | 287 | } |
290 | } | 288 | } |
291 | 289 | ||
292 | return args; | 290 | return args; |
293 | }, anUsername, oneTimePassword); | 291 | }, anUsername, oneTimePassword); |
294 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'OTP_login_loadingOTP'); | 292 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'OTP_login_loadingOTP'); |
295 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); | 293 | deferredResult.addCallback(MochiKit.Base.method(Clipperz.PM.Proxy.defaultProxy, 'handshake')); |
296 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'OTP_login_extractingPassphrase'); | 294 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'OTP_login_extractingPassphrase'); |
297 | deferredResult.addCallback(function(aResult) { | 295 | deferredResult.addCallback(function(aResult) { |
298 | return Clipperz.PM.Crypto.deferredDecrypt(oneTimePassword, aResult['data'], aResult['version']); | 296 | return Clipperz.PM.Crypto.deferredDecrypt(oneTimePassword, aResult['data'], aResult['version']); |
299 | }); | 297 | }); |
300 | deferredResult.addCallback(function(aResult) { | 298 | deferredResult.addCallback(function(aResult) { |
301 | return (new Clipperz.ByteArray().appendBase64String(aResult['passphrase'])).asString(); | 299 | return (new Clipperz.ByteArray().appendBase64String(aResult['passphrase'])).asString(); |
302 | }); | 300 | }); |
303 | deferredResult.addMethod(this, 'doLoginWithUsernameAndPassphrase', anUsername), | 301 | deferredResult.addMethod(this, 'doLoginWithUsernameAndPassphrase', anUsername), |
304 | */ | 302 | */ |
305 | var args; | 303 | var args; |
306 | var normalizedOTP; | 304 | var normalizedOTP; |
307 | 305 | ||
308 | normalizedOTP = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(someParameters['password']); | 306 | normalizedOTP = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(someParameters['password']); |
309 | 307 | ||
310 | args = { | 308 | args = { |
311 | 'message': 'oneTimePassword', | 309 | 'message': 'oneTimePassword', |
312 | 'version': Clipperz.PM.Connection.communicationProtocol.currentVersion, | 310 | 'version': Clipperz.PM.Connection.communicationProtocol.currentVersion, |
313 | 'parameters': { | 311 | 'parameters': { |
314 | 'oneTimePasswordKey': Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(someParameters['username'], normalizedOTP), | 312 | 'oneTimePasswordKey': Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(someParameters['username'], normalizedOTP), |
315 | 'oneTimePasswordKeyChecksum':Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(someParameters['username'], normalizedOTP) | 313 | 'oneTimePasswordKeyChecksum':Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(someParameters['username'], normalizedOTP) |
316 | } | 314 | } |
317 | } | 315 | } |
318 | 316 | ||
319 | return Clipperz.Async.callbacks("Connction.redeemOTP", [ | 317 | return Clipperz.Async.callbacks("Connction.redeemOTP", [ |
320 | MochiKit.Base.method(this.proxy(), 'handshake', args), | 318 | MochiKit.Base.method(this.proxy(), 'handshake', args), |
321 | function(aResult) { | 319 | function(aResult) { |
322 | return Clipperz.PM.Crypto.deferredDecrypt({ | 320 | return Clipperz.PM.Crypto.deferredDecrypt({ |
323 | value:aResult['data'], | 321 | value:aResult['data'], |
324 | key:normalizedOTP, | 322 | key:normalizedOTP, |
@@ -408,148 +406,147 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz. | |||
408 | // TODO: ????? | 406 | // TODO: ????? |
409 | // if (this.oneTimePassword() != null) { | 407 | // if (this.oneTimePassword() != null) { |
410 | /// ?? result = this.user().oneTimePasswordManager().archiveOneTimePassword(this.oneTimePassword())); | 408 | /// ?? result = this.user().oneTimePasswordManager().archiveOneTimePassword(this.oneTimePassword())); |
411 | // } | 409 | // } |
412 | 410 | ||
413 | if ((isReconnecting == true) && (this.serverLockValue() != someParameters['lock'])) { | 411 | if ((isReconnecting == true) && (this.serverLockValue() != someParameters['lock'])) { |
414 | throw Clipperz.PM.Connection.exception.StaleData; | 412 | throw Clipperz.PM.Connection.exception.StaleData; |
415 | } else { | 413 | } else { |
416 | this.setServerLockValue(someParameters['lock']); | 414 | this.setServerLockValue(someParameters['lock']); |
417 | } | 415 | } |
418 | 416 | ||
419 | return someParameters; | 417 | return someParameters; |
420 | }, this)); | 418 | }, this)); |
421 | // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_loggedIn'); | 419 | // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_loggedIn'); |
422 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); | 420 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); |
423 | deferredResult.addCallback(MochiKit.Async.succeed, {result:"done"}); | 421 | deferredResult.addCallback(MochiKit.Async.succeed, {result:"done"}); |
424 | 422 | ||
425 | deferredResult.callback(); | 423 | deferredResult.callback(); |
426 | 424 | ||
427 | return deferredResult; | 425 | return deferredResult; |
428 | }, | 426 | }, |
429 | 427 | ||
430 | //========================================================================= | 428 | //========================================================================= |
431 | 429 | ||
432 | 'logout': function() { | 430 | 'logout': function() { |
433 | return Clipperz.Async.callbacks("Connection.logout", [ | 431 | return Clipperz.Async.callbacks("Connection.logout", [ |
434 | MochiKit.Base.method(this, 'setSharedSecret'), | 432 | MochiKit.Base.method(this, 'setSharedSecret'), |
435 | MochiKit.Base.method(this.proxy(), 'logout', {}) | 433 | MochiKit.Base.method(this.proxy(), 'logout', {}) |
436 | ], {trace:false}); | 434 | ], {trace:false}); |
437 | }, | 435 | }, |
438 | 436 | ||
439 | //========================================================================= | 437 | //========================================================================= |
440 | 438 | ||
441 | 'ping': function () { | 439 | 'ping': function () { |
442 | //TODO: ping the server in order to have a valid session | 440 | //TODO: ping the server in order to have a valid session |
443 | }, | 441 | }, |
444 | 442 | ||
445 | //========================================================================= | 443 | //========================================================================= |
446 | 444 | ||
447 | 'message': function(aMessageName, someParameters) { | 445 | 'message': function(aMessageName, someParameters) { |
448 | var args; | 446 | var args; |
449 | var parameters; | 447 | var parameters; |
450 | 448 | ||
451 | parameters = someParameters || {}; | 449 | parameters = someParameters || {}; |
452 | if (typeof(parameters['user']) != 'undefined') { | 450 | if (typeof(parameters['user']) != 'undefined') { |
453 | parameters['user']['lock'] = this.serverLockValue(); | 451 | parameters['user']['lock'] = this.serverLockValue(); |
454 | } | 452 | } |
455 | 453 | ||
456 | //console.log(">>> Connection.message", aMessageName, someParameters); | ||
457 | args = { | 454 | args = { |
458 | message: aMessageName, | 455 | message: aMessageName, |
459 | srpSharedSecret: this.sharedSecret(), | 456 | srpSharedSecret: this.sharedSecret(), |
460 | // parameters: (someParameters || {}) | 457 | // parameters: (someParameters || {}) |
461 | parameters: parameters | 458 | parameters: parameters |
462 | } | 459 | } |
463 | 460 | ||
464 | return this.sendMessage(args); | 461 | return this.sendMessage(args); |
465 | }, | 462 | }, |
466 | 463 | ||
467 | //------------------------------------------------------------------------- | 464 | //------------------------------------------------------------------------- |
468 | 465 | ||
469 | 'sendMessage': function(someArguments) { | 466 | 'sendMessage': function(someArguments) { |
470 | vardeferredResult; | 467 | vardeferredResult; |
471 | 468 | ||
472 | deferredResult = new Clipperz.Async.Deferred("Connection.sendMessage", {trace:false}); | 469 | deferredResult = new Clipperz.Async.Deferred("Connection.sendMessage", {trace:false}); |
473 | deferredResult.addMethod(this.proxy(), 'message', someArguments); | 470 | deferredResult.addMethod(this.proxy(), 'message', someArguments); |
474 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | 471 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { |
475 | if (typeof(res['lock']) != 'undefined') { | 472 | if (typeof(res['lock']) != 'undefined') { |
476 | this.setServerLockValue(res['lock']); | 473 | this.setServerLockValue(res['lock']); |
477 | } | 474 | } |
478 | return res; | 475 | return res; |
479 | }, this)); | 476 | }, this)); |
480 | 477 | ||
481 | deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments); | 478 | deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments); |
482 | deferredResult.callback(); | 479 | deferredResult.callback(); |
483 | 480 | ||
484 | return deferredResult | 481 | return deferredResult |
485 | }, | 482 | }, |
486 | 483 | ||
487 | //------------------------------------------------------------------------- | 484 | //------------------------------------------------------------------------- |
488 | 485 | ||
489 | 'messageExceptionHandler': function(anOriginalMessageArguments, anError) { | 486 | 'messageExceptionHandler': function(anOriginalMessageArguments, anError) { |
490 | var result; | 487 | var result; |
491 | 488 | ||
492 | console.log(">>> Connection.messageExceptionHandler", anError, anError.message); | 489 | Clipperz.log(">>> Connection.messageExceptionHandler: " + anError.message, anError); |
493 | if (anError instanceof MochiKit.Async.CancelledError) { | 490 | if (anError instanceof MochiKit.Async.CancelledError) { |
494 | result = anError; | 491 | result = anError; |
495 | } else { | 492 | } else { |
496 | if ((anError.message == 'Trying to communicate without an active connection')|| | 493 | if ((anError.message == 'Trying to communicate without an active connection')|| |
497 | (anError.message == 'No tollManager available for current session') | 494 | (anError.message == 'No tollManager available for current session') |
498 | ) { | 495 | ) { |
499 | result = this.reestablishConnection(anOriginalMessageArguments); | 496 | result = this.reestablishConnection(anOriginalMessageArguments); |
500 | } else if (anError.message == 'Session with stale data') { | 497 | } else if (anError.message == 'Session with stale data') { |
501 | MochiKit.Signal.signal(this, 'EXCEPTION'); | 498 | MochiKit.Signal.signal(this, 'EXCEPTION'); |
502 | } else { | 499 | } else { |
503 | result = anError; | 500 | result = anError; |
504 | } | 501 | } |
505 | } | 502 | } |
506 | console.log("<<< Connection.messageExceptionHandler", anError) | 503 | Clipperz.log("<<< Connection.messageExceptionHandler") |
507 | 504 | ||
508 | return result;; | 505 | return result;; |
509 | }, | 506 | }, |
510 | 507 | ||
511 | //========================================================================= | 508 | //========================================================================= |
512 | 509 | ||
513 | 'reestablishConnection': function(anOriginalMessageArguments) { | 510 | 'reestablishConnection': function(anOriginalMessageArguments) { |
514 | var deferredResult; | 511 | var deferredResult; |
515 | 512 | ||
516 | deferredResult = new Clipperz.Async.Deferred("Connection.reestablishConnection"); | 513 | deferredResult = new Clipperz.Async.Deferred("Connection.reestablishConnection"); |
517 | deferredResult.addMethod(this, 'reset'); | 514 | deferredResult.addMethod(this, 'reset'); |
518 | deferredResult.addMethod(this, 'login', true); | 515 | deferredResult.addMethod(this, 'login', true); |
519 | deferredResult.addCallback(MochiKit.Base.bind(function(aMessage) { | 516 | deferredResult.addCallback(MochiKit.Base.bind(function(aMessage) { |
520 | aMessage['srpSharedSecret'] = this.sharedSecret(); | 517 | aMessage['srpSharedSecret'] = this.sharedSecret(); |
521 | return aMessage; | 518 | return aMessage; |
522 | }, this), anOriginalMessageArguments); | 519 | }, this), anOriginalMessageArguments); |
523 | deferredResult.addMethod(this, 'sendMessage'); | 520 | deferredResult.addMethod(this, 'sendMessage'); |
524 | deferredResult.addErrback(MochiKit.Signal.signal, this, 'EXCEPTION', null); | 521 | deferredResult.addErrback(MochiKit.Signal.signal, this, 'EXCEPTION', null); |
525 | deferredResult.callback(); | 522 | deferredResult.callback(); |
526 | 523 | ||
527 | return deferredResult; | 524 | return deferredResult; |
528 | }, | 525 | }, |
529 | 526 | ||
530 | //========================================================================= | 527 | //========================================================================= |
531 | 528 | ||
532 | 'serverSideUserCredentials': function(aUsername, aPassword) { | 529 | 'serverSideUserCredentials': function(aUsername, aPassword) { |
533 | varresult; | 530 | varresult; |
534 | varnewSrpConnection; | 531 | varnewSrpConnection; |
535 | var normalizedAttributes; | 532 | var normalizedAttributes; |
536 | 533 | ||
537 | normalizedAttributes = this.normalizedCredentials({username:aUsername, password:aPassword}); | 534 | normalizedAttributes = this.normalizedCredentials({username:aUsername, password:aPassword}); |
538 | newSrpConnection = new Clipperz.Crypto.SRP.Connection({ C:normalizedAttributes['username'], P:normalizedAttributes['password'], hash:this.hash() }); | 535 | newSrpConnection = new Clipperz.Crypto.SRP.Connection({ C:normalizedAttributes['username'], P:normalizedAttributes['password'], hash:this.hash() }); |
539 | result = newSrpConnection.serverSideCredentials(); | 536 | result = newSrpConnection.serverSideCredentials(); |
540 | result['version'] = this.clipperz_pm_crypto_version(); | 537 | result['version'] = this.clipperz_pm_crypto_version(); |
541 | 538 | ||
542 | return result; | 539 | return result; |
543 | }, | 540 | }, |
544 | 541 | ||
545 | //========================================================================= | 542 | //========================================================================= |
546 | 543 | ||
547 | 'normalizedCredentials': function(someValues) { | 544 | 'normalizedCredentials': function(someValues) { |
548 | var result; | 545 | var result; |
549 | 546 | ||
550 | result = {} | 547 | result = {} |
551 | result['username'] = this.hash()(new Clipperz.ByteArray(someValues['username'])).toHexString().substring(2); | 548 | result['username'] = this.hash()(new Clipperz.ByteArray(someValues['username'])).toHexString().substring(2); |
552 | result['password'] = this.hash()(new Clipperz.ByteArray(someValues['password'] + someValues['username'])).toHexString().substring(2); | 549 | result['password'] = this.hash()(new Clipperz.ByteArray(someValues['password'] + someValues['username'])).toHexString().substring(2); |
553 | 550 | ||
554 | return result; | 551 | return result; |
555 | }, | 552 | }, |