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 Does common handling for requests coming from web pages and | 6 * @fileoverview Does common handling for requests coming from web pages and |
7 * routes them to the provided handler. | 7 * routes them to the provided handler. |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 if (registeredKey['version'] != 'U2F_V1' && | 42 if (registeredKey['version'] != 'U2F_V1' && |
43 registeredKey['version'] != 'U2F_V2') { | 43 registeredKey['version'] != 'U2F_V2') { |
44 return false; | 44 return false; |
45 } | 45 } |
46 } | 46 } |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 /** | 50 /** |
51 * Returns whether the array of registered keys appears to be valid. | 51 * Returns whether the array of registered keys appears to be valid. |
52 * @param {Array.<Object>} registeredKeys The array of registered keys. | 52 * @param {Array<Object>} registeredKeys The array of registered keys. |
53 * @param {boolean} appIdRequired Whether the appId property is required on | 53 * @param {boolean} appIdRequired Whether the appId property is required on |
54 * each challenge. | 54 * each challenge. |
55 * @return {boolean} Whether the array appears valid. | 55 * @return {boolean} Whether the array appears valid. |
56 */ | 56 */ |
57 function isValidRegisteredKeyArray(registeredKeys, appIdRequired) { | 57 function isValidRegisteredKeyArray(registeredKeys, appIdRequired) { |
58 return registeredKeys.every(function(key) { | 58 return registeredKeys.every(function(key) { |
59 return isValidRegisteredKey(key, appIdRequired); | 59 return isValidRegisteredKey(key, appIdRequired); |
60 }); | 60 }); |
61 } | 61 } |
62 | 62 |
63 /** | 63 /** |
64 * Returns whether the array of SignChallenges appears to be valid. | 64 * Returns whether the array of SignChallenges appears to be valid. |
65 * @param {Array.<SignChallenge>} signChallenges The array of sign challenges. | 65 * @param {Array<SignChallenge>} signChallenges The array of sign challenges. |
66 * @param {boolean} challengeValueRequired Whether each challenge object | 66 * @param {boolean} challengeValueRequired Whether each challenge object |
67 * requires a challenge value. | 67 * requires a challenge value. |
68 * @param {boolean} appIdRequired Whether the appId property is required on | 68 * @param {boolean} appIdRequired Whether the appId property is required on |
69 * each challenge. | 69 * each challenge. |
70 * @return {boolean} Whether the array appears valid. | 70 * @return {boolean} Whether the array appears valid. |
71 */ | 71 */ |
72 function isValidSignChallengeArray(signChallenges, challengeValueRequired, | 72 function isValidSignChallengeArray(signChallenges, challengeValueRequired, |
73 appIdRequired) { | 73 appIdRequired) { |
74 for (var i = 0; i < signChallenges.length; i++) { | 74 for (var i = 0; i < signChallenges.length; i++) { |
75 var incomingChallenge = signChallenges[i]; | 75 var incomingChallenge = signChallenges[i]; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } catch (exception) { | 309 } catch (exception) { |
310 console.warn('sendResponse failed: ' + exception); | 310 console.warn('sendResponse failed: ' + exception); |
311 } | 311 } |
312 } else { | 312 } else { |
313 console.warn(UTIL_fmt('Tried to reply more than once! Juan, FIX ME')); | 313 console.warn(UTIL_fmt('Tried to reply more than once! Juan, FIX ME')); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 /** | 317 /** |
318 * @param {!string} string Input string | 318 * @param {!string} string Input string |
319 * @return {Array.<number>} SHA256 hash value of string. | 319 * @return {Array<number>} SHA256 hash value of string. |
320 */ | 320 */ |
321 function sha256HashOfString(string) { | 321 function sha256HashOfString(string) { |
322 var s = new SHA256(); | 322 var s = new SHA256(); |
323 s.update(UTIL_StringToBytes(string)); | 323 s.update(UTIL_StringToBytes(string)); |
324 return s.digest(); | 324 return s.digest(); |
325 } | 325 } |
326 | 326 |
327 /** | 327 /** |
328 * Normalizes the TLS channel ID value: | 328 * Normalizes the TLS channel ID value: |
329 * 1. Converts semantically empty values (undefined, null, 0) to the empty | 329 * 1. Converts semantically empty values (undefined, null, 0) to the empty |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 * @param {Object|string|undefined} opt_tlsChannelId TLS Channel Id | 402 * @param {Object|string|undefined} opt_tlsChannelId TLS Channel Id |
403 * @return {string} A string representation of the browser data object. | 403 * @return {string} A string representation of the browser data object. |
404 */ | 404 */ |
405 function makeSignBrowserData(serverChallenge, origin, opt_tlsChannelId) { | 405 function makeSignBrowserData(serverChallenge, origin, opt_tlsChannelId) { |
406 return makeBrowserData( | 406 return makeBrowserData( |
407 'navigator.id.getAssertion', serverChallenge, origin, opt_tlsChannelId); | 407 'navigator.id.getAssertion', serverChallenge, origin, opt_tlsChannelId); |
408 } | 408 } |
409 | 409 |
410 /** | 410 /** |
411 * Encodes the sign data as an array of sign helper challenges. | 411 * Encodes the sign data as an array of sign helper challenges. |
412 * @param {Array.<SignChallenge>} signChallenges The sign challenges to encode. | 412 * @param {Array<SignChallenge>} signChallenges The sign challenges to encode. |
413 * @param {string|undefined} opt_defaultChallenge A default sign challenge | 413 * @param {string|undefined} opt_defaultChallenge A default sign challenge |
414 * value, if a request does not provide one. | 414 * value, if a request does not provide one. |
415 * @param {string=} opt_defaultAppId The app id to use for each challenge, if | 415 * @param {string=} opt_defaultAppId The app id to use for each challenge, if |
416 * the challenge contains none. | 416 * the challenge contains none. |
417 * @param {function(string, string): string=} opt_challengeHashFunction | 417 * @param {function(string, string): string=} opt_challengeHashFunction |
418 * A function that produces, from a key handle and a raw challenge, a hash | 418 * A function that produces, from a key handle and a raw challenge, a hash |
419 * of the raw challenge. If none is provided, a default hash function is | 419 * of the raw challenge. If none is provided, a default hash function is |
420 * used. | 420 * used. |
421 * @return {!Array.<SignHelperChallenge>} The sign challenges, encoded. | 421 * @return {!Array<SignHelperChallenge>} The sign challenges, encoded. |
422 */ | 422 */ |
423 function encodeSignChallenges(signChallenges, opt_defaultChallenge, | 423 function encodeSignChallenges(signChallenges, opt_defaultChallenge, |
424 opt_defaultAppId, opt_challengeHashFunction) { | 424 opt_defaultAppId, opt_challengeHashFunction) { |
425 function encodedSha256(keyHandle, challenge) { | 425 function encodedSha256(keyHandle, challenge) { |
426 return B64_encode(sha256HashOfString(challenge)); | 426 return B64_encode(sha256HashOfString(challenge)); |
427 } | 427 } |
428 var challengeHashFn = opt_challengeHashFunction || encodedSha256; | 428 var challengeHashFn = opt_challengeHashFunction || encodedSha256; |
429 var encodedSignChallenges = []; | 429 var encodedSignChallenges = []; |
430 if (signChallenges) { | 430 if (signChallenges) { |
431 for (var i = 0; i < signChallenges.length; i++) { | 431 for (var i = 0; i < signChallenges.length; i++) { |
(...skipping 19 matching lines...) Expand all Loading... |
451 'version': (challenge['version'] || 'U2F_V1') | 451 'version': (challenge['version'] || 'U2F_V1') |
452 }; | 452 }; |
453 encodedSignChallenges.push(encodedChallenge); | 453 encodedSignChallenges.push(encodedChallenge); |
454 } | 454 } |
455 } | 455 } |
456 return encodedSignChallenges; | 456 return encodedSignChallenges; |
457 } | 457 } |
458 | 458 |
459 /** | 459 /** |
460 * Makes a sign helper request from an array of challenges. | 460 * Makes a sign helper request from an array of challenges. |
461 * @param {Array.<SignHelperChallenge>} challenges The sign challenges. | 461 * @param {Array<SignHelperChallenge>} challenges The sign challenges. |
462 * @param {number=} opt_timeoutSeconds Timeout value. | 462 * @param {number=} opt_timeoutSeconds Timeout value. |
463 * @param {string=} opt_logMsgUrl URL to log to. | 463 * @param {string=} opt_logMsgUrl URL to log to. |
464 * @return {SignHelperRequest} The sign helper request. | 464 * @return {SignHelperRequest} The sign helper request. |
465 */ | 465 */ |
466 function makeSignHelperRequest(challenges, opt_timeoutSeconds, opt_logMsgUrl) { | 466 function makeSignHelperRequest(challenges, opt_timeoutSeconds, opt_logMsgUrl) { |
467 var request = { | 467 var request = { |
468 'type': 'sign_helper_request', | 468 'type': 'sign_helper_request', |
469 'signData': challenges, | 469 'signData': challenges, |
470 'timeout': opt_timeoutSeconds || 0, | 470 'timeout': opt_timeoutSeconds || 0, |
471 'timeoutSeconds': opt_timeoutSeconds || 0 | 471 'timeoutSeconds': opt_timeoutSeconds || 0 |
472 }; | 472 }; |
473 if (opt_logMsgUrl !== undefined) { | 473 if (opt_logMsgUrl !== undefined) { |
474 request.logMsgUrl = opt_logMsgUrl; | 474 request.logMsgUrl = opt_logMsgUrl; |
475 } | 475 } |
476 return request; | 476 return request; |
477 } | 477 } |
OLD | NEW |