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 Implements a sign helper using USB gnubbies. | 6 * @fileoverview Implements a sign helper using USB gnubbies. |
7 */ | 7 */ |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 var CORRUPT_sign = false; | 10 var CORRUPT_sign = false; |
11 | 11 |
12 /** | 12 /** |
13 * @param {!GnubbyFactory} factory Factory for gnubby instances | 13 * @param {!GnubbyFactory} factory Factory for gnubby instances |
14 * @param {Countdown} timer Timer after whose expiration the caller is no longer | 14 * @param {Countdown} timer Timer after whose expiration the caller is no longer |
15 * interested in the result of a sign request. | 15 * interested in the result of a sign request. |
16 * @param {function(number, boolean)} errorCb Called when a sign request fails | 16 * @param {function(number, boolean)} errorCb Called when a sign request fails |
17 * with an error code and whether any gnubbies were found. | 17 * with an error code and whether any gnubbies were found. |
18 * @param {function(SignHelperChallenge, string)} successCb Called with the | 18 * @param {function(SignHelperChallenge, string, string=)} successCb Called with |
19 * signature produced by a successful sign request. | 19 * the signature produced by a successful sign request. |
20 * @param {(function(number, boolean)|undefined)} opt_progressCb Called with | |
21 * progress updates to the sign request. | |
22 * @param {string=} opt_logMsgUrl A URL to post log messages to. | 20 * @param {string=} opt_logMsgUrl A URL to post log messages to. |
23 * @constructor | 21 * @constructor |
24 * @implements {SignHelper} | 22 * @implements {SignHelper} |
25 */ | 23 */ |
26 function UsbSignHelper(factory, timer, errorCb, successCb, opt_progressCb, | 24 function UsbSignHelper(factory, timer, errorCb, successCb, opt_logMsgUrl) { |
27 opt_logMsgUrl) { | |
28 /** @private {!GnubbyFactory} */ | 25 /** @private {!GnubbyFactory} */ |
29 this.factory_ = factory; | 26 this.factory_ = factory; |
30 /** @private {Countdown} */ | 27 /** @private {Countdown} */ |
31 this.timer_ = timer; | 28 this.timer_ = timer; |
32 /** @private {function(number, boolean)} */ | 29 /** @private {function(number, boolean)} */ |
33 this.errorCb_ = errorCb; | 30 this.errorCb_ = errorCb; |
34 /** @private {function(SignHelperChallenge, string)} */ | 31 /** @private {function(SignHelperChallenge, string, string=)} */ |
35 this.successCb_ = successCb; | 32 this.successCb_ = successCb; |
36 /** @private {string|undefined} */ | 33 /** @private {string|undefined} */ |
37 this.logMsgUrl_ = opt_logMsgUrl; | 34 this.logMsgUrl_ = opt_logMsgUrl; |
38 | 35 |
39 /** @private {Array.<SignHelperChallenge>} */ | 36 /** @private {Array.<SignHelperChallenge>} */ |
40 this.pendingChallenges_ = []; | 37 this.pendingChallenges_ = []; |
41 /** @private {Array.<usbGnubby>} */ | 38 /** @private {Array.<usbGnubby>} */ |
42 this.waitingForTouchGnubbies_ = []; | 39 this.waitingForTouchGnubbies_ = []; |
43 | 40 |
44 /** @private {boolean} */ | 41 /** @private {boolean} */ |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 179 |
183 if (CORRUPT_sign) { | 180 if (CORRUPT_sign) { |
184 CORRUPT_sign = false; | 181 CORRUPT_sign = false; |
185 info[info.length - 1] = info[info.length - 1] ^ 0xff; | 182 info[info.length - 1] = info[info.length - 1] ^ 0xff; |
186 } | 183 } |
187 var encodedChallenge = {}; | 184 var encodedChallenge = {}; |
188 encodedChallenge['challengeHash'] = B64_encode(challenge['challengeHash']); | 185 encodedChallenge['challengeHash'] = B64_encode(challenge['challengeHash']); |
189 encodedChallenge['appIdHash'] = B64_encode(challenge['appIdHash']); | 186 encodedChallenge['appIdHash'] = B64_encode(challenge['appIdHash']); |
190 encodedChallenge['keyHandle'] = B64_encode(challenge['keyHandle']); | 187 encodedChallenge['keyHandle'] = B64_encode(challenge['keyHandle']); |
191 this.successCb_( | 188 this.successCb_( |
192 /** @type {SignHelperChallenge} */ (encodedChallenge), B64_encode(info)); | 189 /** @type {SignHelperChallenge} */ (encodedChallenge), B64_encode(info), |
| 190 'USB'); |
193 }; | 191 }; |
194 | 192 |
195 /** | 193 /** |
196 * Reports error to the caller. | 194 * Reports error to the caller. |
197 * @param {number} code error to report | 195 * @param {number} code error to report |
198 * @param {boolean} anyGnubbies If any gnubbies were found | 196 * @param {boolean} anyGnubbies If any gnubbies were found |
199 * @private | 197 * @private |
200 */ | 198 */ |
201 UsbSignHelper.prototype.notifyError_ = function(code, anyGnubbies) { | 199 UsbSignHelper.prototype.notifyError_ = function(code, anyGnubbies) { |
202 if (this.notified_) | 200 if (this.notified_) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 this.gnubbyFactory_ = gnubbyFactory; | 320 this.gnubbyFactory_ = gnubbyFactory; |
323 } | 321 } |
324 | 322 |
325 /** | 323 /** |
326 * @param {Countdown} timer Timer after whose expiration the caller is no longer | 324 * @param {Countdown} timer Timer after whose expiration the caller is no longer |
327 * interested in the result of a sign request. | 325 * interested in the result of a sign request. |
328 * @param {function(number, boolean)} errorCb Called when a sign request fails | 326 * @param {function(number, boolean)} errorCb Called when a sign request fails |
329 * with an error code and whether any gnubbies were found. | 327 * with an error code and whether any gnubbies were found. |
330 * @param {function(SignHelperChallenge, string)} successCb Called with the | 328 * @param {function(SignHelperChallenge, string)} successCb Called with the |
331 * signature produced by a successful sign request. | 329 * signature produced by a successful sign request. |
332 * @param {(function(number, boolean)|undefined)} opt_progressCb Called with | |
333 * progress updates to the sign request. | |
334 * @param {string=} opt_logMsgUrl A URL to post log messages to. | 330 * @param {string=} opt_logMsgUrl A URL to post log messages to. |
335 * @return {UsbSignHelper} the newly created helper. | 331 * @return {UsbSignHelper} the newly created helper. |
336 */ | 332 */ |
337 UsbSignHelperFactory.prototype.createHelper = | 333 UsbSignHelperFactory.prototype.createHelper = |
338 function(timer, errorCb, successCb, opt_progressCb, opt_logMsgUrl) { | 334 function(timer, errorCb, successCb, opt_logMsgUrl) { |
339 var helper = | 335 var helper = |
340 new UsbSignHelper(this.gnubbyFactory_, timer, errorCb, successCb, | 336 new UsbSignHelper(this.gnubbyFactory_, timer, errorCb, successCb, |
341 opt_progressCb, opt_logMsgUrl); | 337 opt_logMsgUrl); |
342 return helper; | 338 return helper; |
343 }; | 339 }; |
OLD | NEW |