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,46 +1,44 @@ | |||
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; |
@@ -65,49 +63,50 @@ Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { | |||
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 | ||
@@ -252,49 +251,48 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz. | |||
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) { |
@@ -432,100 +430,99 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz. | |||
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 | ||