OLD | NEW |
---|---|
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 Loading... | |
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.credentials_ = 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 credentials = new remoting.CredentialsProvider({ |
210 clientPairingId, clientPairedSecret); | 171 fetchPin: fetchPin, |
172 pairingInfo: { id: clientPairingId, secret: clientPairedSecret }, | |
173 fetchThirdPartyToken: fetchThirdPartyToken | |
174 }); | |
175 this.connectInternal_(host, credentials); | |
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.credentials_); |
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 credentials = new remoting.CredentialsProvider({ |
208 fetchThirdPartyToken : fetchThirdPartyToken | |
209 }); | |
210 this.connectInternal_(host, credentials); | |
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.credentials_.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 * Initiate a Me2Me 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} credentials Credentials. |
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, credentials) { |
277 clientPairingId, clientPairedSecret) { | |
278 // Cancel any existing connect operation. | 236 // Cancel any existing connect operation. |
279 this.cancel(); | 237 this.cancel(); |
280 | |
Jamie
2015/02/26 23:20:14
Leave this blank line. It was intended to suggest
kelvinp
2015/02/27 01:03:21
Done.
| |
281 this.host_ = host; | 238 this.host_ = host; |
282 this.fetchPin_ = fetchPin; | 239 this.credentials_ = credentials; |
283 this.fetchThirdPartyToken_ = fetchThirdPartyToken; | |
284 this.updatePairingInfo(clientPairingId, clientPairedSecret); | |
285 | |
286 this.connectSignaling_(); | 240 this.connectSignaling_(); |
287 }; | 241 }; |
288 | 242 |
289 /** | 243 /** |
290 * Initiate an IT2Me connection. | 244 * Initiate an IT2Me connection. |
291 * | 245 * |
292 * @param {string} accessCode The access code as entered by the user. | 246 * @param {string} accessCode The access code as entered by the user. |
293 * @return {void} Nothing. | 247 * @return {void} Nothing. |
294 */ | 248 */ |
295 remoting.SessionConnectorImpl.prototype.connectIT2Me = function(accessCode) { | 249 remoting.SessionConnectorImpl.prototype.connectIT2Me = function(accessCode) { |
296 var kSupportIdLen = 7; | 250 var kSupportIdLen = 7; |
297 var kHostSecretLen = 5; | 251 var kHostSecretLen = 5; |
298 var kAccessCodeLen = kSupportIdLen + kHostSecretLen; | 252 var kAccessCodeLen = kSupportIdLen + kHostSecretLen; |
299 | 253 |
300 // Cancel any existing connect operation. | 254 // Cancel any existing connect operation. |
301 this.cancel(); | 255 this.cancel(); |
302 | 256 |
303 var normalizedAccessCode = this.normalizeAccessCode_(accessCode); | 257 var normalizedAccessCode = this.normalizeAccessCode_(accessCode); |
304 if (normalizedAccessCode.length != kAccessCodeLen) { | 258 if (normalizedAccessCode.length != kAccessCodeLen) { |
305 this.onError_(remoting.Error.INVALID_ACCESS_CODE); | 259 this.onError_(remoting.Error.INVALID_ACCESS_CODE); |
306 return; | 260 return; |
307 } | 261 } |
308 | |
309 var hostId = normalizedAccessCode.substring(0, kSupportIdLen); | 262 var hostId = normalizedAccessCode.substring(0, kSupportIdLen); |
310 this.passPhrase_ = normalizedAccessCode; | 263 this.credentials_ = new remoting.CredentialsProvider({ |
264 accessCode: normalizedAccessCode | |
265 }); | |
311 this.connectionMode_ = remoting.DesktopConnectedView.Mode.IT2ME; | 266 this.connectionMode_ = remoting.DesktopConnectedView.Mode.IT2ME; |
312 remoting.identity.getToken().then( | 267 remoting.identity.getToken().then( |
313 this.connectIT2MeWithToken_.bind(this, hostId), | 268 this.connectIT2MeWithToken_.bind(this, hostId), |
314 remoting.Error.handler(this.onError_)); | 269 remoting.Error.handler(this.onError_)); |
315 }; | 270 }; |
316 | 271 |
317 /** | 272 /** |
318 * Reconnect a closed connection. | 273 * Reconnect a closed connection. |
319 * | 274 * |
320 * @return {void} Nothing. | 275 * @return {void} Nothing. |
321 */ | 276 */ |
322 remoting.SessionConnectorImpl.prototype.reconnect = function() { | 277 remoting.SessionConnectorImpl.prototype.reconnect = function() { |
323 if (this.connectionMode_ == remoting.DesktopConnectedView.Mode.IT2ME) { | 278 if (this.connectionMode_ == remoting.DesktopConnectedView.Mode.IT2ME) { |
324 console.error('reconnect not supported for IT2Me.'); | 279 console.error('reconnect not supported for IT2Me.'); |
325 return; | 280 return; |
326 } | 281 } |
327 this.logHostOfflineErrors_ = false; | 282 this.logHostOfflineErrors_ = false; |
328 this.connectMe2MeInternal_(this.host_, this.fetchPin_, | 283 this.connectInternal_(this.host_, this.credentials_); |
329 this.fetchThirdPartyToken_, this.clientPairingId_, | |
330 this.clientPairedSecret_); | |
331 }; | 284 }; |
332 | 285 |
333 /** | 286 /** |
334 * Cancel a connection-in-progress. | 287 * Cancel a connection-in-progress. |
335 */ | 288 */ |
336 remoting.SessionConnectorImpl.prototype.cancel = function() { | 289 remoting.SessionConnectorImpl.prototype.cancel = function() { |
337 if (this.clientSession_) { | 290 if (this.clientSession_) { |
338 this.clientSession_.removePlugin(); | 291 this.clientSession_.removePlugin(); |
339 this.clientSession_ = null; | 292 this.clientSession_ = null; |
340 } | 293 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 * @return {void} Nothing. | 383 * @return {void} Nothing. |
431 * @private | 384 * @private |
432 */ | 385 */ |
433 remoting.SessionConnectorImpl.prototype.connectIT2MeWithToken_ = | 386 remoting.SessionConnectorImpl.prototype.connectIT2MeWithToken_ = |
434 function(hostId, token) { | 387 function(hostId, token) { |
435 // Resolve the host id to get the host JID. | 388 // Resolve the host id to get the host JID. |
436 this.pendingXhr_ = remoting.xhr.start({ | 389 this.pendingXhr_ = remoting.xhr.start({ |
437 method: 'GET', | 390 method: 'GET', |
438 url: remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + | 391 url: remoting.settings.DIRECTORY_API_BASE_URL + '/support-hosts/' + |
439 encodeURIComponent(hostId), | 392 encodeURIComponent(hostId), |
440 onDone: this.onIT2MeHostInfo_.bind(this), | 393 onDone: this.onIT2MeHostInfo_.bind(this, hostId), |
441 oauthToken: token | 394 oauthToken: token |
442 }); | 395 }); |
443 }; | 396 }; |
444 | 397 |
445 /** | 398 /** |
446 * Continue an IT2Me connection once the host JID has been looked up. | 399 * Continue an IT2Me connection once the host JID has been looked up. |
447 * | 400 * |
448 * @param {string} hostId | 401 * @param {string} hostId |
449 * @param {XMLHttpRequest} xhr The server response to the support-hosts query. | 402 * @param {XMLHttpRequest} xhr The server response to the support-hosts query. |
450 * @return {void} Nothing. | 403 * @return {void} Nothing. |
(...skipping 26 matching lines...) Expand all Loading... | |
477 */ | 430 */ |
478 remoting.SessionConnectorImpl.prototype.createSession_ = function() { | 431 remoting.SessionConnectorImpl.prototype.createSession_ = function() { |
479 // In some circumstances, the WCS <iframe> can get reloaded, which results | 432 // 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 | 433 // in a new clientJid and a new callback. In this case, remove the old |
481 // client plugin before instantiating a new one. | 434 // client plugin before instantiating a new one. |
482 if (this.clientSession_) { | 435 if (this.clientSession_) { |
483 this.clientSession_.removePlugin(); | 436 this.clientSession_.removePlugin(); |
484 this.clientSession_ = null; | 437 this.clientSession_ = null; |
485 } | 438 } |
486 | 439 |
487 var authenticationMethods = | |
488 'third_party,spake2_pair,spake2_hmac,spake2_plain'; | |
489 this.clientSession_ = new remoting.ClientSession( | 440 this.clientSession_ = new remoting.ClientSession( |
490 this.host_, this.signalStrategy_, this.clientContainer_, this.passPhrase_, | 441 this.host_, this.signalStrategy_, this.credentials_, |
491 this.fetchPin_, this.fetchThirdPartyToken_, authenticationMethods, | 442 this.clientContainer_, this.connectionMode_, this.defaultRemapKeys_); |
492 this.connectionMode_, this.clientPairingId_, this.clientPairedSecret_, | |
493 this.defaultRemapKeys_); | |
494 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); | 443 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); |
495 this.clientSession_.addEventListener( | 444 this.clientSession_.addEventListener( |
496 remoting.ClientSession.Events.stateChanged, | 445 remoting.ClientSession.Events.stateChanged, |
497 this.bound_.onStateChange); | 446 this.bound_.onStateChange); |
498 this.clientSession_.createPluginAndConnect(this.onExtensionMessage_, | 447 this.clientSession_.createPluginAndConnect(this.onExtensionMessage_, |
499 this.requiredCapabilities_); | 448 this.requiredCapabilities_); |
500 }; | 449 }; |
501 | 450 |
502 /** | 451 /** |
503 * Handle a change in the state of the client session prior to successful | 452 * 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 Loading... | |
624 */ | 573 */ |
625 remoting.DefaultSessionConnectorFactory.prototype.createConnector = | 574 remoting.DefaultSessionConnectorFactory.prototype.createConnector = |
626 function(clientContainer, onConnected, onError, onExtensionMessage, | 575 function(clientContainer, onConnected, onError, onExtensionMessage, |
627 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { | 576 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { |
628 return new remoting.SessionConnectorImpl(clientContainer, onConnected, | 577 return new remoting.SessionConnectorImpl(clientContainer, onConnected, |
629 onError, onExtensionMessage, | 578 onError, onExtensionMessage, |
630 onConnectionFailed, | 579 onConnectionFailed, |
631 requiredCapabilities, | 580 requiredCapabilities, |
632 defaultRemapKeys); | 581 defaultRemapKeys); |
633 }; | 582 }; |
OLD | NEW |