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 an enroll handler using USB gnubbies. | 6 * @fileoverview Implements an enroll handler using USB gnubbies. |
7 */ | 7 */ |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 * results from more gnubbies. | 91 * results from more gnubbies. |
92 * @private | 92 * @private |
93 */ | 93 */ |
94 UsbEnrollHandler.prototype.signerFoundGnubby_ = | 94 UsbEnrollHandler.prototype.signerFoundGnubby_ = |
95 function(signResult, moreExpected) { | 95 function(signResult, moreExpected) { |
96 if (!signResult.code) { | 96 if (!signResult.code) { |
97 // If the signer reports a gnubby can sign, report this immediately to the | 97 // If the signer reports a gnubby can sign, report this immediately to the |
98 // caller, as the gnubby is already enrolled. Map ok to WRONG_DATA, so the | 98 // caller, as the gnubby is already enrolled. Map ok to WRONG_DATA, so the |
99 // caller knows what to do. | 99 // caller knows what to do. |
100 this.notifyError_(DeviceStatusCodes.WRONG_DATA_STATUS); | 100 this.notifyError_(DeviceStatusCodes.WRONG_DATA_STATUS); |
101 } else if (signResult.code == DeviceStatusCodes.WRONG_DATA_STATUS) { | 101 } else if (signResult.code == DeviceStatusCodes.WRONG_DATA_STATUS || |
| 102 signResult.code == DeviceStatusCodes.WRONG_LENGTH_STATUS) { |
102 var gnubby = signResult['gnubby']; | 103 var gnubby = signResult['gnubby']; |
103 // A valid helper request contains at least one enroll challenge, so use | 104 // A valid helper request contains at least one enroll challenge, so use |
104 // the app id hash from the first challenge. | 105 // the app id hash from the first challenge. |
105 var appIdHash = this.request_.enrollChallenges[0].appIdHash; | 106 var appIdHash = this.request_.enrollChallenges[0].appIdHash; |
106 DEVICE_FACTORY_REGISTRY.getGnubbyFactory().notEnrolledPrerequisiteCheck( | 107 DEVICE_FACTORY_REGISTRY.getGnubbyFactory().notEnrolledPrerequisiteCheck( |
107 gnubby, appIdHash, this.gnubbyPrerequisitesChecked_.bind(this)); | 108 gnubby, appIdHash, this.gnubbyPrerequisitesChecked_.bind(this)); |
108 } | 109 } |
109 }; | 110 }; |
110 | 111 |
111 /** | 112 /** |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 * @param {Gnubby} gnubby Gnubby instance | 200 * @param {Gnubby} gnubby Gnubby instance |
200 * @param {string} version Protocol version | 201 * @param {string} version Protocol version |
201 * @private | 202 * @private |
202 */ | 203 */ |
203 UsbEnrollHandler.prototype.tryEnroll_ = function(gnubby, version) { | 204 UsbEnrollHandler.prototype.tryEnroll_ = function(gnubby, version) { |
204 var challenge = this.getChallengeOfVersion_(version); | 205 var challenge = this.getChallengeOfVersion_(version); |
205 if (!challenge) { | 206 if (!challenge) { |
206 this.removeWrongVersionGnubby_(gnubby); | 207 this.removeWrongVersionGnubby_(gnubby); |
207 return; | 208 return; |
208 } | 209 } |
209 var challengeChallenge = B64_decode(challenge['challenge']); | 210 var challengeValue = B64_decode(challenge['challengeHash']); |
210 var appIdHash = B64_decode(challenge['appIdHash']); | 211 var appIdHash = challenge['appIdHash']; |
211 gnubby.enroll(challengeChallenge, appIdHash, | 212 var individualAttest = |
212 this.enrollCallback_.bind(this, gnubby, version)); | 213 DEVICE_FACTORY_REGISTRY.getIndividualAttestation(). |
| 214 requestIndividualAttestation(appIdHash); |
| 215 gnubby.enroll(challengeValue, B64_decode(appIdHash), |
| 216 this.enrollCallback_.bind(this, gnubby, version), individualAttest); |
213 }; | 217 }; |
214 | 218 |
215 /** | 219 /** |
216 * Finds the (first) challenge of the given version in this helper's challenges. | 220 * Finds the (first) challenge of the given version in this helper's challenges. |
217 * @param {string} version Protocol version | 221 * @param {string} version Protocol version |
218 * @return {Object} challenge, if found, or null if not. | 222 * @return {Object} challenge, if found, or null if not. |
219 * @private | 223 * @private |
220 */ | 224 */ |
221 UsbEnrollHandler.prototype.getChallengeOfVersion_ = function(version) { | 225 UsbEnrollHandler.prototype.getChallengeOfVersion_ = function(version) { |
222 for (var i = 0; i < this.enrollChallenges.length; i++) { | 226 for (var i = 0; i < this.enrollChallenges.length; i++) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 this.notified_ = true; | 329 this.notified_ = true; |
326 this.close(); | 330 this.close(); |
327 var reply = { | 331 var reply = { |
328 'type': 'enroll_helper_reply', | 332 'type': 'enroll_helper_reply', |
329 'code': DeviceStatusCodes.OK_STATUS, | 333 'code': DeviceStatusCodes.OK_STATUS, |
330 'version': version, | 334 'version': version, |
331 'enrollData': info | 335 'enrollData': info |
332 }; | 336 }; |
333 this.cb_(reply); | 337 this.cb_(reply); |
334 }; | 338 }; |
OLD | NEW |