summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/Connection.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Connection.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/Connection.js34
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
@@ -32,24 +32,25 @@ if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
32// 32//
33//----------------------------------------------------------------------------- 33//-----------------------------------------------------------------------------
34 34
35Clipperz.PM.Connection = function (args) { 35Clipperz.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
48Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { 49Clipperz.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() + "]";
52 }, 53 },
53 54
54 //========================================================================= 55 //=========================================================================
55 56
@@ -137,24 +138,34 @@ MochiKit.Logging.logError("### Connection.defaultErrorHandler: " + anErrorString
137 }, 138 },
138 139
139 //------------------------------------------------------------------------- 140 //-------------------------------------------------------------------------
140 141
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) {
157 this._oneTimePassword = aValue; 168 this._oneTimePassword = aValue;
158 }, 169 },
159*/ 170*/
160 //========================================================================= 171 //=========================================================================
@@ -311,31 +322,30 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.
311 return Clipperz.PM.Crypto.deferredDecrypt({ 322 return Clipperz.PM.Crypto.deferredDecrypt({
312 value:aResult['data'], 323 value:aResult['data'],
313 key:normalizedOTP, 324 key:normalizedOTP,
314 version:aResult['version'] 325 version:aResult['version']
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));
338 deferredResult.addCallback(function() { 348 deferredResult.addCallback(function() {
339 var result; 349 var result;
340 350
341 result = { 351 result = {
@@ -390,24 +400,31 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.
390 } 400 }
391 401
392 return result; 402 return result;
393 }); 403 });
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
410 return deferredResult; 427 return deferredResult;
411 }, 428 },
412 429
413 //========================================================================= 430 //=========================================================================
@@ -420,46 +437,52 @@ Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.
420 }, 437 },
421 438
422 //========================================================================= 439 //=========================================================================
423 440
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
462 }, 485 },
463 486
464 //------------------------------------------------------------------------- 487 //-------------------------------------------------------------------------
465 488
@@ -578,24 +601,25 @@ Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz.
578 601
579 'hash': function() { 602 'hash': function() {
580 return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash; 603 return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash;
581 }, 604 },
582 605
583 //----------------------------------------------------------------------------- 606 //-----------------------------------------------------------------------------
584 __syntaxFix__: "syntax fix" 607 __syntaxFix__: "syntax fix"
585 608
586}); 609});
587 610
588Clipperz.PM.Connection.exception = { 611Clipperz.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
594Clipperz.PM.Connection.communicationProtocol = { 618Clipperz.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,
598 '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection 622 '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection
599 }, 623 },
600 'fallbackVersions': { 624 'fallbackVersions': {
601 // 'current':'0.1', 625 // 'current':'0.1',