| 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 Gnubby methods related to U2F support. | 6 * @fileoverview Gnubby methods related to U2F support. |
| 7 */ | 7 */ |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 // Commands and flags of the Gnubby applet | 10 // Commands and flags of the Gnubby applet |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 /** Attest with device key */ | 28 /** Attest with device key */ |
| 29 Gnubby.P1_INDIVIDUAL_KEY = 0x80; | 29 Gnubby.P1_INDIVIDUAL_KEY = 0x80; |
| 30 | 30 |
| 31 // Version values | 31 // Version values |
| 32 /** V1 of the applet. */ | 32 /** V1 of the applet. */ |
| 33 Gnubby.U2F_V1 = 'U2F_V1'; | 33 Gnubby.U2F_V1 = 'U2F_V1'; |
| 34 /** V2 of the applet. */ | 34 /** V2 of the applet. */ |
| 35 Gnubby.U2F_V2 = 'U2F_V2'; | 35 Gnubby.U2F_V2 = 'U2F_V2'; |
| 36 | 36 |
| 37 /** Perform enrollment | 37 /** Perform enrollment |
| 38 * @param {Array.<number>|ArrayBuffer|Uint8Array} challenge Enrollment challenge | 38 * @param {Array<number>|ArrayBuffer|Uint8Array} challenge Enrollment challenge |
| 39 * @param {Array.<number>|ArrayBuffer|Uint8Array} appIdHash Hashed application | 39 * @param {Array<number>|ArrayBuffer|Uint8Array} appIdHash Hashed application |
| 40 * id | 40 * id |
| 41 * @param {function(...)} cb Result callback | 41 * @param {function(...)} cb Result callback |
| 42 * @param {boolean=} opt_individualAttestation Request the individual | 42 * @param {boolean=} opt_individualAttestation Request the individual |
| 43 * attestation cert rather than the batch one. | 43 * attestation cert rather than the batch one. |
| 44 */ | 44 */ |
| 45 Gnubby.prototype.enroll = function(challenge, appIdHash, cb, | 45 Gnubby.prototype.enroll = function(challenge, appIdHash, cb, |
| 46 opt_individualAttestation) { | 46 opt_individualAttestation) { |
| 47 var p1 = Gnubby.P1_TUP_REQUIRED | Gnubby.P1_TUP_CONSUME; | 47 var p1 = Gnubby.P1_TUP_REQUIRED | Gnubby.P1_TUP_CONSUME; |
| 48 if (opt_individualAttestation) { | 48 if (opt_individualAttestation) { |
| 49 p1 |= Gnubby.P1_INDIVIDUAL_KEY; | 49 p1 |= Gnubby.P1_INDIVIDUAL_KEY; |
| 50 } | 50 } |
| 51 var apdu = new Uint8Array( | 51 var apdu = new Uint8Array( |
| 52 [0x00, | 52 [0x00, |
| 53 Gnubby.U2F_ENROLL, | 53 Gnubby.U2F_ENROLL, |
| 54 p1, | 54 p1, |
| 55 0x00, 0x00, 0x00, | 55 0x00, 0x00, 0x00, |
| 56 challenge.length + appIdHash.length]); | 56 challenge.length + appIdHash.length]); |
| 57 var u8 = new Uint8Array(apdu.length + challenge.length + | 57 var u8 = new Uint8Array(apdu.length + challenge.length + |
| 58 appIdHash.length + 2); | 58 appIdHash.length + 2); |
| 59 for (var i = 0; i < apdu.length; ++i) u8[i] = apdu[i]; | 59 for (var i = 0; i < apdu.length; ++i) u8[i] = apdu[i]; |
| 60 for (var i = 0; i < challenge.length; ++i) u8[i + apdu.length] = | 60 for (var i = 0; i < challenge.length; ++i) u8[i + apdu.length] = |
| 61 challenge[i]; | 61 challenge[i]; |
| 62 for (var i = 0; i < appIdHash.length; ++i) { | 62 for (var i = 0; i < appIdHash.length; ++i) { |
| 63 u8[i + apdu.length + challenge.length] = appIdHash[i]; | 63 u8[i + apdu.length + challenge.length] = appIdHash[i]; |
| 64 } | 64 } |
| 65 this.apduReply(u8.buffer, cb); | 65 this.apduReply(u8.buffer, cb); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 /** Request signature | 68 /** Request signature |
| 69 * @param {Array.<number>|ArrayBuffer|Uint8Array} challengeHash Hashed | 69 * @param {Array<number>|ArrayBuffer|Uint8Array} challengeHash Hashed |
| 70 * signature challenge | 70 * signature challenge |
| 71 * @param {Array.<number>|ArrayBuffer|Uint8Array} appIdHash Hashed application | 71 * @param {Array<number>|ArrayBuffer|Uint8Array} appIdHash Hashed application |
| 72 * id | 72 * id |
| 73 * @param {Array.<number>|ArrayBuffer|Uint8Array} keyHandle Key handle to use | 73 * @param {Array<number>|ArrayBuffer|Uint8Array} keyHandle Key handle to use |
| 74 * @param {function(...)} cb Result callback | 74 * @param {function(...)} cb Result callback |
| 75 * @param {boolean=} opt_nowink Request signature without winking | 75 * @param {boolean=} opt_nowink Request signature without winking |
| 76 * (e.g. during enroll) | 76 * (e.g. during enroll) |
| 77 */ | 77 */ |
| 78 Gnubby.prototype.sign = function(challengeHash, appIdHash, keyHandle, cb, | 78 Gnubby.prototype.sign = function(challengeHash, appIdHash, keyHandle, cb, |
| 79 opt_nowink) { | 79 opt_nowink) { |
| 80 var self = this; | 80 var self = this; |
| 81 // The sign command's format is ever-so-slightly different between V1 and V2, | 81 // The sign command's format is ever-so-slightly different between V1 and V2, |
| 82 // so get this gnubby's version prior to sending it. | 82 // so get this gnubby's version prior to sending it. |
| 83 this.version(function(rc, opt_data) { | 83 this.version(function(rc, opt_data) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 self.version_ = v1.buffer; | 143 self.version_ = v1.buffer; |
| 144 cb(-GnubbyDevice.OK, v1.buffer); | 144 cb(-GnubbyDevice.OK, v1.buffer); |
| 145 } else { | 145 } else { |
| 146 if (!rc) { | 146 if (!rc) { |
| 147 self.version_ = data; | 147 self.version_ = data; |
| 148 } | 148 } |
| 149 cb(rc, data); | 149 cb(rc, data); |
| 150 } | 150 } |
| 151 }); | 151 }); |
| 152 }; | 152 }; |
| OLD | NEW |