author | Clipperz <info@clipperz.com> | 2013-01-08 15:21:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-08 15:21:04 (UTC) |
commit | 816fc35420a434b1d54ae5833d617608f7456048 (patch) (unidiff) | |
tree | 95b8caf354083593d7775e4dda6f4c556b44a2d9 /frontend/gamma/js/Clipperz/PM/Connection.js | |
parent | 267603e3aa3cf0029411e67ae14018b52344c296 (diff) | |
download | clipperz-816fc35420a434b1d54ae5833d617608f7456048.zip clipperz-816fc35420a434b1d54ae5833d617608f7456048.tar.gz clipperz-816fc35420a434b1d54ae5833d617608f7456048.tar.bz2 |
Updated version of /gamma
Tons of changes, included a new draft of the mobile version (still VERY rough)
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 | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Connection.js b/frontend/gamma/js/Clipperz/PM/Connection.js index b4e8aaa..a05a310 100644 --- a/frontend/gamma/js/Clipperz/PM/Connection.js +++ b/frontend/gamma/js/Clipperz/PM/Connection.js | |||
@@ -36,16 +36,17 @@ Clipperz.PM.Connection = function (args) { | |||
36 | args = args || {}; | 36 | args = args || {}; |
37 | 37 | ||
38 | this._proxy = args.proxy || Clipperz.PM.Proxy.defaultProxy; | 38 | this._proxy = args.proxy || Clipperz.PM.Proxy.defaultProxy; |
39 | this._getCredentialsFunction = args.getCredentialsFunction; | 39 | this._getCredentialsFunction = args.getCredentialsFunction; |
40 | 40 | ||
41 | this._clipperz_pm_crypto_version = null; | 41 | this._clipperz_pm_crypto_version = null; |
42 | this._connectionId = null; | 42 | this._connectionId = null; |
43 | this._sharedSecret = null; | 43 | this._sharedSecret = null; |
44 | this._serverLockValue = null; | ||
44 | 45 | ||
45 | return this; | 46 | return this; |
46 | } | 47 | } |
47 | 48 | ||
48 | Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { | 49 | Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { |
49 | 50 | ||
50 | 'toString': function() { | 51 | 'toString': function() { |
51 | return "Connection [" + this.version() + "]"; | 52 | return "Connection [" + this.version() + "]"; |
@@ -141,16 +142,26 @@ MochiKit.Logging.logError("### Connection.defaultErrorHandler: " + anErrorString | |||
141 | 'connectionId': function() { | 142 | 'connectionId': function() { |
142 | return this._connectionId; | 143 | return this._connectionId; |
143 | }, | 144 | }, |
144 | 145 | ||
145 | 'setConnectionId': function(aValue) { | 146 | 'setConnectionId': function(aValue) { |
146 | this._connectionId = aValue; | 147 | this._connectionId = aValue; |
147 | }, | 148 | }, |
148 | 149 | ||
150 | //------------------------------------------------------------------------- | ||
151 | |||
152 | 'serverLockValue': function () { | ||
153 | return this._serverLockValue; | ||
154 | }, | ||
155 | |||
156 | 'setServerLockValue': function (aValue) { | ||
157 | this._serverLockValue = aValue; | ||
158 | }, | ||
159 | |||
149 | //========================================================================= | 160 | //========================================================================= |
150 | /* | 161 | /* |
151 | //TODO: ????? | 162 | //TODO: ????? |
152 | 'oneTimePassword': function() { | 163 | 'oneTimePassword': function() { |
153 | return this._oneTimePassword; | 164 | return this._oneTimePassword; |
154 | }, | 165 | }, |
155 | 166 | ||
156 | 'setOneTimePassword': function(aValue) { | 167 | 'setOneTimePassword': function(aValue) { |
@@ -315,23 +326,22 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz. | |||
315 | }); | 326 | }); |
316 | }, | 327 | }, |
317 | function(aResult) { | 328 | function(aResult) { |
318 | return (new Clipperz.ByteArray().appendBase64String(aResult['passphrase'])).asString(); | 329 | return (new Clipperz.ByteArray().appendBase64String(aResult['passphrase'])).asString(); |
319 | } | 330 | } |
320 | ], {trace:false}) | 331 | ], {trace:false}) |
321 | }, | 332 | }, |
322 | 333 | ||
323 | 'login': function(/*anUsername, aPassphrase*/) { | 334 | 'login': function(isReconnecting) { |
324 | vardeferredResult; | 335 | vardeferredResult; |
325 | var cryptoVersion; | 336 | var cryptoVersion; |
326 | var srpConnection; | 337 | var srpConnection; |
327 | 338 | ||
328 | cryptoVersion = this.clipperz_pm_crypto_version(); | 339 | cryptoVersion = this.clipperz_pm_crypto_version(); |
329 | |||
330 | deferredResult = new Clipperz.Async.Deferred("Connection.login", {trace:false}); | 340 | deferredResult = new Clipperz.Async.Deferred("Connection.login", {trace:false}); |
331 | deferredResult.addCallback(this.getCredentialsFunction()); | 341 | deferredResult.addCallback(this.getCredentialsFunction()); |
332 | deferredResult.addMethod(this, 'normalizedCredentials'); | 342 | deferredResult.addMethod(this, 'normalizedCredentials'); |
333 | // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_sendingCredentials'); | 343 | // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_sendingCredentials'); |
334 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); | 344 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); |
335 | deferredResult.addCallback(MochiKit.Base.bind(function(someCredentials) { | 345 | deferredResult.addCallback(MochiKit.Base.bind(function(someCredentials) { |
336 | srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() }); | 346 | srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() }); |
337 | }, this)); | 347 | }, this)); |
@@ -394,16 +404,23 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz. | |||
394 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { | 404 | deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { |
395 | this.setConnectionId(someParameters['connectionId']); | 405 | this.setConnectionId(someParameters['connectionId']); |
396 | this.setSharedSecret(srpConnection.K()); | 406 | this.setSharedSecret(srpConnection.K()); |
397 | 407 | ||
398 | // TODO: ????? | 408 | // TODO: ????? |
399 | // if (this.oneTimePassword() != null) { | 409 | // if (this.oneTimePassword() != null) { |
400 | /// ?? result = this.user().oneTimePasswordManager().archiveOneTimePassword(this.oneTimePassword())); | 410 | /// ?? result = this.user().oneTimePasswordManager().archiveOneTimePassword(this.oneTimePassword())); |
401 | // } | 411 | // } |
412 | |||
413 | if ((isReconnecting == true) && (this.serverLockValue() != someParameters['lock'])) { | ||
414 | throw Clipperz.PM.Connection.exception.StaleData; | ||
415 | } else { | ||
416 | this.setServerLockValue(someParameters['lock']); | ||
417 | } | ||
418 | |||
402 | return someParameters; | 419 | return someParameters; |
403 | }, this)); | 420 | }, this)); |
404 | // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_loggedIn'); | 421 | // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_loggedIn'); |
405 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); | 422 | deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); |
406 | deferredResult.addCallback(MochiKit.Async.succeed, {result:"done"}); | 423 | deferredResult.addCallback(MochiKit.Async.succeed, {result:"done"}); |
407 | 424 | ||
408 | deferredResult.callback(); | 425 | deferredResult.callback(); |
409 | 426 | ||
@@ -424,38 +441,44 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz. | |||
424 | 'ping': function () { | 441 | 'ping': function () { |
425 | //TODO: ping the server in order to have a valid session | 442 | //TODO: ping the server in order to have a valid session |
426 | }, | 443 | }, |
427 | 444 | ||
428 | //========================================================================= | 445 | //========================================================================= |
429 | 446 | ||
430 | 'message': function(aMessageName, someParameters) { | 447 | 'message': function(aMessageName, someParameters) { |
431 | var args; | 448 | var args; |
449 | var parameters; | ||
450 | |||
451 | parameters = someParameters || {}; | ||
452 | if (typeof(parameters['user']) != 'undefined') { | ||
453 | parameters['user']['lock'] = this.serverLockValue(); | ||
454 | } | ||
432 | 455 | ||
433 | //console.log(">>> Connection.message", aMessageName, someParameters); | 456 | //console.log(">>> Connection.message", aMessageName, someParameters); |
434 | args = { | 457 | args = { |
435 | message: aMessageName, | 458 | message: aMessageName, |
436 | srpSharedSecret: this.sharedSecret(), | 459 | srpSharedSecret: this.sharedSecret(), |
437 | parameters: (someParameters || {}) | 460 | // parameters: (someParameters || {}) |
461 | parameters: parameters | ||
438 | } | 462 | } |
439 | 463 | ||
440 | return this.sendMessage(args); | 464 | return this.sendMessage(args); |
441 | }, | 465 | }, |
442 | 466 | ||
443 | //------------------------------------------------------------------------- | 467 | //------------------------------------------------------------------------- |
444 | 468 | ||
445 | 'sendMessage': function(someArguments) { | 469 | 'sendMessage': function(someArguments) { |
446 | vardeferredResult; | 470 | vardeferredResult; |
447 | 471 | ||
448 | deferredResult = new Clipperz.Async.Deferred("Connection.sendMessage", {trace:false}); | 472 | deferredResult = new Clipperz.Async.Deferred("Connection.sendMessage", {trace:false}); |
449 | deferredResult.addMethod(this.proxy(), 'message', someArguments); | 473 | deferredResult.addMethod(this.proxy(), 'message', someArguments); |
450 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | 474 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { |
451 | if (typeof(res['lock']) != 'undefined') { | 475 | if (typeof(res['lock']) != 'undefined') { |
452 | //TODO: ????? | 476 | this.setServerLockValue(res['lock']); |
453 | // ?? this.user().setLock(res['lock']); | ||
454 | } | 477 | } |
455 | return res; | 478 | return res; |
456 | }, this)); | 479 | }, this)); |
457 | 480 | ||
458 | deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments); | 481 | deferredResult.addErrback(MochiKit.Base.method(this, 'messageExceptionHandler'), someArguments); |
459 | deferredResult.callback(); | 482 | deferredResult.callback(); |
460 | 483 | ||
461 | return deferredResult | 484 | return deferredResult |
@@ -582,16 +605,17 @@ Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz. | |||
582 | 605 | ||
583 | //----------------------------------------------------------------------------- | 606 | //----------------------------------------------------------------------------- |
584 | __syntaxFix__: "syntax fix" | 607 | __syntaxFix__: "syntax fix" |
585 | 608 | ||
586 | }); | 609 | }); |
587 | 610 | ||
588 | Clipperz.PM.Connection.exception = { | 611 | Clipperz.PM.Connection.exception = { |
589 | WrongChecksum: new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.InvalidValue"), | 612 | WrongChecksum: new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.InvalidValue"), |
613 | StaleData: new MochiKit.Base.NamedError("Stale data"), | ||
590 | UnexpectedRequest:new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.UnexpectedRequest") | 614 | UnexpectedRequest:new MochiKit.Base.NamedError("Clipperz.ByteArray.exception.UnexpectedRequest") |
591 | }; | 615 | }; |
592 | 616 | ||
593 | 617 | ||
594 | Clipperz.PM.Connection.communicationProtocol = { | 618 | Clipperz.PM.Connection.communicationProtocol = { |
595 | 'currentVersion': '0.2', | 619 | 'currentVersion': '0.2', |
596 | 'versions': { | 620 | 'versions': { |
597 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, | 621 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, |