summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/Connection.js
Unidiff
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.js33
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,603 +1,600 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer 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
26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
27if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } 25if (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
35Clipperz.PM.Connection = function (args) { 33Clipperz.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
49Clipperz.PM.Connection.prototype = MochiKit.Base.update(null, { 47Clipperz.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) {
89MochiKit.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;
138 }, 137 },
139 138
140 //------------------------------------------------------------------------- 139 //-------------------------------------------------------------------------
141 140
142 'connectionId': function() { 141 'connectionId': function() {
143 return this._connectionId; 142 return this._connectionId;
144 }, 143 },
145 144
146 'setConnectionId': function(aValue) { 145 'setConnectionId': function(aValue) {
147 this._connectionId = aValue; 146 this._connectionId = aValue;
148 }, 147 },
149 148
150 //------------------------------------------------------------------------- 149 //-------------------------------------------------------------------------
151 150
152 'serverLockValue': function () { 151 'serverLockValue': function () {
153 return this._serverLockValue; 152 return this._serverLockValue;
154 }, 153 },
155 154
156 'setServerLockValue': function (aValue) { 155 'setServerLockValue': function (aValue) {
157 this._serverLockValue = aValue; 156 this._serverLockValue = aValue;
158 }, 157 },
159 158
160 //========================================================================= 159 //=========================================================================
161/* 160/*
162 //TODO: ????? 161 //TODO: ?????
163 'oneTimePassword': function() { 162 'oneTimePassword': function() {
164 return this._oneTimePassword; 163 return this._oneTimePassword;
165 }, 164 },
166 165
167 'setOneTimePassword': function(aValue) { 166 'setOneTimePassword': function(aValue) {
168 this._oneTimePassword = aValue; 167 this._oneTimePassword = aValue;
169 }, 168 },
170*/ 169*/
171 //========================================================================= 170 //=========================================================================
172 171
173 'reset': function() { 172 'reset': function() {
174 this.setSharedSecret(null); 173 this.setSharedSecret(null);
175 this.setConnectionId(null); 174 this.setConnectionId(null);
176 }, 175 },
177 176
178 //========================================================================= 177 //=========================================================================
179 __syntaxFix__: "syntax fix" 178 __syntaxFix__: "syntax fix"
180 179
181} 180}
182); 181);
183 182
184 183
185if (typeof(Clipperz.PM.Connection.SRP) == 'undefined') { Clipperz.PM.Connection.SRP = {}; } 184if (typeof(Clipperz.PM.Connection.SRP) == 'undefined') { Clipperz.PM.Connection.SRP = {}; }
186//----------------------------------------------------------------------------- 185//-----------------------------------------------------------------------------
187// 186//
188 // S R P [ 1 . 0 ] C O N N E C T I O N class 187 // S R P [ 1 . 0 ] C O N N E C T I O N class
189// 188//
190//----------------------------------------------------------------------------- 189//-----------------------------------------------------------------------------
191 190
192Clipperz.PM.Connection.SRP['1.0'] = function (args) { 191Clipperz.PM.Connection.SRP['1.0'] = function (args) {
193 Clipperz.PM.Connection.call(this, args); 192 Clipperz.PM.Connection.call(this, args);
194 193
195 return this; 194 return this;
196} 195}
197 196
198Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection(), { 197Clipperz.PM.Connection.SRP['1.0'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection(), {
199 198
200 'version': function() { 199 'version': function() {
201 return '1.0'; 200 return '1.0';
202 }, 201 },
203 202
204 //========================================================================= 203 //=========================================================================
205 204
206 'register': function (someUserData) { 205 'register': function (someUserData) {
207 vardeferredResult; 206 vardeferredResult;
208 var cryptoVersion; 207 var cryptoVersion;
209 var srpConnection; 208 var srpConnection;
210 209
211 cryptoVersion = this.clipperz_pm_crypto_version(); 210 cryptoVersion = this.clipperz_pm_crypto_version();
212 211
213 deferredResult = new Clipperz.Async.Deferred("Connection.registerWithVersion", {trace:false}); 212 deferredResult = new Clipperz.Async.Deferred("Connection.registerWithVersion", {trace:false});
214 deferredResult.collectResults({ 213 deferredResult.collectResults({
215 'credentials': [ 214 'credentials': [
216 this.getCredentialsFunction(), 215 this.getCredentialsFunction(),
217 MochiKit.Base.method(this, 'normalizedCredentials'), 216 MochiKit.Base.method(this, 'normalizedCredentials'),
218 MochiKit.Base.bind(function(someCredentials) { 217 MochiKit.Base.bind(function(someCredentials) {
219 var srpConnection; 218 var srpConnection;
220 var result; 219 var result;
221 220
222 srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() }); 221 srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() });
223 result = srpConnection.serverSideCredentials(); 222 result = srpConnection.serverSideCredentials();
224 result['version'] = Clipperz.PM.Connection.communicationProtocol.currentVersion; 223 result['version'] = Clipperz.PM.Connection.communicationProtocol.currentVersion;
225 224
226 return result; 225 return result;
227 }, this) 226 }, this)
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,
325 version:aResult['version'] 323 version:aResult['version']
326 }); 324 });
327 }, 325 },
328 function(aResult) { 326 function(aResult) {
329 return (new Clipperz.ByteArray().appendBase64String(aResult['passphrase'])).asString(); 327 return (new Clipperz.ByteArray().appendBase64String(aResult['passphrase'])).asString();
330 } 328 }
331 ], {trace:false}) 329 ], {trace:false})
332 }, 330 },
333 331
334 'login': function(isReconnecting) { 332 'login': function(isReconnecting) {
335 vardeferredResult; 333 vardeferredResult;
336 var cryptoVersion; 334 var cryptoVersion;
337 var srpConnection; 335 var srpConnection;
338 336
339 cryptoVersion = this.clipperz_pm_crypto_version(); 337 cryptoVersion = this.clipperz_pm_crypto_version();
340 deferredResult = new Clipperz.Async.Deferred("Connection.login", {trace:false}); 338 deferredResult = new Clipperz.Async.Deferred("Connection.login", {trace:false});
341 deferredResult.addCallback(this.getCredentialsFunction()); 339 deferredResult.addCallback(this.getCredentialsFunction());
342 deferredResult.addMethod(this, 'normalizedCredentials'); 340 deferredResult.addMethod(this, 'normalizedCredentials');
343 // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_sendingCredentials'); 341 // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_sendingCredentials');
344 deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); 342 deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress');
345 deferredResult.addCallback(MochiKit.Base.bind(function(someCredentials) { 343 deferredResult.addCallback(MochiKit.Base.bind(function(someCredentials) {
346 srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() }); 344 srpConnection = new Clipperz.Crypto.SRP.Connection({ C:someCredentials['username'], P:someCredentials['password'], hash:this.hash() });
347 }, this)); 345 }, this));
348 deferredResult.addCallback(function() { 346 deferredResult.addCallback(function() {
349 var result; 347 var result;
350 348
351 result = { 349 result = {
352 message: 'connect', 350 message: 'connect',
353 version: cryptoVersion, 351 version: cryptoVersion,
354 parameters: { 352 parameters: {
355 C: srpConnection.C(), 353 C: srpConnection.C(),
356 A: srpConnection.A().asString(16) 354 A: srpConnection.A().asString(16)
357 // reconnecting: this.connectionId() 355 // reconnecting: this.connectionId()
358 } 356 }
359 }; 357 };
360 358
361 // TODO: ????? 359 // TODO: ?????
362 // if (isReconnecting == true) { 360 // if (isReconnecting == true) {
363 // args.parameters['reconnecting'] = aConnection.connectionId(); 361 // args.parameters['reconnecting'] = aConnection.connectionId();
364 // } 362 // }
365 363
366 return result; 364 return result;
367 }); 365 });
368 deferredResult.addMethod(this.proxy(), 'handshake'); 366 deferredResult.addMethod(this.proxy(), 'handshake');
369 // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_credentialVerification'); 367 // deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'updatedProgressState', 'connection_credentialVerification');
370 deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); 368 deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress');
371 deferredResult.addCallback(function(someParameters) { 369 deferredResult.addCallback(function(someParameters) {
372 var result; 370 var result;
373 371
374 srpConnection.set_s(new Clipperz.Crypto.BigInt(someParameters['s'], 16)); 372 srpConnection.set_s(new Clipperz.Crypto.BigInt(someParameters['s'], 16));
375 srpConnection.set_B(new Clipperz.Crypto.BigInt(someParameters['B'], 16)); 373 srpConnection.set_B(new Clipperz.Crypto.BigInt(someParameters['B'], 16));
376 374
377 //TODO: ????? 375 //TODO: ?????
378 // if (typeof(someParameters['oneTimePassword']) != 'undefined') { 376 // if (typeof(someParameters['oneTimePassword']) != 'undefined') {
379 // this.setOneTimePassword(someParameters['oneTimePassword']); 377 // this.setOneTimePassword(someParameters['oneTimePassword']);
380 // } 378 // }
381 379
382 result = { 380 result = {
383 message: 'credentialCheck', 381 message: 'credentialCheck',
384 version: cryptoVersion, 382 version: cryptoVersion,
385 parameters: { 383 parameters: {
386 M1: srpConnection.M1() 384 M1: srpConnection.M1()
387 } 385 }
388 }; 386 };
389 387
390 return result; 388 return result;
391 }); 389 });
392 deferredResult.addMethod(this.proxy(), 'handshake'); 390 deferredResult.addMethod(this.proxy(), 'handshake');
393 deferredResult.addCallback(function(someParameters) { 391 deferredResult.addCallback(function(someParameters) {
394 var result; 392 var result;
395 393
396 if (someParameters['M2'] == srpConnection.M2()) { 394 if (someParameters['M2'] == srpConnection.M2()) {
397 result = MochiKit.Async.succeed(someParameters); 395 result = MochiKit.Async.succeed(someParameters);
398 } else { 396 } else {
399 result = MochiKit.Async.fail(Clipperz.PM.Connection.exception.WrongChecksum); 397 result = MochiKit.Async.fail(Clipperz.PM.Connection.exception.WrongChecksum);
400 } 398 }
401 399
402 return result; 400 return result;
403 }); 401 });
404 deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) { 402 deferredResult.addCallback(MochiKit.Base.bind(function(someParameters) {
405 this.setConnectionId(someParameters['connectionId']); 403 this.setConnectionId(someParameters['connectionId']);
406 this.setSharedSecret(srpConnection.K()); 404 this.setSharedSecret(srpConnection.K());
407 405
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
492console.log(">>> Connection.messageExceptionHandler", anError, anError.message); 489Clipperz.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 }
506console.log("<<< Connection.messageExceptionHandler", anError) 503Clipperz.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 },
556 553
557 //----------------------------------------------------------------------------- 554 //-----------------------------------------------------------------------------
558 555
559 'hash': function() { 556 'hash': function() {
560 return Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].hash; 557 return Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].hash;
561 }, 558 },
562 559
563 //----------------------------------------------------------------------------- 560 //-----------------------------------------------------------------------------
564 __syntaxFix__: "syntax fix" 561 __syntaxFix__: "syntax fix"
565 562
566}); 563});
567 564
568 565
569 566
570//----------------------------------------------------------------------------- 567//-----------------------------------------------------------------------------
571// 568//
572 // S R P [ 1 . 1 ] C O N N E C T I O N class 569 // S R P [ 1 . 1 ] C O N N E C T I O N class
573// 570//
574//----------------------------------------------------------------------------- 571//-----------------------------------------------------------------------------
575 572
576Clipperz.PM.Connection.SRP['1.1'] = function (args) { 573Clipperz.PM.Connection.SRP['1.1'] = function (args) {
577 Clipperz.PM.Connection.SRP['1.0'].call(this, args); 574 Clipperz.PM.Connection.SRP['1.0'].call(this, args);
578 575
579 return this; 576 return this;
580} 577}
581 578
582Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection.SRP['1.0'](), { 579Clipperz.PM.Connection.SRP['1.1'].prototype = MochiKit.Base.update(new Clipperz.PM.Connection.SRP['1.0'](), {
583 580
584 'version': function() { 581 'version': function() {
585 return '1.1'; 582 return '1.1';
586 }, 583 },
587 584
588 //----------------------------------------------------------------------------- 585 //-----------------------------------------------------------------------------
589 586
590 'normalizedCredentials': function(someValues) { 587 'normalizedCredentials': function(someValues) {
591 var result; 588 var result;
592 589
593 result = {} 590 result = {}
594 result['username'] = this.hash()(new Clipperz.ByteArray(someValues['username'] + someValues['password'])).toHexString().substring(2); 591 result['username'] = this.hash()(new Clipperz.ByteArray(someValues['username'] + someValues['password'])).toHexString().substring(2);
595 result['password'] = this.hash()(new Clipperz.ByteArray(someValues['password'] + someValues['username'])).toHexString().substring(2); 592 result['password'] = this.hash()(new Clipperz.ByteArray(someValues['password'] + someValues['username'])).toHexString().substring(2);
596 593
597 return result; 594 return result;
598 }, 595 },
599 596
600 //----------------------------------------------------------------------------- 597 //-----------------------------------------------------------------------------
601 598
602 'hash': function() { 599 'hash': function() {
603 return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash; 600 return Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].hash;