OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 Handles web page requests for gnubby sign requests. | 6 * @fileoverview Handles web page requests for gnubby sign requests. |
7 * | 7 * |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // If the sign challenge array is empty, the global appId is required. | 216 // If the sign challenge array is empty, the global appId is required. |
217 if (!hasAppId && (!signChallenges || !signChallenges.length)) { | 217 if (!hasAppId && (!signChallenges || !signChallenges.length)) { |
218 return false; | 218 return false; |
219 } | 219 } |
220 return isValidSignChallengeArray(signChallenges, hasDefaultChallenge, | 220 return isValidSignChallengeArray(signChallenges, hasDefaultChallenge, |
221 !hasAppId); | 221 !hasAppId); |
222 } | 222 } |
223 | 223 |
224 /** | 224 /** |
225 * Adapter class representing a queued sign request. | 225 * Adapter class representing a queued sign request. |
226 * @param {!Array.<SignChallenge>} signChallenges The sign challenges. | 226 * @param {!Array<SignChallenge>} signChallenges The sign challenges. |
227 * @param {Countdown} timer Timeout timer | 227 * @param {Countdown} timer Timeout timer |
228 * @param {WebRequestSender} sender Message sender. | 228 * @param {WebRequestSender} sender Message sender. |
229 * @param {function(U2fError)} errorCb Error callback | 229 * @param {function(U2fError)} errorCb Error callback |
230 * @param {function(SignChallenge, string, string)} successCb Success callback | 230 * @param {function(SignChallenge, string, string)} successCb Success callback |
231 * @param {string|undefined} opt_defaultChallenge A default sign challenge | 231 * @param {string|undefined} opt_defaultChallenge A default sign challenge |
232 * value, if a request does not provide one. | 232 * value, if a request does not provide one. |
233 * @param {string|undefined} opt_appId The app id for the entire request. | 233 * @param {string|undefined} opt_appId The app id for the entire request. |
234 * @param {string|undefined} opt_logMsgUrl Url to post log messages to | 234 * @param {string|undefined} opt_logMsgUrl Url to post log messages to |
235 * @constructor | 235 * @constructor |
236 * @implements {Closeable} | 236 * @implements {Closeable} |
237 */ | 237 */ |
238 function QueuedSignRequest(signChallenges, timer, sender, errorCb, | 238 function QueuedSignRequest(signChallenges, timer, sender, errorCb, |
239 successCb, opt_defaultChallenge, opt_appId, opt_logMsgUrl) { | 239 successCb, opt_defaultChallenge, opt_appId, opt_logMsgUrl) { |
240 /** @private {!Array.<SignChallenge>} */ | 240 /** @private {!Array<SignChallenge>} */ |
241 this.signChallenges_ = signChallenges; | 241 this.signChallenges_ = signChallenges; |
242 /** @private {Countdown} */ | 242 /** @private {Countdown} */ |
243 this.timer_ = timer.clone(this.close.bind(this)); | 243 this.timer_ = timer.clone(this.close.bind(this)); |
244 /** @private {WebRequestSender} */ | 244 /** @private {WebRequestSender} */ |
245 this.sender_ = sender; | 245 this.sender_ = sender; |
246 /** @private {function(U2fError)} */ | 246 /** @private {function(U2fError)} */ |
247 this.errorCb_ = errorCb; | 247 this.errorCb_ = errorCb; |
248 /** @private {function(SignChallenge, string, string)} */ | 248 /** @private {function(SignChallenge, string, string)} */ |
249 this.successCb_ = successCb; | 249 this.successCb_ = successCb; |
250 /** @private {string|undefined} */ | 250 /** @private {string|undefined} */ |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 /** @private {function(SignChallenge, string, string)} */ | 354 /** @private {function(SignChallenge, string, string)} */ |
355 this.successCb_ = successCb; | 355 this.successCb_ = successCb; |
356 /** @private {string|undefined} */ | 356 /** @private {string|undefined} */ |
357 this.logMsgUrl_ = opt_logMsgUrl; | 357 this.logMsgUrl_ = opt_logMsgUrl; |
358 | 358 |
359 /** @private {boolean} */ | 359 /** @private {boolean} */ |
360 this.challengesSet_ = false; | 360 this.challengesSet_ = false; |
361 /** @private {boolean} */ | 361 /** @private {boolean} */ |
362 this.done_ = false; | 362 this.done_ = false; |
363 | 363 |
364 /** @private {Object.<string, string>} */ | 364 /** @private {Object<string, string>} */ |
365 this.browserData_ = {}; | 365 this.browserData_ = {}; |
366 /** @private {Object.<string, SignChallenge>} */ | 366 /** @private {Object<string, SignChallenge>} */ |
367 this.serverChallenges_ = {}; | 367 this.serverChallenges_ = {}; |
368 // Allow http appIds for http origins. (Broken, but the caller deserves | 368 // Allow http appIds for http origins. (Broken, but the caller deserves |
369 // what they get.) | 369 // what they get.) |
370 /** @private {boolean} */ | 370 /** @private {boolean} */ |
371 this.allowHttp_ = this.sender_.origin ? | 371 this.allowHttp_ = this.sender_.origin ? |
372 this.sender_.origin.indexOf('http://') == 0 : false; | 372 this.sender_.origin.indexOf('http://') == 0 : false; |
373 /** @private {Closeable} */ | 373 /** @private {Closeable} */ |
374 this.handler_ = null; | 374 this.handler_ = null; |
375 } | 375 } |
376 | 376 |
377 /** | 377 /** |
378 * Sets the challenges to be signed. | 378 * Sets the challenges to be signed. |
379 * @param {Array.<SignChallenge>} signChallenges The challenges to set. | 379 * @param {Array<SignChallenge>} signChallenges The challenges to set. |
380 * @param {string=} opt_defaultChallenge A default sign challenge | 380 * @param {string=} opt_defaultChallenge A default sign challenge |
381 * value, if a request does not provide one. | 381 * value, if a request does not provide one. |
382 * @param {string=} opt_appId The app id for the entire request. | 382 * @param {string=} opt_appId The app id for the entire request. |
383 * @return {boolean} Whether the challenges could be set. | 383 * @return {boolean} Whether the challenges could be set. |
384 */ | 384 */ |
385 Signer.prototype.setChallenges = function(signChallenges, opt_defaultChallenge, | 385 Signer.prototype.setChallenges = function(signChallenges, opt_defaultChallenge, |
386 opt_appId) { | 386 opt_appId) { |
387 if (this.challengesSet_ || this.done_) | 387 if (this.challengesSet_ || this.done_) |
388 return false; | 388 return false; |
389 if (this.timer_.expired()) { | 389 if (this.timer_.expired()) { |
390 this.notifyError_({errorCode: ErrorCodes.TIMEOUT}); | 390 this.notifyError_({errorCode: ErrorCodes.TIMEOUT}); |
391 return true; | 391 return true; |
392 } | 392 } |
393 /** @private {Array.<SignChallenge>} */ | 393 /** @private {Array<SignChallenge>} */ |
394 this.signChallenges_ = signChallenges; | 394 this.signChallenges_ = signChallenges; |
395 /** @private {string|undefined} */ | 395 /** @private {string|undefined} */ |
396 this.defaultChallenge_ = opt_defaultChallenge; | 396 this.defaultChallenge_ = opt_defaultChallenge; |
397 /** @private {string|undefined} */ | 397 /** @private {string|undefined} */ |
398 this.appId_ = opt_appId; | 398 this.appId_ = opt_appId; |
399 /** @private {boolean} */ | 399 /** @private {boolean} */ |
400 this.challengesSet_ = true; | 400 this.challengesSet_ = true; |
401 | 401 |
402 this.checkAppIds_(); | 402 this.checkAppIds_(); |
403 return true; | 403 return true; |
(...skipping 18 matching lines...) Expand all Loading... |
422 } | 422 } |
423 FACTORY_REGISTRY.getOriginChecker() | 423 FACTORY_REGISTRY.getOriginChecker() |
424 .canClaimAppIds(this.sender_.origin, appIds) | 424 .canClaimAppIds(this.sender_.origin, appIds) |
425 .then(this.originChecked_.bind(this, appIds)); | 425 .then(this.originChecked_.bind(this, appIds)); |
426 }; | 426 }; |
427 | 427 |
428 /** | 428 /** |
429 * Called with the result of checking the origin. When the origin is allowed | 429 * Called with the result of checking the origin. When the origin is allowed |
430 * to claim the app ids, begins checking whether the app ids also list the | 430 * to claim the app ids, begins checking whether the app ids also list the |
431 * origin. | 431 * origin. |
432 * @param {!Array.<string>} appIds The app ids. | 432 * @param {!Array<string>} appIds The app ids. |
433 * @param {boolean} result Whether the origin could claim the app ids. | 433 * @param {boolean} result Whether the origin could claim the app ids. |
434 * @private | 434 * @private |
435 */ | 435 */ |
436 Signer.prototype.originChecked_ = function(appIds, result) { | 436 Signer.prototype.originChecked_ = function(appIds, result) { |
437 if (!result) { | 437 if (!result) { |
438 var error = { | 438 var error = { |
439 errorCode: ErrorCodes.BAD_REQUEST, | 439 errorCode: ErrorCodes.BAD_REQUEST, |
440 errorMessage: 'bad appId' | 440 errorMessage: 'bad appId' |
441 }; | 441 }; |
442 this.notifyError_(error); | 442 this.notifyError_(error); |
443 return; | 443 return; |
444 } | 444 } |
445 /** @private {!AppIdChecker} */ | 445 /** @private {!AppIdChecker} */ |
446 this.appIdChecker_ = new AppIdChecker(FACTORY_REGISTRY.getTextFetcher(), | 446 this.appIdChecker_ = new AppIdChecker(FACTORY_REGISTRY.getTextFetcher(), |
447 this.timer_.clone(), this.sender_.origin, | 447 this.timer_.clone(), this.sender_.origin, |
448 /** @type {!Array.<string>} */ (appIds), this.allowHttp_, | 448 /** @type {!Array<string>} */ (appIds), this.allowHttp_, |
449 this.logMsgUrl_); | 449 this.logMsgUrl_); |
450 this.appIdChecker_.doCheck().then(this.appIdChecked_.bind(this)); | 450 this.appIdChecker_.doCheck().then(this.appIdChecked_.bind(this)); |
451 }; | 451 }; |
452 | 452 |
453 /** | 453 /** |
454 * Called with the result of checking app ids. When the app ids are valid, | 454 * Called with the result of checking app ids. When the app ids are valid, |
455 * adds the sign challenges to those being signed. | 455 * adds the sign challenges to those being signed. |
456 * @param {boolean} result Whether the app ids are valid. | 456 * @param {boolean} result Whether the app ids are valid. |
457 * @private | 457 * @private |
458 */ | 458 */ |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 | 604 |
605 var key = reply.responseData['keyHandle']; | 605 var key = reply.responseData['keyHandle']; |
606 var browserData = this.browserData_[key]; | 606 var browserData = this.browserData_[key]; |
607 // Notify with server-provided challenge, not the encoded one: the | 607 // Notify with server-provided challenge, not the encoded one: the |
608 // server-provided challenge contains additional fields it relies on. | 608 // server-provided challenge contains additional fields it relies on. |
609 var serverChallenge = this.serverChallenges_[key]; | 609 var serverChallenge = this.serverChallenges_[key]; |
610 this.notifySuccess_(serverChallenge, reply.responseData.signatureData, | 610 this.notifySuccess_(serverChallenge, reply.responseData.signatureData, |
611 browserData); | 611 browserData); |
612 } | 612 } |
613 }; | 613 }; |
OLD | NEW |