Commit b5a34152 authored by Matthew Braithwaite's avatar Matthew Braithwaite Committed by Commit Bot

Update cryptotoken to 0.9.71.

Most changes are cosmetic.

Bug: 780299
Change-Id: I346ec1b6bd11ef20ef8018989b51c9c5842c4dee
Reviewed-on: https://chromium-review.googlesource.com/701468
Commit-Queue: Matt Braithwaite <mab@google.com>
Reviewed-by: default avatarAdam Langley <agl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521217}
parent 0eb57d23
......@@ -44,6 +44,12 @@ DeviceStatusCodes.INVALID_DATA_STATUS = 0x6984;
*/
DeviceStatusCodes.WRONG_DATA_STATUS = 0x6a80;
/**
* Device operation file not found status.
* @const
*/
DeviceStatusCodes.FILE_NOT_FOUND_STATUS = 0x6a82;
/**
* Device operation timeout status.
* @const
......
......@@ -539,7 +539,7 @@ Enroller.prototype.notifyError_ = function(error) {
* Notifies the caller of success with the provided response data.
* @param {string} u2fVersion Protocol version
* @param {string} info Response data
* @param {string|undefined} opt_browserData Browser data used
* @param {string=} opt_browserData Browser data used
* @private
*/
Enroller.prototype.notifySuccess_ = function(
......@@ -562,6 +562,12 @@ Enroller.prototype.helperComplete_ = function(reply) {
console.log(UTIL_fmt(
'helper reported ' + reply.code.toString(16) + ', returning ' +
reportedError.errorCode));
// Log non-expected reply codes if we have url to send them.
if (reportedError.errorCode == ErrorCodes.OTHER_ERROR) {
var logMsg = 'log=u2fenroll&rc=' + reply.code.toString(16);
if (this.logMsgUrl_)
logMessage(logMsg, this.logMsgUrl_);
}
this.notifyError_(reportedError);
} else {
console.log(UTIL_fmt('Gnubby enrollment succeeded!!!!!'));
......
......@@ -170,7 +170,7 @@ Gnubbies.prototype.enumerate = function(cb, opt_type) {
}
console.log(UTIL_fmt('Enumerated ' + devs.length + ' gnubbies'));
console.log(devs);
console.log(UTIL_fmt(JSON.stringify(devs)));
var presentDevs = {};
var deviceIds = [];
......
......@@ -66,10 +66,10 @@ Gnubby.prototype.cancelOpen = function() {
/**
* Opens the gnubby with the given index, or the first found gnubby if no
* index is specified.
* @param {GnubbyDeviceId} which The device to open. If null, the first
* @param {?GnubbyDeviceId} which The device to open. If null, the first
* gnubby found is opened.
* @param {GnubbyEnumerationTypes=} opt_type Which type of device to enumerate.
* @param {function(number)|undefined} opt_cb Called with result of opening the
* @param {function(number)=} opt_cb Called with result of opening the
* gnubby.
* @param {string=} opt_caller Identifier for the caller.
*/
......@@ -113,22 +113,23 @@ Gnubby.prototype.open = function(which, opt_type, opt_cb, opt_caller) {
if (self.closeHook_) {
self.dev.setDestroyHook(self.closeHook_);
}
cb(rc);
cb.call(self, rc);
});
}
if (which) {
setCid(which);
self.which = which;
Gnubby.gnubbies_.addClient(which, self, function(rc, device) {
if (!rc) {
self.dev = device;
if (self.closeHook_) {
self.dev.setDestroyHook(self.closeHook_);
}
}
cb(rc);
});
Gnubby.gnubbies_.addClient(
/** @type {GnubbyDeviceId} */ (which), self, function(rc, device) {
if (!rc) {
self.dev = device;
if (self.closeHook_) {
self.dev.setDestroyHook(self.closeHook_);
}
}
cb.call(self, rc);
});
} else {
Gnubby.gnubbies_.enumerate(enumerated, opt_type);
}
......@@ -139,7 +140,7 @@ Gnubby.prototype.open = function(which, opt_type, opt_cb, opt_caller) {
* collide within this application, but may when others simultaneously access
* the device.
* @param {number} gnubbyInstance An instance identifier for a gnubby.
* @param {GnubbyDeviceId} which The device identifer for the gnubby device.
* @param {GnubbyDeviceId} which The device identifier for the gnubby device.
* @return {number} The channel id.
* @private
*/
......@@ -497,9 +498,8 @@ Gnubby.prototype.write_ = function(cmd, data) {
* @param {ArrayBuffer|Uint8Array} data Command data
* @param {number} timeout Timeout in seconds.
* @param {function(number, ArrayBuffer=)} cb Callback
* @private
*/
Gnubby.prototype.exchange_ = function(cmd, data, timeout, cb) {
Gnubby.prototype.exchange = function(cmd, data, timeout, cb) {
var busyWait = new CountdownTimer(Gnubby.SYS_TIMER_, this.busyMillis);
var self = this;
......@@ -742,7 +742,7 @@ Gnubby.prototype.blink = function(data, cb) {
var d = new Uint8Array([data]);
data = d.buffer;
}
this.exchange_(GnubbyDevice.CMD_PROMPT, data, Gnubby.NORMAL_TIMEOUT, cb);
this.exchange(GnubbyDevice.CMD_PROMPT, data, Gnubby.NORMAL_TIMEOUT, cb);
};
/** Lock the gnubby
......@@ -756,7 +756,7 @@ Gnubby.prototype.lock = function(data, cb) {
var d = new Uint8Array([data]);
data = d.buffer;
}
this.exchange_(GnubbyDevice.CMD_LOCK, data, Gnubby.NORMAL_TIMEOUT, cb);
this.exchange(GnubbyDevice.CMD_LOCK, data, Gnubby.NORMAL_TIMEOUT, cb);
};
/** Unlock the gnubby
......@@ -766,7 +766,7 @@ Gnubby.prototype.unlock = function(cb) {
if (!cb)
cb = Gnubby.defaultCallback;
var data = new Uint8Array([0]);
this.exchange_(GnubbyDevice.CMD_LOCK, data.buffer, Gnubby.NORMAL_TIMEOUT, cb);
this.exchange(GnubbyDevice.CMD_LOCK, data.buffer, Gnubby.NORMAL_TIMEOUT, cb);
};
/** Request system information data.
......@@ -775,7 +775,7 @@ Gnubby.prototype.unlock = function(cb) {
Gnubby.prototype.sysinfo = function(cb) {
if (!cb)
cb = Gnubby.defaultCallback;
this.exchange_(
this.exchange(
GnubbyDevice.CMD_SYSINFO, new ArrayBuffer(0), Gnubby.NORMAL_TIMEOUT, cb);
};
......@@ -785,7 +785,7 @@ Gnubby.prototype.sysinfo = function(cb) {
Gnubby.prototype.wink = function(cb) {
if (!cb)
cb = Gnubby.defaultCallback;
this.exchange_(
this.exchange(
GnubbyDevice.CMD_WINK, new ArrayBuffer(0), Gnubby.NORMAL_TIMEOUT, cb);
};
......@@ -796,7 +796,7 @@ Gnubby.prototype.wink = function(cb) {
Gnubby.prototype.dfu = function(data, cb) {
if (!cb)
cb = Gnubby.defaultCallback;
this.exchange_(GnubbyDevice.CMD_DFU, data, Gnubby.NORMAL_TIMEOUT, cb);
this.exchange(GnubbyDevice.CMD_DFU, data, Gnubby.NORMAL_TIMEOUT, cb);
};
/** Ping the gnubby
......@@ -811,7 +811,7 @@ Gnubby.prototype.ping = function(data, cb) {
window.crypto.getRandomValues(d);
data = d.buffer;
}
this.exchange_(GnubbyDevice.CMD_PING, data, Gnubby.NORMAL_TIMEOUT, cb);
this.exchange(GnubbyDevice.CMD_PING, data, Gnubby.NORMAL_TIMEOUT, cb);
};
/** Send a raw APDU command
......@@ -821,7 +821,7 @@ Gnubby.prototype.ping = function(data, cb) {
Gnubby.prototype.apdu = function(data, cb) {
if (!cb)
cb = Gnubby.defaultCallback;
this.exchange_(GnubbyDevice.CMD_APDU, data, Gnubby.MAX_TIMEOUT, cb);
this.exchange(GnubbyDevice.CMD_APDU, data, Gnubby.MAX_TIMEOUT, cb);
};
/** Reset gnubby
......@@ -830,7 +830,7 @@ Gnubby.prototype.apdu = function(data, cb) {
Gnubby.prototype.reset = function(cb) {
if (!cb)
cb = Gnubby.defaultCallback;
this.exchange_(
this.exchange(
GnubbyDevice.CMD_ATR, new ArrayBuffer(0), Gnubby.MAX_TIMEOUT, cb);
};
......@@ -845,7 +845,7 @@ Gnubby.prototype.usb_test = function(args, cb) {
if (!cb)
cb = Gnubby.defaultCallback;
var u8 = new Uint8Array(args);
this.exchange_(
this.exchange(
GnubbyDevice.CMD_USB_TEST, u8.buffer, Gnubby.NORMAL_TIMEOUT, cb);
};
......
......@@ -50,3 +50,13 @@ GnubbyFactory.prototype.openGnubby = function(
*/
GnubbyFactory.prototype.notEnrolledPrerequisiteCheck = function(
gnubby, appIdHash, cb) {};
/**
* Called immediately after enrolling the gnubby to perform necessary actions.
* @param {Gnubby} gnubby The just-enrolled gnubby.
* @param {string} appIdHash The base64-encoded hash of the app id for which
* the gnubby was enrolled.
* @param {FactoryOpenCallback} cb Called with the result of the action.
* (A non-zero status indicates failure.)
*/
GnubbyFactory.prototype.postEnrollAction = function(gnubby, appIdHash, cb) {};
......@@ -11,7 +11,7 @@
* @param {string=} opt_logMsgUrl the url to post log messages to.
*/
function logMessage(logMsg, opt_logMsgUrl) {
console.log(UTIL_fmt('logMessage("' + logMsg + '")'));
console.warn(UTIL_fmt('logMessage("' + logMsg + '")'));
if (!opt_logMsgUrl) {
return;
......
{
"name": "CryptoTokenExtension",
"description": "CryptoToken Component Extension",
"version": "0.9.46",
"version": "0.9.71",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq7zRobvA+AVlvNqkHSSVhh1sEWsHSqz4oR/XptkDe/Cz3+gW9ZGumZ20NCHjaac8j1iiesdigp8B1LJsd/2WWv2Dbnto4f8GrQ5MVphKyQ9WJHwejEHN2K4vzrTcwaXqv5BSTXwxlxS/mXCmXskTfryKTLuYrcHEWK8fCHb+0gvr8b/kvsi75A1aMmb6nUnFJvETmCkOCPNX5CHTdy634Ts/x0fLhRuPlahk63rdf7agxQv5viVjQFk+tbgv6aa9kdSd11Js/RZ9yZjrFgHOBWgP4jTBqud4+HUglrzu8qynFipyNRLCZsaxhm+NItTyNgesxLdxZcwOz56KD1Q4IQIDAQAB",
"manifest_version": 2,
"permissions": [
......
......@@ -52,7 +52,7 @@ function MultipleGnubbySigner(
/** @private {string|undefined} */
this.logMsgUrl_ = opt_logMsgUrl;
/** @private {Array<SignHelperChallenge>} */
/** @private {Array<DecodedSignHelperChallenge>} */
this.challenges_ = [];
/** @private {boolean} */
this.challengesSet_ = false;
......@@ -107,12 +107,12 @@ MultipleGnubbySigner.prototype.doSign = function(challenges) {
if (challenges) {
for (var i = 0; i < challenges.length; i++) {
var decodedChallenge = {};
var challenge = challenges[i];
decodedChallenge['challengeHash'] =
B64_decode(challenge['challengeHash']);
decodedChallenge['appIdHash'] = B64_decode(challenge['appIdHash']);
decodedChallenge['keyHandle'] = B64_decode(challenge['keyHandle']);
var decodedChallenge = {
challengeHash: B64_decode(challenge['challengeHash']),
appIdHash: B64_decode(challenge['appIdHash']),
keyHandle: B64_decode(challenge['keyHandle'])
};
if (challenge['version']) {
decodedChallenge['version'] = challenge['version'];
}
......
......@@ -33,8 +33,10 @@ function RequestToken(queue, id, beginCb, opt_prev, opt_next) {
this.queue_ = queue;
/** @private {number} */
this.id_ = id;
/** @type {function(QueuedRequestToken)} */
this.beginCb = beginCb;
/** @private {boolean} */
this.begun_ = false;
/** @private {function(QueuedRequestToken)} */
this.beginCb_ = beginCb;
/** @type {RequestToken} */
this.prev = null;
/** @type {RequestToken} */
......@@ -43,6 +45,17 @@ function RequestToken(queue, id, beginCb, opt_prev, opt_next) {
this.completed_ = false;
}
/** Begins work on this queued request. */
RequestToken.prototype.begin = function() {
this.begun_ = true;
this.beginCb_(this);
};
/** @return {boolean} Whether this token has already begun. */
RequestToken.prototype.begun = function() {
return this.begun_;
};
/** Completes (or cancels) this queued request. */
RequestToken.prototype.complete = function() {
if (this.completed_) {
......@@ -59,6 +72,12 @@ RequestToken.prototype.completed = function() {
return this.completed_;
};
/** @return {number} This token's id. */
RequestToken.prototype.id = function() {
return this.id_;
};
/**
* @param {!SystemTimer} sysTimer A system timer implementation.
* @constructor
......@@ -96,15 +115,32 @@ RequestQueue.prototype.insertToken_ = function(token) {
/**
* Removes this token from the queue.
* @param {RequestToken} token Queue token
* @return {RequestToken?} The next token in the queue to run, if any.
* @private
*/
RequestQueue.prototype.removeToken_ = function(token) {
var nextTokenToRun = null;
// If this token has been begun, find the next token to run.
if (token.begun()) {
// Find the first token in the queue which has not yet been begun, and which
// is not the token being removed.
for (var nextToken = this.head_; nextToken; nextToken = nextToken.next) {
if (nextToken !== token && !nextToken.begun()) {
nextTokenToRun = nextToken;
break;
}
}
}
// Remove this token from the queue
if (token.next) {
token.next.prev = token.prev;
}
if (token.prev) {
token.prev.next = token.next;
}
// Update head and tail of queue.
if (this.head_ === token && this.tail_ === token) {
this.head_ = this.tail_ = null;
} else {
......@@ -117,7 +153,12 @@ RequestQueue.prototype.removeToken_ = function(token) {
this.tail_.next = null;
}
}
// Isolate this token to prevent it from manipulating the queue, e.g. if
// complete() is called a second time with it.
token.prev = token.next = null;
return nextTokenToRun;
};
/**
......@@ -126,11 +167,16 @@ RequestQueue.prototype.removeToken_ = function(token) {
* @param {RequestToken} token Queue token
*/
RequestQueue.prototype.complete = function(token) {
console.log(UTIL_fmt('token ' + this.id_ + ' completed'));
var next = token.next;
this.removeToken_(token);
var next = this.removeToken_(token);
if (next) {
next.beginCb(next);
console.log(
UTIL_fmt('token ' + token.id() + ' completed, starting ' + next.id()));
next.begin();
} else if (this.empty()) {
console.log(UTIL_fmt('token ' + token.id() + ' completed, queue empty'));
} else {
console.log(UTIL_fmt(
'token ' + token.id() + ' completed (earlier token still running)'));
}
};
......@@ -156,7 +202,7 @@ RequestQueue.prototype.queueRequest = function(beginCb, timer) {
if (startNow) {
this.sysTimer_.setTimeout(function() {
if (!token.completed()) {
token.beginCb(token);
token.begin();
}
}, 0);
}
......
......@@ -11,6 +11,9 @@
var gnubbySignRequestQueue;
/**
* Initialize request queue.
*/
function initRequestQueue() {
gnubbySignRequestQueue =
new OriginKeyedRequestQueue(FACTORY_REGISTRY.getSystemTimer());
......@@ -177,10 +180,10 @@ function isValidSignRequest(request) {
* @param {WebRequestSender} sender Message sender.
* @param {function(U2fError)} errorCb Error callback
* @param {function(SignChallenge, string, string)} successCb Success callback
* @param {string|undefined} opt_defaultChallenge A default sign challenge
* @param {string=} opt_defaultChallenge A default sign challenge
* value, if a request does not provide one.
* @param {string|undefined} opt_appId The app id for the entire request.
* @param {string|undefined} opt_logMsgUrl Url to post log messages to
* @param {string=} opt_appId The app id for the entire request.
* @param {string=} opt_logMsgUrl Url to post log messages to
* @constructor
* @implements {Closeable}
*/
......@@ -538,6 +541,12 @@ Signer.prototype.helperComplete_ = function(helperReply, opt_source) {
console.log(UTIL_fmt(
'helper reported ' + reply.code.toString(16) + ', returning ' +
reportedError.errorCode));
// Log non-expected reply codes if we have an url to send them
if (reportedError.errorCode == ErrorCodes.OTHER_ERROR) {
var logMsg = 'log=u2fsign&rc=' + reply.code.toString(16);
if (this.logMsgUrl_)
logMessage(logMsg, this.logMsgUrl_);
}
this.notifyError_(reportedError);
} else {
if (this.logMsgUrl_ && opt_source) {
......
......@@ -11,11 +11,21 @@
'use strict';
/**
* @typedef {{
* challengeHash: Array<number>,
* appIdHash: Array<number>,
* keyHandle: Array<number>,
* version: (string|undefined)
* }}
*/
var DecodedSignHelperChallenge;
/**
* @typedef {{
* code: number,
* gnubby: (Gnubby|undefined),
* challenge: (SignHelperChallenge|undefined),
* challenge: (DecodedSignHelperChallenge|undefined),
* info: (ArrayBuffer|undefined)
* }}
*/
......@@ -65,14 +75,14 @@ function SingleGnubbySigner(
/** @private {string|undefined} */
this.logMsgUrl_ = opt_logMsgUrl;
/** @private {!Array<!SignHelperChallenge>} */
/** @private {!Array<!DecodedSignHelperChallenge>} */
this.challenges_ = [];
/** @private {number} */
this.challengeIndex_ = 0;
/** @private {boolean} */
this.challengesSet_ = false;
/** @private {!Object<string, number>} */
/** @private {!Object<Array<number>, number>} */
this.cachedError_ = [];
/** @private {(function()|undefined)} */
......@@ -132,7 +142,7 @@ SingleGnubbySigner.prototype.closed_ = function() {
/**
* Begins signing the given challenges.
* @param {Array<SignHelperChallenge>} challenges The challenges to sign.
* @param {Array<DecodedSignHelperChallenge>} challenges The challenges to sign.
* @return {boolean} Whether the challenges were accepted.
*/
SingleGnubbySigner.prototype.doSign = function(challenges) {
......@@ -481,7 +491,7 @@ SingleGnubbySigner.prototype.goToError_ = function(code, opt_warn) {
/**
* Switches to the success state, and notifies caller.
* @param {number} code Status code
* @param {SignHelperChallenge=} opt_challenge The challenge signed
* @param {DecodedSignHelperChallenge=} opt_challenge The challenge signed
* @param {ArrayBuffer=} opt_info Optional result data
* @private
*/
......
......@@ -284,8 +284,16 @@ UsbEnrollHandler.prototype.enrollCallback_ = function(
break;
case DeviceStatusCodes.OK_STATUS:
var info = B64_encode(new Uint8Array(infoArray || []));
this.notifySuccess_(version, info);
var appIdHash = this.request_.enrollChallenges[0].appIdHash;
DEVICE_FACTORY_REGISTRY.getGnubbyFactory().postEnrollAction(
gnubby, appIdHash, (rc) => {
if (rc == DeviceStatusCodes.OK_STATUS) {
var info = B64_encode(new Uint8Array(infoArray || []));
this.notifySuccess_(version, info);
} else {
this.notifyError_(rc);
}
});
break;
default:
......
......@@ -198,7 +198,7 @@ UsbGnubbyDevice.prototype.readOneReply_ = function() {
}, 0);
} else {
console.log(UTIL_fmt('no x.data!'));
console.log(x);
console.log(UTIL_fmt(JSON.stringify(x)));
window.setTimeout(function() {
self.destroy();
}, 0);
......
......@@ -65,3 +65,15 @@ UsbGnubbyFactory.prototype.notEnrolledPrerequisiteCheck = function(
gnubby, appIdHash, cb) {
cb(DeviceStatusCodes.OK_STATUS, gnubby);
};
/**
* No-op post enroll action.
* @param {Gnubby} gnubby The just-enrolled gnubby.
* @param {string} appIdHash The base64-encoded hash of the app id for which
* the gnubby was enrolled.
* @param {FactoryOpenCallback} cb Called with the result of the action.
* (A non-zero status indicates failure.)
*/
UsbGnubbyFactory.prototype.postEnrollAction = function(gnubby, appIdHash, cb) {
cb(DeviceStatusCodes.OK_STATUS, gnubby);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment