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'; |
11 | 11 |
12 var signRequestQueue = new OriginKeyedRequestQueue(); | 12 var signRequestQueue = new OriginKeyedRequestQueue(); |
13 | 13 |
14 /** | 14 /** |
15 * Handles a web sign request. | 15 * Handles a web sign request. |
16 * @param {MessageSender} sender The sender of the message. | 16 * @param {MessageSender} sender The sender of the message. |
17 * @param {Object} request The web page's sign request. | 17 * @param {Object} request The web page's sign request. |
18 * @param {Function} sendResponse Called back with the result of the sign. | 18 * @param {Function} sendResponse Called back with the result of the sign. |
19 * @return {Closeable} Request handler that should be closed when the browser | 19 * @return {Closeable} Request handler that should be closed when the browser |
20 * message channel is closed. | 20 * message channel is closed. |
21 */ | 21 */ |
22 function handleWebSignRequest(sender, request, sendResponse) { | 22 function handleWebSignRequest(sender, request, sendResponse) { |
23 var sentResponse = false; | 23 var sentResponse = false; |
24 var queuedSignRequest; | 24 var queuedSignRequest; |
25 | 25 |
26 function sendErrorResponse(u2fCode) { | 26 function sendErrorResponse(error) { |
27 sendResponseOnce(sentResponse, queuedSignRequest, | 27 sendResponseOnce(sentResponse, queuedSignRequest, |
28 makeWebErrorResponse(request, | 28 makeWebErrorResponse(request, |
29 mapErrorCodeToGnubbyCodeType(u2fCode, true /* forSign */)), | 29 mapErrorCodeToGnubbyCodeType(error.errorCode, true /* forSign */)), |
30 sendResponse); | 30 sendResponse); |
31 } | 31 } |
32 | 32 |
33 function sendSuccessResponse(challenge, info, browserData) { | 33 function sendSuccessResponse(challenge, info, browserData) { |
34 var responseData = makeWebSignResponseDataFromChallenge(challenge); | 34 var responseData = makeWebSignResponseDataFromChallenge(challenge); |
35 addSignatureAndBrowserDataToResponseData(responseData, info, browserData, | 35 addSignatureAndBrowserDataToResponseData(responseData, info, browserData, |
36 'browserData'); | 36 'browserData'); |
37 var response = makeWebSuccessResponse(request, responseData); | 37 var response = makeWebSuccessResponse(request, responseData); |
38 sendResponseOnce(sentResponse, queuedSignRequest, response, sendResponse); | 38 sendResponseOnce(sentResponse, queuedSignRequest, response, sendResponse); |
39 } | 39 } |
(...skipping 10 matching lines...) Expand all Loading... |
50 * @param {MessageSender} sender The sender of the message. | 50 * @param {MessageSender} sender The sender of the message. |
51 * @param {Object} request The web page's sign request. | 51 * @param {Object} request The web page's sign request. |
52 * @param {Function} sendResponse Called back with the result of the sign. | 52 * @param {Function} sendResponse Called back with the result of the sign. |
53 * @return {Closeable} Request handler that should be closed when the browser | 53 * @return {Closeable} Request handler that should be closed when the browser |
54 * message channel is closed. | 54 * message channel is closed. |
55 */ | 55 */ |
56 function handleU2fSignRequest(sender, request, sendResponse) { | 56 function handleU2fSignRequest(sender, request, sendResponse) { |
57 var sentResponse = false; | 57 var sentResponse = false; |
58 var queuedSignRequest; | 58 var queuedSignRequest; |
59 | 59 |
60 function sendErrorResponse(u2fCode) { | 60 function sendErrorResponse(error) { |
61 sendResponseOnce(sentResponse, queuedSignRequest, | 61 sendResponseOnce(sentResponse, queuedSignRequest, |
62 makeU2fErrorResponse(request, u2fCode), sendResponse); | 62 makeU2fErrorResponse(request, error.errorCode, error.errorMessage), |
| 63 sendResponse); |
63 } | 64 } |
64 | 65 |
65 function sendSuccessResponse(challenge, info, browserData) { | 66 function sendSuccessResponse(challenge, info, browserData) { |
66 var responseData = makeU2fSignResponseDataFromChallenge(challenge); | 67 var responseData = makeU2fSignResponseDataFromChallenge(challenge); |
67 addSignatureAndBrowserDataToResponseData(responseData, info, browserData, | 68 addSignatureAndBrowserDataToResponseData(responseData, info, browserData, |
68 'clientData'); | 69 'clientData'); |
69 var response = makeU2fSuccessResponse(request, responseData); | 70 var response = makeU2fSuccessResponse(request, responseData); |
70 sendResponseOnce(sentResponse, queuedSignRequest, response, sendResponse); | 71 sendResponseOnce(sentResponse, queuedSignRequest, response, sendResponse); |
71 } | 72 } |
72 | 73 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 responseData['signatureData'] = signatureData; | 117 responseData['signatureData'] = signatureData; |
117 } | 118 } |
118 | 119 |
119 /** | 120 /** |
120 * Validates a sign request using the given sign challenges name, and, if valid, | 121 * Validates a sign request using the given sign challenges name, and, if valid, |
121 * enqueues the sign request for eventual processing. | 122 * enqueues the sign request for eventual processing. |
122 * @param {MessageSender} sender The sender of the message. | 123 * @param {MessageSender} sender The sender of the message. |
123 * @param {Object} request The web page's sign request. | 124 * @param {Object} request The web page's sign request. |
124 * @param {string} signChallengesName The name of the sign challenges value in | 125 * @param {string} signChallengesName The name of the sign challenges value in |
125 * the request. | 126 * the request. |
126 * @param {function(ErrorCodes)} errorCb Error callback. | 127 * @param {function(U2fError)} errorCb Error callback. |
127 * @param {function(SignChallenge, string, string)} successCb Success callback. | 128 * @param {function(SignChallenge, string, string)} successCb Success callback. |
128 * @return {Closeable} Request handler that should be closed when the browser | 129 * @return {Closeable} Request handler that should be closed when the browser |
129 * message channel is closed. | 130 * message channel is closed. |
130 */ | 131 */ |
131 function validateAndEnqueueSignRequest(sender, request, | 132 function validateAndEnqueueSignRequest(sender, request, |
132 signChallengesName, errorCb, successCb) { | 133 signChallengesName, errorCb, successCb) { |
133 var origin = getOriginFromUrl(/** @type {string} */ (sender.url)); | 134 var origin = getOriginFromUrl(/** @type {string} */ (sender.url)); |
134 if (!origin) { | 135 if (!origin) { |
135 errorCb(ErrorCodes.BAD_REQUEST); | 136 errorCb({errorCode: ErrorCodes.BAD_REQUEST}); |
136 return null; | 137 return null; |
137 } | 138 } |
138 // More closure type inference fail. | 139 // More closure type inference fail. |
139 var nonNullOrigin = /** @type {string} */ (origin); | 140 var nonNullOrigin = /** @type {string} */ (origin); |
140 | 141 |
141 if (!isValidSignRequest(request, signChallengesName)) { | 142 if (!isValidSignRequest(request, signChallengesName)) { |
142 errorCb(ErrorCodes.BAD_REQUEST); | 143 errorCb({errorCode: ErrorCodes.BAD_REQUEST}); |
143 return null; | 144 return null; |
144 } | 145 } |
145 | 146 |
146 var signChallenges = request[signChallengesName]; | 147 var signChallenges = request[signChallengesName]; |
147 var appId; | 148 var appId; |
148 if (request['appId']) { | 149 if (request['appId']) { |
149 appId = request['appId']; | 150 appId = request['appId']; |
150 } else { | 151 } else { |
151 // A valid sign data has at least one challenge, so get the appId from | 152 // A valid sign data has at least one challenge, so get the appId from |
152 // the first challenge. | 153 // the first challenge. |
153 appId = signChallenges[0]['appId']; | 154 appId = signChallenges[0]['appId']; |
154 } | 155 } |
155 // Sanity check | 156 // Sanity check |
156 if (!appId) { | 157 if (!appId) { |
157 console.warn(UTIL_fmt('empty sign appId?')); | 158 console.warn(UTIL_fmt('empty sign appId?')); |
158 errorCb(ErrorCodes.BAD_REQUEST); | 159 errorCb({errorCode: ErrorCodes.BAD_REQUEST}); |
159 return null; | 160 return null; |
160 } | 161 } |
161 var timer = createTimerForRequest( | 162 var timer = createTimerForRequest( |
162 FACTORY_REGISTRY.getCountdownFactory(), request); | 163 FACTORY_REGISTRY.getCountdownFactory(), request); |
163 var logMsgUrl = request['logMsgUrl']; | 164 var logMsgUrl = request['logMsgUrl']; |
164 | 165 |
165 // Queue sign requests from the same origin, to protect against simultaneous | 166 // Queue sign requests from the same origin, to protect against simultaneous |
166 // sign-out on many tabs resulting in repeated sign-in requests. | 167 // sign-out on many tabs resulting in repeated sign-in requests. |
167 var queuedSignRequest = new QueuedSignRequest(signChallenges, | 168 var queuedSignRequest = new QueuedSignRequest(signChallenges, |
168 timer, nonNullOrigin, errorCb, successCb, appId, sender.tlsChannelId, | 169 timer, nonNullOrigin, errorCb, successCb, appId, sender.tlsChannelId, |
(...skipping 21 matching lines...) Expand all Loading... |
190 return false; | 191 return false; |
191 var hasAppId = request.hasOwnProperty('appId'); | 192 var hasAppId = request.hasOwnProperty('appId'); |
192 return isValidSignChallengeArray(signChallenges, !hasAppId); | 193 return isValidSignChallengeArray(signChallenges, !hasAppId); |
193 } | 194 } |
194 | 195 |
195 /** | 196 /** |
196 * Adapter class representing a queued sign request. | 197 * Adapter class representing a queued sign request. |
197 * @param {!Array.<SignChallenge>} signChallenges The sign challenges. | 198 * @param {!Array.<SignChallenge>} signChallenges The sign challenges. |
198 * @param {Countdown} timer Timeout timer | 199 * @param {Countdown} timer Timeout timer |
199 * @param {string} origin Signature origin | 200 * @param {string} origin Signature origin |
200 * @param {function(ErrorCodes)} errorCb Error callback | 201 * @param {function(U2fError)} errorCb Error callback |
201 * @param {function(SignChallenge, string, string)} successCb Success callback | 202 * @param {function(SignChallenge, string, string)} successCb Success callback |
202 * @param {string|undefined} opt_appId The app id for the entire request. | 203 * @param {string|undefined} opt_appId The app id for the entire request. |
203 * @param {string|undefined} opt_tlsChannelId TLS Channel Id | 204 * @param {string|undefined} opt_tlsChannelId TLS Channel Id |
204 * @param {string|undefined} opt_logMsgUrl Url to post log messages to | 205 * @param {string|undefined} opt_logMsgUrl Url to post log messages to |
205 * @constructor | 206 * @constructor |
206 * @implements {Closeable} | 207 * @implements {Closeable} |
207 */ | 208 */ |
208 function QueuedSignRequest(signChallenges, timer, origin, errorCb, | 209 function QueuedSignRequest(signChallenges, timer, origin, errorCb, |
209 successCb, opt_appId, opt_tlsChannelId, opt_logMsgUrl) { | 210 successCb, opt_appId, opt_tlsChannelId, opt_logMsgUrl) { |
210 /** @private {!Array.<SignChallenge>} */ | 211 /** @private {!Array.<SignChallenge>} */ |
211 this.signChallenges_ = signChallenges; | 212 this.signChallenges_ = signChallenges; |
212 /** @private {Countdown} */ | 213 /** @private {Countdown} */ |
213 this.timer_ = timer; | 214 this.timer_ = timer; |
214 /** @private {string} */ | 215 /** @private {string} */ |
215 this.origin_ = origin; | 216 this.origin_ = origin; |
216 /** @private {function(ErrorCodes)} */ | 217 /** @private {function(U2fError)} */ |
217 this.errorCb_ = errorCb; | 218 this.errorCb_ = errorCb; |
218 /** @private {function(SignChallenge, string, string)} */ | 219 /** @private {function(SignChallenge, string, string)} */ |
219 this.successCb_ = successCb; | 220 this.successCb_ = successCb; |
220 /** @private {string|undefined} */ | 221 /** @private {string|undefined} */ |
221 this.appId_ = opt_appId; | 222 this.appId_ = opt_appId; |
222 /** @private {string|undefined} */ | 223 /** @private {string|undefined} */ |
223 this.tlsChannelId_ = opt_tlsChannelId; | 224 this.tlsChannelId_ = opt_tlsChannelId; |
224 /** @private {string|undefined} */ | 225 /** @private {string|undefined} */ |
225 this.logMsgUrl_ = opt_logMsgUrl; | 226 this.logMsgUrl_ = opt_logMsgUrl; |
226 /** @private {boolean} */ | 227 /** @private {boolean} */ |
(...skipping 27 matching lines...) Expand all Loading... |
254 * @param {QueuedRequestToken} token Token for this sign request. | 255 * @param {QueuedRequestToken} token Token for this sign request. |
255 */ | 256 */ |
256 QueuedSignRequest.prototype.begin = function(token) { | 257 QueuedSignRequest.prototype.begin = function(token) { |
257 this.begun_ = true; | 258 this.begun_ = true; |
258 this.setToken(token); | 259 this.setToken(token); |
259 this.signer_ = new Signer(this.timer_, this.origin_, | 260 this.signer_ = new Signer(this.timer_, this.origin_, |
260 this.signerFailed_.bind(this), this.signerSucceeded_.bind(this), | 261 this.signerFailed_.bind(this), this.signerSucceeded_.bind(this), |
261 this.tlsChannelId_, this.logMsgUrl_); | 262 this.tlsChannelId_, this.logMsgUrl_); |
262 if (!this.signer_.setChallenges(this.signChallenges_, this.appId_)) { | 263 if (!this.signer_.setChallenges(this.signChallenges_, this.appId_)) { |
263 token.complete(); | 264 token.complete(); |
264 this.errorCb_(ErrorCodes.BAD_REQUEST); | 265 this.errorCb_({errorCode: ErrorCodes.BAD_REQUEST}); |
265 } | 266 } |
266 }; | 267 }; |
267 | 268 |
268 /** | 269 /** |
269 * Called when this request's signer fails. | 270 * Called when this request's signer fails. |
270 * @param {ErrorCodes} code The failure code reported by the signer. | 271 * @param {U2fError} error The failure reported by the signer. |
271 * @private | 272 * @private |
272 */ | 273 */ |
273 QueuedSignRequest.prototype.signerFailed_ = function(code) { | 274 QueuedSignRequest.prototype.signerFailed_ = function(error) { |
274 this.token_.complete(); | 275 this.token_.complete(); |
275 this.errorCb_(code); | 276 this.errorCb_(error); |
276 }; | 277 }; |
277 | 278 |
278 /** | 279 /** |
279 * Called when this request's signer succeeds. | 280 * Called when this request's signer succeeds. |
280 * @param {SignChallenge} challenge The challenge that was signed. | 281 * @param {SignChallenge} challenge The challenge that was signed. |
281 * @param {string} info The sign result. | 282 * @param {string} info The sign result. |
282 * @param {string} browserData Browser data JSON | 283 * @param {string} browserData Browser data JSON |
283 * @private | 284 * @private |
284 */ | 285 */ |
285 QueuedSignRequest.prototype.signerSucceeded_ = | 286 QueuedSignRequest.prototype.signerSucceeded_ = |
286 function(challenge, info, browserData) { | 287 function(challenge, info, browserData) { |
287 this.token_.complete(); | 288 this.token_.complete(); |
288 this.successCb_(challenge, info, browserData); | 289 this.successCb_(challenge, info, browserData); |
289 }; | 290 }; |
290 | 291 |
291 /** | 292 /** |
292 * Creates an object to track signing with a gnubby. | 293 * Creates an object to track signing with a gnubby. |
293 * @param {Countdown} timer Timer for sign request. | 294 * @param {Countdown} timer Timer for sign request. |
294 * @param {string} origin The origin making the request. | 295 * @param {string} origin The origin making the request. |
295 * @param {function(ErrorCodes)} errorCb Called when the sign operation fails. | 296 * @param {function(U2fError)} errorCb Called when the sign operation fails. |
296 * @param {function(SignChallenge, string, string)} successCb Called when the | 297 * @param {function(SignChallenge, string, string)} successCb Called when the |
297 * sign operation succeeds. | 298 * sign operation succeeds. |
298 * @param {string=} opt_tlsChannelId the TLS channel ID, if any, of the origin | 299 * @param {string=} opt_tlsChannelId the TLS channel ID, if any, of the origin |
299 * making the request. | 300 * making the request. |
300 * @param {string=} opt_logMsgUrl The url to post log messages to. | 301 * @param {string=} opt_logMsgUrl The url to post log messages to. |
301 * @constructor | 302 * @constructor |
302 */ | 303 */ |
303 function Signer(timer, origin, errorCb, successCb, | 304 function Signer(timer, origin, errorCb, successCb, |
304 opt_tlsChannelId, opt_logMsgUrl) { | 305 opt_tlsChannelId, opt_logMsgUrl) { |
305 /** @private {Countdown} */ | 306 /** @private {Countdown} */ |
306 this.timer_ = timer; | 307 this.timer_ = timer; |
307 /** @private {string} */ | 308 /** @private {string} */ |
308 this.origin_ = origin; | 309 this.origin_ = origin; |
309 /** @private {function(ErrorCodes)} */ | 310 /** @private {function(U2fError)} */ |
310 this.errorCb_ = errorCb; | 311 this.errorCb_ = errorCb; |
311 /** @private {function(SignChallenge, string, string)} */ | 312 /** @private {function(SignChallenge, string, string)} */ |
312 this.successCb_ = successCb; | 313 this.successCb_ = successCb; |
313 /** @private {string|undefined} */ | 314 /** @private {string|undefined} */ |
314 this.tlsChannelId_ = opt_tlsChannelId; | 315 this.tlsChannelId_ = opt_tlsChannelId; |
315 /** @private {string|undefined} */ | 316 /** @private {string|undefined} */ |
316 this.logMsgUrl_ = opt_logMsgUrl; | 317 this.logMsgUrl_ = opt_logMsgUrl; |
317 | 318 |
318 /** @private {boolean} */ | 319 /** @private {boolean} */ |
319 this.challengesSet_ = false; | 320 this.challengesSet_ = false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 /** | 356 /** |
356 * Checks the app ids of incoming requests. | 357 * Checks the app ids of incoming requests. |
357 * @private | 358 * @private |
358 */ | 359 */ |
359 Signer.prototype.checkAppIds_ = function() { | 360 Signer.prototype.checkAppIds_ = function() { |
360 var appIds = getDistinctAppIds(this.signChallenges_); | 361 var appIds = getDistinctAppIds(this.signChallenges_); |
361 if (this.appId_) { | 362 if (this.appId_) { |
362 appIds = UTIL_unionArrays([this.appId_], appIds); | 363 appIds = UTIL_unionArrays([this.appId_], appIds); |
363 } | 364 } |
364 if (!appIds || !appIds.length) { | 365 if (!appIds || !appIds.length) { |
365 this.notifyError_(ErrorCodes.BAD_REQUEST); | 366 var error = { |
| 367 errorCode: ErrorCodes.BAD_REQUEST, |
| 368 errorMessage: 'missing appId' |
| 369 }; |
| 370 this.notifyError_(error); |
366 return; | 371 return; |
367 } | 372 } |
368 FACTORY_REGISTRY.getOriginChecker().canClaimAppIds(this.origin_, appIds) | 373 FACTORY_REGISTRY.getOriginChecker().canClaimAppIds(this.origin_, appIds) |
369 .then(this.originChecked_.bind(this, appIds)); | 374 .then(this.originChecked_.bind(this, appIds)); |
370 }; | 375 }; |
371 | 376 |
372 /** | 377 /** |
373 * Called with the result of checking the origin. When the origin is allowed | 378 * Called with the result of checking the origin. When the origin is allowed |
374 * to claim the app ids, begins checking whether the app ids also list the | 379 * to claim the app ids, begins checking whether the app ids also list the |
375 * origin. | 380 * origin. |
376 * @param {!Array.<string>} appIds The app ids. | 381 * @param {!Array.<string>} appIds The app ids. |
377 * @param {boolean} result Whether the origin could claim the app ids. | 382 * @param {boolean} result Whether the origin could claim the app ids. |
378 * @private | 383 * @private |
379 */ | 384 */ |
380 Signer.prototype.originChecked_ = function(appIds, result) { | 385 Signer.prototype.originChecked_ = function(appIds, result) { |
381 if (!result) { | 386 if (!result) { |
382 this.notifyError_(ErrorCodes.BAD_REQUEST); | 387 var error = { |
| 388 errorCode: ErrorCodes.BAD_REQUEST, |
| 389 errorMessage: 'bad appId' |
| 390 }; |
| 391 this.notifyError_(error); |
383 return; | 392 return; |
384 } | 393 } |
385 /** @private {!AppIdChecker} */ | 394 /** @private {!AppIdChecker} */ |
386 this.appIdChecker_ = new AppIdChecker(FACTORY_REGISTRY.getTextFetcher(), | 395 this.appIdChecker_ = new AppIdChecker(FACTORY_REGISTRY.getTextFetcher(), |
387 this.timer_.clone(), this.origin_, | 396 this.timer_.clone(), this.origin_, |
388 /** @type {!Array.<string>} */ (appIds), this.allowHttp_, | 397 /** @type {!Array.<string>} */ (appIds), this.allowHttp_, |
389 this.logMsgUrl_); | 398 this.logMsgUrl_); |
390 this.appIdChecker_.doCheck().then(this.appIdChecked_.bind(this)); | 399 this.appIdChecker_.doCheck().then(this.appIdChecked_.bind(this)); |
391 }; | 400 }; |
392 | 401 |
393 /** | 402 /** |
394 * Called with the result of checking app ids. When the app ids are valid, | 403 * Called with the result of checking app ids. When the app ids are valid, |
395 * adds the sign challenges to those being signed. | 404 * adds the sign challenges to those being signed. |
396 * @param {boolean} result Whether the app ids are valid. | 405 * @param {boolean} result Whether the app ids are valid. |
397 * @private | 406 * @private |
398 */ | 407 */ |
399 Signer.prototype.appIdChecked_ = function(result) { | 408 Signer.prototype.appIdChecked_ = function(result) { |
400 if (!result) { | 409 if (!result) { |
401 this.notifyError_(ErrorCodes.BAD_REQUEST); | 410 var error = { |
| 411 errorCode: ErrorCodes.BAD_REQUEST, |
| 412 errorMessage: 'bad appId' |
| 413 }; |
| 414 this.notifyError_(error); |
402 return; | 415 return; |
403 } | 416 } |
404 if (!this.doSign_()) { | 417 if (!this.doSign_()) { |
405 this.notifyError_(ErrorCodes.BAD_REQUEST); | 418 this.notifyError_({errorCode: ErrorCodes.BAD_REQUEST}); |
406 return; | 419 return; |
407 } | 420 } |
408 }; | 421 }; |
409 | 422 |
410 /** | 423 /** |
411 * Begins signing this signer's challenges. | 424 * Begins signing this signer's challenges. |
412 * @return {boolean} Whether the challenge could be added. | 425 * @return {boolean} Whether the challenge could be added. |
413 * @private | 426 * @private |
414 */ | 427 */ |
415 Signer.prototype.doSign_ = function() { | 428 Signer.prototype.doSign_ = function() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 this.appIdChecker_.close(); | 469 this.appIdChecker_.close(); |
457 } | 470 } |
458 if (this.handler_) { | 471 if (this.handler_) { |
459 this.handler_.close(); | 472 this.handler_.close(); |
460 this.handler_ = null; | 473 this.handler_ = null; |
461 } | 474 } |
462 this.timer_.clearTimeout(); | 475 this.timer_.clearTimeout(); |
463 }; | 476 }; |
464 | 477 |
465 /** | 478 /** |
466 * Notifies the caller of error with the given error code. | 479 * Notifies the caller of error. |
467 * @param {ErrorCodes} code Error code | 480 * @param {U2fError} error Error. |
468 * @private | 481 * @private |
469 */ | 482 */ |
470 Signer.prototype.notifyError_ = function(code) { | 483 Signer.prototype.notifyError_ = function(error) { |
471 if (this.done_) | 484 if (this.done_) |
472 return; | 485 return; |
473 this.close(); | 486 this.close(); |
474 this.done_ = true; | 487 this.done_ = true; |
475 this.errorCb_(code); | 488 this.errorCb_(error); |
476 }; | 489 }; |
477 | 490 |
478 /** | 491 /** |
479 * Notifies the caller of success. | 492 * Notifies the caller of success. |
480 * @param {SignChallenge} challenge The challenge that was signed. | 493 * @param {SignChallenge} challenge The challenge that was signed. |
481 * @param {string} info The sign result. | 494 * @param {string} info The sign result. |
482 * @param {string} browserData Browser data JSON | 495 * @param {string} browserData Browser data JSON |
483 * @private | 496 * @private |
484 */ | 497 */ |
485 Signer.prototype.notifySuccess_ = function(challenge, info, browserData) { | 498 Signer.prototype.notifySuccess_ = function(challenge, info, browserData) { |
486 if (this.done_) | 499 if (this.done_) |
487 return; | 500 return; |
488 this.close(); | 501 this.close(); |
489 this.done_ = true; | 502 this.done_ = true; |
490 this.successCb_(challenge, info, browserData); | 503 this.successCb_(challenge, info, browserData); |
491 }; | 504 }; |
492 | 505 |
493 /** | 506 /** |
494 * Called by the helper upon completion. | 507 * Called by the helper upon completion. |
495 * @param {HelperReply} helperReply The result of the sign request. | 508 * @param {HelperReply} helperReply The result of the sign request. |
496 * @param {string=} opt_source The source of the sign result. | 509 * @param {string=} opt_source The source of the sign result. |
497 * @private | 510 * @private |
498 */ | 511 */ |
499 Signer.prototype.helperComplete_ = function(helperReply, opt_source) { | 512 Signer.prototype.helperComplete_ = function(helperReply, opt_source) { |
500 if (helperReply.type != 'sign_helper_reply') { | 513 if (helperReply.type != 'sign_helper_reply') { |
501 this.notifyError_(ErrorCodes.OTHER_ERROR); | 514 this.notifyError_({errorCode: ErrorCodes.OTHER_ERROR}); |
502 return; | 515 return; |
503 } | 516 } |
504 var reply = /** @type {SignHelperReply} */ (helperReply); | 517 var reply = /** @type {SignHelperReply} */ (helperReply); |
505 | 518 |
506 if (reply.code) { | 519 if (reply.code) { |
507 var reportedError = mapDeviceStatusCodeToErrorCode(reply.code); | 520 var reportedError = mapDeviceStatusCodeToU2fError(reply.code); |
508 console.log(UTIL_fmt('helper reported ' + reply.code.toString(16) + | 521 console.log(UTIL_fmt('helper reported ' + reply.code.toString(16) + |
509 ', returning ' + reportedError)); | 522 ', returning ' + reportedError.errorCode)); |
510 this.notifyError_(reportedError); | 523 this.notifyError_(reportedError); |
511 } else { | 524 } else { |
512 if (this.logMsgUrl_ && opt_source) { | 525 if (this.logMsgUrl_ && opt_source) { |
513 var logMsg = 'signed&source=' + opt_source; | 526 var logMsg = 'signed&source=' + opt_source; |
514 logMessage(logMsg, this.logMsgUrl_); | 527 logMessage(logMsg, this.logMsgUrl_); |
515 } | 528 } |
516 | 529 |
517 var key = reply.responseData['keyHandle']; | 530 var key = reply.responseData['keyHandle']; |
518 var browserData = this.browserData_[key]; | 531 var browserData = this.browserData_[key]; |
519 // Notify with server-provided challenge, not the encoded one: the | 532 // Notify with server-provided challenge, not the encoded one: the |
520 // server-provided challenge contains additional fields it relies on. | 533 // server-provided challenge contains additional fields it relies on. |
521 var serverChallenge = this.serverChallenges_[key]; | 534 var serverChallenge = this.serverChallenges_[key]; |
522 this.notifySuccess_(serverChallenge, reply.responseData.signatureData, | 535 this.notifySuccess_(serverChallenge, reply.responseData.signatureData, |
523 browserData); | 536 browserData); |
524 } | 537 } |
525 }; | 538 }; |
OLD | NEW |