Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2135 from kvhnuke/devop/update-u2f-api
Browse files Browse the repository at this point in the history
devop/update-u2f-api
  • Loading branch information
gamalielhere authored Nov 2, 2018
2 parents a6190b9 + 816d615 commit dcc38ac
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 1,054 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### New

- Add ZTX token [#2136](https://github.com/kvhnuke/etherwallet/pull/2136)

### Devop

- Update u2f-api [#2135](https://github.com/kvhnuke/etherwallet/pull/2135)

### Release v3.24.0

### New
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/signMsgCtrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
const u2f = require('u2f-api');
var signMsgCtrl = function($scope, $sce, walletService) {
walletService.wallet = null;
$scope.visibility = "signView";
Expand Down
417 changes: 245 additions & 172 deletions app/scripts/main.js

Large diffs are not rendered by default.

93 changes: 54 additions & 39 deletions app/scripts/staticJS/digitalBitboxUsb.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,69 @@
/**
* (c) 2017 Douglas Bakkum, Shift Devices AG
* (c) 2017 Douglas Bakkum, Shift Devices AG
* MIT license
**/

'use strict';
**/

"use strict";
const u2f = require("u2f-api");
var DigitalBitboxUsb = function(timeoutSeconds) {
this.timeoutSeconds = timeoutSeconds;
}
this.timeoutSeconds = timeoutSeconds;
};

// Convert from normal to web-safe, strip trailing "="s
DigitalBitboxUsb.webSafe64 = function(base64) {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
return base64
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
};

// Convert from web-safe to normal, add trailing "="s
DigitalBitboxUsb.normal64 = function(base64) {
return base64.replace(/\-/g, '+').replace(/_/g, '/') + '=='.substring(0, (3*base64.length)%4);
}
return (
base64.replace(/\-/g, "+").replace(/_/g, "/") +
"==".substring(0, (3 * base64.length) % 4)
);
};

DigitalBitboxUsb.prototype.u2fCallback = function(response, callback) {
if ('signatureData' in response) {
var data = new Buffer((DigitalBitboxUsb.normal64(response.signatureData)), 'base64');
if (data.length > 7)
callback(data.slice(5));
else
return;// Empty frame received, wait for data
}
else {
callback(undefined, response);
}
}
if ("signatureData" in response) {
var data = new Buffer(
DigitalBitboxUsb.normal64(response.signatureData),
"base64"
);
if (data.length > 7) callback(data.slice(5));
else return; // Empty frame received, wait for data
} else {
callback(undefined, response);
}
};

DigitalBitboxUsb.prototype.exchange = function(msg, callback) {
msg = Buffer.from(msg, 'ascii');
var kh_max_len = 128 - 2;// Subtract 2 bytes for `index` and `total` header
var challenge = new Buffer("dbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdb", 'hex');
var total = Math.ceil(msg.length / kh_max_len);
var self = this;
var localCallback = function(result) {
self.u2fCallback(result, callback);
}
for (var index = 0; index < total; index++) {
var kh = Buffer.concat([Buffer.from([total]), Buffer.from([index]), msg.slice(index * kh_max_len, (index + 1) * kh_max_len)]);
var key = {
version: 'U2F_V2',
keyHandle: DigitalBitboxUsb.webSafe64(kh.toString('base64')),
};
u2f.sign(location.origin, DigitalBitboxUsb.webSafe64(challenge.toString('base64')), [key], localCallback, this.timeoutSeconds);
}
}
msg = Buffer.from(msg, "ascii");
var kh_max_len = 128 - 2; // Subtract 2 bytes for `index` and `total` header
var challenge = new Buffer(
"dbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdb",
"hex"
);
var total = Math.ceil(msg.length / kh_max_len);
var self = this;
var localCallback = function(result) {
self.u2fCallback(result, callback);
};
for (var index = 0; index < total; index++) {
var kh = Buffer.concat([
Buffer.from([total]),
Buffer.from([index]),
msg.slice(index * kh_max_len, (index + 1) * kh_max_len)
]);
var key = {
appId: location.origin,
challenge: DigitalBitboxUsb.webSafe64(challenge.toString("base64")),
version: "U2F_V2",
keyHandle: DigitalBitboxUsb.webSafe64(kh.toString("base64"))
};
u2f.sign([key], this.timeoutSeconds).then(localCallback);
}
};

