Skip to content

Commit

Permalink
allow non-wrap responses from hw-transport-u2f
Browse files Browse the repository at this point in the history
  • Loading branch information
flocks committed Oct 26, 2018
1 parent 6bc9104 commit 81821cc
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/hw-transport-u2f/src/TransportU2F.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function attemptExchange(
apdu: Buffer,
timeoutMillis: number,
debug: *,
scrambleKey: Buffer
scrambleKey: Buffer,
unwrap: boolean
): Promise<Buffer> {
const keyHandle = wrapApdu(apdu, scrambleKey);
const challenge = Buffer.from(
Expand All @@ -54,7 +55,12 @@ function attemptExchange(
const { signatureData } = response;
if (typeof signatureData === "string") {
const data = Buffer.from(normal64(signatureData), "base64");
const result = data.slice(5);
let result;
if (!unwrap) {
result = data;
} else {
result = data.slice(5);
}
if (debug) {
debug("<= " + result.toString("hex"));
}
Expand Down Expand Up @@ -117,6 +123,8 @@ export default class TransportU2F extends Transport<null> {

scrambleKey: Buffer;

unwrap: boolean = true;

/**
* static function to create a new Transport from a connected Ledger device discoverable via U2F (browser support)
*/
Expand Down Expand Up @@ -165,7 +173,8 @@ export default class TransportU2F extends Transport<null> {
apdu,
this.exchangeTimeout,
this.debug,
this.scrambleKey
this.scrambleKey,
this.unwrap
);
} catch (e) {
const isU2FError = typeof e.metaData === "object";
Expand All @@ -189,6 +198,10 @@ export default class TransportU2F extends Transport<null> {
this.scrambleKey = Buffer.from(scrambleKey, "ascii");
}

setUnwrap(unwrap: boolean) {
this.unwrap = unwrap;
}

close(): Promise<void> {
const i = transportInstances.indexOf(this);
if (i === -1) {
Expand Down

0 comments on commit 81821cc

Please sign in to comment.