Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: remoting/webapp/crd/js/session_connector_impl.js

Issue 954373002: [Webapp Refactor] Group authentications fields into remoting.CredentialsProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove supports() Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Connect set-up state machine for Me2Me and IT2Me 7 * Connect set-up state machine for Me2Me and IT2Me
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // Initialize/declare per-connection state. 110 // Initialize/declare per-connection state.
111 this.reset(); 111 this.reset();
112 }; 112 };
113 113
114 /** 114 /**
115 * Reset the per-connection state so that the object can be re-used for a 115 * Reset the per-connection state so that the object can be re-used for a
116 * second connection. Note the none of the shared WCS state is reset. 116 * second connection. Note the none of the shared WCS state is reset.
117 */ 117 */
118 remoting.SessionConnectorImpl.prototype.reset = function() { 118 remoting.SessionConnectorImpl.prototype.reset = function() {
119 /** 119 /**
120 * For paired connections, the client id of this device, issued by the host.
121 *
122 * @type {string}
123 * @private
124 */
125 this.clientPairingId_ = '';
126
127 /**
128 * For paired connections, the paired secret for this device, issued by the
129 * host.
130 *
131 * @type {string}
132 * @private
133 */
134 this.clientPairedSecret_ = '';
135
136 /**
137 * String used to authenticate to the host on connection. For IT2Me, this is
138 * the access code; for Me2Me it is the PIN.
139 *
140 * @type {string}
141 * @private
142 */
143 this.passPhrase_ = '';
144
145 /**
146 * @type {remoting.Host} 120 * @type {remoting.Host}
147 * @private 121 * @private
148 */ 122 */
149 this.host_ = null; 123 this.host_ = null;
150 124
151 /** 125 /**
152 * @type {boolean} 126 * @type {boolean}
153 * @private 127 * @private
154 */ 128 */
155 this.logHostOfflineErrors_ = false; 129 this.logHostOfflineErrors_ = false;
156 130
157 /** 131 /**
158 * @type {remoting.ClientSession} 132 * @type {remoting.ClientSession}
159 * @private 133 * @private
160 */ 134 */
161 this.clientSession_ = null; 135 this.clientSession_ = null;
162 136
163 /** 137 /**
164 * @type {XMLHttpRequest} 138 * @type {XMLHttpRequest}
165 * @private 139 * @private
166 */ 140 */
167 this.pendingXhr_ = null; 141 this.pendingXhr_ = null;
168 142
169 /** 143 /**
170 * Function to interactively obtain the PIN from the user. 144 * @type {remoting.CredentialsProvider}
171 * @type {function(boolean, function(string):void):void}
172 * @private 145 * @private
173 */ 146 */
174 this.fetchPin_ = function(onPinFetched) {}; 147 this.credentialsProvider_ = null;
175
176 /**
177 * @type {function(string, string, string,
178 * function(string, string):void): void}
179 * @private
180 */
181 this.fetchThirdPartyToken_ = function(
182 tokenUrl, hostPublicKey, scope, onThirdPartyTokenFetched) {};
183 }; 148 };
184 149
185 /** 150 /**
186 * Initiate a Me2Me connection. 151 * Initiate a Me2Me connection.
187 * 152 *
188 * This doesn't report host-offline errors because the connection will 153 * This doesn't report host-offline errors because the connection will
189 * be retried and retryConnectMe2Me is responsible for reporting these errors. 154 * be retried and retryConnectMe2Me is responsible for reporting these errors.
190 * 155 *
191 * @param {remoting.Host} host The Me2Me host to which to connect. 156 * @param {remoting.Host} host The Me2Me host to which to connect.
192 * @param {function(boolean, function(string):void):void} fetchPin Function to 157 * @param {function(boolean, function(string):void):void} fetchPin Function to
193 * interactively obtain the PIN from the user. 158 * interactively obtain the PIN from the user.
194 * @param {function(string, string, string,
195 * function(string, string): void): void}
196 * fetchThirdPartyToken Function to obtain a token from a third party
197 * authentication server.
198 * @param {string} clientPairingId The client id issued by the host when 159 * @param {string} clientPairingId The client id issued by the host when
199 * this device was paired, if it is already paired. 160 * this device was paired, if it is already paired.
200 * @param {string} clientPairedSecret The shared secret issued by the host when 161 * @param {string} clientPairedSecret The shared secret issued by the host when
201 * this device was paired, if it is already paired. 162 * this device was paired, if it is already paired.
202 * @return {void} Nothing. 163 * @return {void} Nothing.
203 */ 164 */
204 remoting.SessionConnectorImpl.prototype.connectMe2Me = 165 remoting.SessionConnectorImpl.prototype.connectMe2Me =
205 function(host, fetchPin, fetchThirdPartyToken, 166 function(host, fetchPin, fetchThirdPartyToken,
206 clientPairingId, clientPairedSecret) { 167 clientPairingId, clientPairedSecret) {
207 this.connectionMode_ = remoting.DesktopConnectedView.Mode.ME2ME; 168 this.connectionMode_ = remoting.DesktopConnectedView.Mode.ME2ME;
208 this.logHostOfflineErrors_ = false; 169 this.logHostOfflineErrors_ = false;
209 this.connectMe2MeInternal_(host, fetchPin, fetchThirdPartyToken, 170 var credentialsProvider = new remoting.CredentialsProvider({
210 clientPairingId, clientPairedSecret); 171 fetchPin: fetchPin,
172 pairingInfo: { id: clientPairingId, secret: clientPairedSecret },
173 fetchThirdPartyToken: fetchThirdPartyToken
174 });
175 this.connectInternal_(host, credentialsProvider);
211 }; 176 };
212 177
213 /** 178 /**
214 * Retry connecting to a Me2Me host after a connection failure. 179 * Retry connecting to a Me2Me host after a connection failure.
215 * 180 *
216 * This is the same as connectMe2Me except that is will log errors if the 181 * This is the same as connectMe2Me except that is will log errors if the
217 * host is offline. 182 * host is offline.
218 * 183 *
219 * @param {remoting.Host} host The Me2Me host to refresh. 184 * @param {remoting.Host} host The Me2Me host to refresh.
220 * @return {void} Nothing. 185 * @return {void} Nothing.
221 */ 186 */
222 remoting.SessionConnectorImpl.prototype.retryConnectMe2Me = function(host) { 187 remoting.SessionConnectorImpl.prototype.retryConnectMe2Me = function(host) {
223 this.connectionMode_ = remoting.DesktopConnectedView.Mode.ME2ME; 188 this.connectionMode_ = remoting.DesktopConnectedView.Mode.ME2ME;
224 this.logHostOfflineErrors_ = true; 189 this.logHostOfflineErrors_ = true;
225 this.connectMe2MeInternal_(host, this.fetchPin_, this.fetchThirdPartyToken_, 190 this.connectInternal_(host, this.credentialsProvider_);
226 this.clientPairingId_, this.clientPairedSecret_);
227 }; 191 };
228 192
229 /** 193 /**
230 * Initiate a Me2App connection. 194 * Initiate a Me2App connection.
231 * 195 *
232 * @param {remoting.Host} host The Me2Me host to which to connect. 196 * @param {remoting.Host} host The Me2Me host to which to connect.
233 * @param {function(string, string, string, 197 * @param {function(string, string, string,
234 * function(string, string): void): void} 198 * function(string, string): void): void}
235 * fetchThirdPartyToken Function to obtain a token from a third party 199 * fetchThirdPartyToken Function to obtain a token from a third party
236 * authenticaiton server. 200 * authenticaiton server.
237 * @return {void} Nothing. 201 * @return {void} Nothing.
238 */ 202 */
239 remoting.SessionConnectorImpl.prototype.connectMe2App = 203 remoting.SessionConnectorImpl.prototype.connectMe2App =
240 function(host, fetchThirdPartyToken) { 204 function(host, fetchThirdPartyToken) {
241 this.connectionMode_ = remoting.DesktopConnectedView.Mode.APP_REMOTING; 205 this.connectionMode_ = remoting.DesktopConnectedView.Mode.APP_REMOTING;
242 this.logHostOfflineErrors_ = true; 206 this.logHostOfflineErrors_ = true;
243 this.connectMe2MeInternal_(host, function() {}, fetchThirdPartyToken, '', ''); 207 var credentialsProvider = new remoting.CredentialsProvider({
208 fetchThirdPartyToken : fetchThirdPartyToken
209 });
210 this.connectInternal_(host, credentialsProvider);
244 }; 211 };
245 212
246 /** 213 /**
247 * Update the pairing info so that the reconnect function will work correctly. 214 * Update the pairing info so that the reconnect function will work correctly.
248 * 215 *
249 * @param {string} clientId The paired client id. 216 * @param {string} clientId The paired client id.
250 * @param {string} sharedSecret The shared secret. 217 * @param {string} sharedSecret The shared secret.
251 */ 218 */
252 remoting.SessionConnectorImpl.prototype.updatePairingInfo = 219 remoting.SessionConnectorImpl.prototype.updatePairingInfo =
253 function(clientId, sharedSecret) { 220 function(clientId, sharedSecret) {
254 this.clientPairingId_ = clientId; 221 var pairingInfo = this.credentialsProvider_.getPairingInfo();
255 this.clientPairedSecret_ = sharedSecret; 222 pairingInfo.id = clientId;
223 pairingInfo.secret = sharedSecret;
256 }; 224 };
257 225
258 /** 226 /**
259 * Initiate a Me2Me connection. 227 * Initiates a connection.
260 * 228 *
261 * @param {remoting.Host} host the Host to connect to. 229 * @param {remoting.Host} host the Host to connect to.
262 * @param {function(boolean, function(string):void):void} fetchPin Function to 230 * @param {remoting.CredentialsProvider} credentialsProvider
263 * interactively obtain the PIN from the user.
264 * @param {function(string, string, string,
265 * function(string, string): void): void}
266 * fetchThirdPartyToken Function to obtain a token from a third party
267 * authentication server.
268 * @param {string} clientPairingId The client id issued by the host when
269 * this device was paired, if it is already paired.
270 * @param {string} clientPairedSecret The shared secret issued by the host when
271 * this device was paired, if it is already paired.
272 * @return {void} Nothing. 231 * @return {void} Nothing.
273 * @private 232 * @private
274 */ 233 */
275 remoting.SessionConnectorImpl.prototype.connectMe2MeInternal_ = 234 remoting.SessionConnectorImpl.prototype.connectInternal_ =
276 function(host, fetchPin, fetchThirdPartyToken, 235 function(host, credentialsProvider) {
277 clientPairingId, clientPairedSecret) {
278 // Cancel any existing connect operation. 236 // Cancel any existing connect operation.
279 this.cancel(); 237 this.cancel();
280 238
281 this.host_ = host; 239 this.host_ = host;
282 this.fetchPin_ = fetchPin; 240 this.credentialsProvider_ = credentialsProvider;
283 this.fetchThirdPartyToken_ = fetchThirdPartyToken;
284 this.updatePairingInfo(clientPairingId, clientPairedSecret);
285
286 this.connectSignaling_(); 241 this.connectSignaling_();
287 }; 242 };
288 243
289 /** 244 /**
290 * Initiate an IT2Me connection. 245 * Initiate an IT2Me connection.
291 * 246 *
292 * @param {string} accessCode The access code as entered by the user. 247 * @param {string} accessCode The access code as entered by the user.
293 * @return {void} Nothing. 248 * @return {void} Nothing.
294 */ 249 */
295 remoting.SessionConnectorImpl.prototype.connectIT2Me = function(accessCode) { 250 remoting.SessionConnectorImpl.prototype.connectIT2Me = function(accessCode) {
296 var kSupportIdLen = 7; 251 var kSupportIdLen = 7;
297 var kHostSecretLen = 5; 252 var kHostSecretLen = 5;
298 var kAccessCodeLen = kSupportIdLen + kHostSecretLen; 253 var kAccessCodeLen = kSupportIdLen + kHostSecretLen;
299 254
300 // Cancel any existing connect operation. 255 // Cancel any existing connect operation.
301 this.cancel(); 256 this.cancel();
302 257
303 var normalizedAccessCode = this.normalizeAccessCode_(accessCode); 258 var normalizedAccessCode = this.normalizeAccessCode_(accessCode);
304 if (normalizedAccessCode.length != kAccessCodeLen) { 259 if (normalizedAccessCode.length != kAccessCodeLen) {
305 this.onError_(remoting.Error.INVALID_ACCESS_CODE); 260 this.onError_(remoting.Error.INVALID_ACCESS_CODE);
306 return; 261 return;
307 } 262 }
308
309 var hostId = normalizedAccessCode.substring(0, kSupportIdLen); 263 var hostId = normalizedAccessCode.substring(0, kSupportIdLen);
310 this.passPhrase_ = normalizedAccessCode; 264 this.credentialsProvider_ = new remoting.CredentialsProvider({
265 accessCode: normalizedAccessCode
266 });
311 this.connectionMode_ = remoting.DesktopConnectedView.Mode.IT2ME; 267 this.connectionMode_ = remoting.DesktopConnectedView.Mode.IT2ME;
312 remoting.identity.getToken().then( 268 remoting.identity.getToken().then(
313 this.connectIT2MeWithToken_.bind(this, hostId), 269 this.connectIT2MeWithToken_.bind(this, hostId),
314 remoting.Error.handler(this.onError_)); 270 remoting.Error.handler(this.onError_));
315 }; 271 };
316 272
317 /** 273 /**
318 * Reconnect a closed connection. 274 * Reconnect a closed connection.
319 * 275 *
320 * @return {void} Nothing. 276 * @return {void} Nothing.
321 */ 277 */
322 remoting.SessionConnectorImpl.prototype.reconnect = function() { 278 remoting.SessionConnectorImpl.prototype.reconnect = function() {
323 if (this.connectionMode_ == remoting.DesktopConnectedView.Mode.IT2ME) { 279 if (this.connectionMode_ == remoting.DesktopConnectedView.Mode.IT2ME) {
324 console.error('reconnect not supported for IT2Me.'); 280 console.error('reconnect not supported for IT2Me.');
325 return; 281 return;
326 } 282 }
327 this.logHostOfflineErrors_ = false; 283 this.logHostOfflineErrors_ = false;
328 this.connectMe2MeInternal_(this.host_, this.fetchPin_, 284 this.connectInternal_(this.host_, this.credentialsProvider_);
329 this.fetchThirdPartyToken_, this.clientPairingId_,
330 this.clientPairedSecret_);
331 }; 285 };
332 286
333 /** 287 /**
334 * Cancel a connection-in-progress. 288 * Cancel a connection-in-progress.
335 */ 289 */
336 remoting.SessionConnectorImpl.prototype.cancel = function() { 290 remoting.SessionConnectorImpl.prototype.cancel = function() {
337 if (this.clientSession_) { 291 if (this.clientSession_) {
338 this.clientSession_.removePlugin(); 292 this.clientSession_.removePlugin();
339 this.clientSession_ = null; 293 this.clientSession_ = null;
340 } 294 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 * @return {void} Nothing. 384 * @return {void} Nothing.
431 * @private 385 * @private
432 */ 386 */
433 remoting.SessionConnectorImpl.prototype.connectIT2MeWithToken_ = 387 remoting.SessionConnectorImpl.prototype.connectIT2MeWithToken_ =
434 function(hostId, token) { 388 function(hostId, token) {
435 // Resolve the host id to get the host JID. 389 // Resolve the host id to get the host JID.
436 this.pendingXhr_ = remoting.xhr.start({ 390 this.pendingXhr_ = remoting.xhr.start({
437 method: 'GET', 391 method: 'GET',
438 url: remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + 392 url: remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' +
439 encodeURIComponent(hostId), 393 encodeURIComponent(hostId),
440 onDone: this.onIT2MeHostInfo_.bind(this), 394 onDone: this.onIT2MeHostInfo_.bind(this, hostId),
441 oauthToken: token 395 oauthToken: token
442 }); 396 });
443 }; 397 };
444 398
445 /** 399 /**
446 * Continue an IT2Me connection once the host JID has been looked up. 400 * Continue an IT2Me connection once the host JID has been looked up.
447 * 401 *
448 * @param {string} hostId 402 * @param {string} hostId
449 * @param {XMLHttpRequest} xhr The server response to the support-hosts query. 403 * @param {XMLHttpRequest} xhr The server response to the support-hosts query.
450 * @return {void} Nothing. 404 * @return {void} Nothing.
(...skipping 26 matching lines...) Expand all
477 */ 431 */
478 remoting.SessionConnectorImpl.prototype.createSession_ = function() { 432 remoting.SessionConnectorImpl.prototype.createSession_ = function() {
479 // In some circumstances, the WCS <iframe> can get reloaded, which results 433 // In some circumstances, the WCS <iframe> can get reloaded, which results
480 // in a new clientJid and a new callback. In this case, remove the old 434 // in a new clientJid and a new callback. In this case, remove the old
481 // client plugin before instantiating a new one. 435 // client plugin before instantiating a new one.
482 if (this.clientSession_) { 436 if (this.clientSession_) {
483 this.clientSession_.removePlugin(); 437 this.clientSession_.removePlugin();
484 this.clientSession_ = null; 438 this.clientSession_ = null;
485 } 439 }
486 440
487 var authenticationMethods =
488 'third_party,spake2_pair,spake2_hmac,spake2_plain';
489 this.clientSession_ = new remoting.ClientSession( 441 this.clientSession_ = new remoting.ClientSession(
490 this.host_, this.signalStrategy_, this.clientContainer_, this.passPhrase_, 442 this.host_, this.signalStrategy_, this.credentialsProvider_,
491 this.fetchPin_, this.fetchThirdPartyToken_, authenticationMethods, 443 this.clientContainer_, this.connectionMode_, this.defaultRemapKeys_);
492 this.connectionMode_, this.clientPairingId_, this.clientPairedSecret_,
493 this.defaultRemapKeys_);
494 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); 444 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_);
495 this.clientSession_.addEventListener( 445 this.clientSession_.addEventListener(
496 remoting.ClientSession.Events.stateChanged, 446 remoting.ClientSession.Events.stateChanged,
497 this.bound_.onStateChange); 447 this.bound_.onStateChange);
498 this.clientSession_.createPluginAndConnect(this.onExtensionMessage_, 448 this.clientSession_.createPluginAndConnect(this.onExtensionMessage_,
499 this.requiredCapabilities_); 449 this.requiredCapabilities_);
500 }; 450 };
501 451
502 /** 452 /**
503 * Handle a change in the state of the client session prior to successful 453 * Handle a change in the state of the client session prior to successful
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 */ 574 */
625 remoting.DefaultSessionConnectorFactory.prototype.createConnector = 575 remoting.DefaultSessionConnectorFactory.prototype.createConnector =
626 function(clientContainer, onConnected, onError, onExtensionMessage, 576 function(clientContainer, onConnected, onError, onExtensionMessage,
627 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { 577 onConnectionFailed, requiredCapabilities, defaultRemapKeys) {
628 return new remoting.SessionConnectorImpl(clientContainer, onConnected, 578 return new remoting.SessionConnectorImpl(clientContainer, onConnected,
629 onError, onExtensionMessage, 579 onError, onExtensionMessage,
630 onConnectionFailed, 580 onConnectionFailed,
631 requiredCapabilities, 581 requiredCapabilities,
632 defaultRemapKeys); 582 defaultRemapKeys);
633 }; 583 };
OLDNEW
« remoting/webapp/crd/js/credentials_provider.js ('K') | « remoting/webapp/crd/js/identity.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698