module.exports = DigitalBitboxUsb
module.exports = DigitalBitboxUsb;
115 changes: 64 additions & 51 deletions app/scripts/staticJS/ledger3.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,81 @@
/********************************************************************************
* Ledger Communication toolkit
* (c) 2016 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

'use strict';
* Ledger Communication toolkit
* (c) 2016 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

"use strict";
const u2f = require("u2f-api");
var Ledger3 = function(scrambleKey, timeoutSeconds) {
this.scrambleKey = new Buffer(scrambleKey, 'ascii');
this.timeoutSeconds = timeoutSeconds;
}
this.scrambleKey = new Buffer(scrambleKey, "ascii");
this.timeoutSeconds = timeoutSeconds;
};

Ledger3.wrapApdu = function(apdu, key) {
var result = new Buffer(apdu.length);
for (var i=0; i<apdu.length; i++) {
result[i] = apdu[i] ^ key[i % key.length];
}
return result;
}
var result = new Buffer(apdu.length);
for (var i = 0; i < apdu.length; i++) {
result[i] = apdu[i] ^ key[i % key.length];
}
return result;
};

// Convert from normal to web-safe, strip trailing "="s
Ledger3.webSafe64 = function(base64) {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
return base64
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
};

// Convert from web-safe to normal, add trailing "="s
Ledger3.normal64 = function(base64) {
return base64.replace(/\-/g, '+').replace(/_/g, '/') + '=='.substring(0, (3*base64.length)%4);
}
return (
base64.replace(/\-/g, "+").replace(/_/g, "/") +
"==".substring(0, (3 * base64.length) % 4)
);
};

Ledger3.prototype.u2fCallback = function(response, callback) {
if (typeof response['signatureData'] != "undefined") {
var data = new Buffer((Ledger3.normal64(response['signatureData'])), 'base64');
callback(data.toString('hex', 5));
}
else {
callback(undefined, response);
}
}
if (typeof response["signatureData"] != "undefined") {
var data = new Buffer(
Ledger3.normal64(response["signatureData"]),
"base64"
);
callback(data.toString("hex", 5));
} else {
callback(undefined, response);
}
};

// callback is function(response, error)
Ledger3.prototype.exchange = function(apduHex, callback) {
var apdu = new Buffer(apduHex, 'hex');
var keyHandle = Ledger3.wrapApdu(apdu, this.scrambleKey);
var challenge = new Buffer("0000000000000000000000000000000000000000000000000000000000000000", 'hex');
var key = {};
key['version'] = 'U2F_V2';
key['keyHandle'] = Ledger3.webSafe64(keyHandle.toString('base64'));
var self = this;
var localCallback = function(result) {
self.u2fCallback(result, callback);
}
u2f.sign(location.origin, Ledger3.webSafe64(challenge.toString('base64')), [key], localCallback, this.timeoutSeconds);
}
var apdu = new Buffer(apduHex, "hex");
var keyHandle = Ledger3.wrapApdu(apdu, this.scrambleKey);
var challenge = new Buffer(
"0000000000000000000000000000000000000000000000000000000000000000",
"hex"
);
var key = {};
key["appId"] = location.origin;
key["challenge"] = Ledger3.webSafe64(challenge.toString("base64"));
key["version"] = "U2F_V2";
key["keyHandle"] = Ledger3.webSafe64(keyHandle.toString("base64"));
var self = this;
var localCallback = function(result) {
self.u2fCallback(result, callback);
};
u2f.sign([key], this.timeoutSeconds).then(localCallback);
};

module.exports = Ledger3
module.exports = Ledger3;
69 changes: 41 additions & 28 deletions app/scripts/staticJS/secalotUsb.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
'use strict';

"use strict";
const u2f = require("u2f-api");
var SecalotUsb = function(timeoutSeconds) {
this.timeoutSeconds = timeoutSeconds;
}
this.timeoutSeconds = timeoutSeconds;
};

// Convert from normal to web-safe, strip trailing "="s
SecalotUsb.webSafe64 = function(base64) {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
return base64
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
};

// Convert from web-safe to normal, add trailing "="s
SecalotUsb.normal64 = function(base64) {
return base64.replace(/\-/g, '+').replace(/_/g, '/') + '=='.substring(0, (3*base64.length)%4);
}
return (
base64.replace(/\-/g, "+").replace(/_/g, "/") +
"==".substring(0, (3 * base64.length) % 4)
);
};

SecalotUsb.prototype.u2fCallback = function(response, callback) {
if (typeof response['signatureData'] != "undefined") {
var data = new Buffer((SecalotUsb.normal64(response['signatureData'])), 'base64');
callback(data.toString('hex'));
}
else {
callback(undefined, response);
}
}
if (typeof response["signatureData"] != "undefined") {
var data = new Buffer(
SecalotUsb.normal64(response["signatureData"]),
"base64"
);
callback(data.toString("hex"));
} else {
callback(undefined, response);
}
};

// callback is function(response, error)
SecalotUsb.prototype.exchange = function(apduHex, callback) {
var apdu = new Buffer('1122334455667788' + apduHex, 'hex');
var challenge = new Buffer("0000000000000000000000000000000000000000000000000000000000000000", 'hex');
var key = {};
key['version'] = 'U2F_V2';
key['keyHandle'] = SecalotUsb.webSafe64(apdu.toString('base64'));
var self = this;
var localCallback = function(result) {
self.u2fCallback(result, callback);
}
u2f.sign(location.origin, SecalotUsb.webSafe64(challenge.toString('base64')), [key], localCallback, this.timeoutSeconds);
}
var apdu = new Buffer("1122334455667788" + apduHex, "hex");
var challenge = new Buffer(
"0000000000000000000000000000000000000000000000000000000000000000",
"hex"
);
var key = {};
key["appId"] = location.origin;
key["challenge"] = SecalotUsb.webSafe64(challenge.toString("base64"));
key["version"] = "U2F_V2";
key["keyHandle"] = SecalotUsb.webSafe64(apdu.toString("base64"));
var self = this;
var localCallback = function(result) {
self.u2fCallback(result, callback);
};
u2f.sign([key], this.timeoutSeconds).then(localCallback);
};

module.exports = SecalotUsb
module.exports = SecalotUsb;
Loading

0 comments on commit dcc38ac

Please sign in to comment.