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

Add cryptotokenPrivate and device support (hid and usb) for U2F #268

Merged
merged 6 commits into from
Jan 9, 2018

Conversation

evq
Copy link
Member

@evq evq commented Jul 31, 2017

This PR contains the following changes required to enable u2f support:

  1. Instantiate the chrome device client to enable the existing chrome.hid and chrome.usb apis
  2. Implement chrome.windows.get which is used by the cryptotoken extension
  3. Build and register the chrome.cryptotokenPrivate extension api
  4. Allow loading of component extensions from pak resources via the brave extension api

I have tested these changes on linux, mac and windows.

@@ -17,7 +17,21 @@ binding.registerCustomHook(function (bindingsAPI, extensionId) {
})

apiFunctions.setHandleRequest('get', function (windowId, getInfo, cb) {
console.warn('chrome.windows.get is not supported yet')
if (arguments.length === 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you actually don't need all of these checks becausesetHandleRequest normalizes the arguments

getInfo = arguments[1]
cb = arguments[2]
}
var responseId = ++id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've moved away from using ++id because it can produce duplicate requests across multiple windows. See tabs_bindings.js for usage of ipc.guid()

@evq evq force-pushed the evq/u2f branch 2 times, most recently from 3046d71 to 3a372c8 Compare August 14, 2017 19:02
@evq evq changed the title WIP Add cryptotokenPrivate and device support (hid and usb) for U2F Add cryptotokenPrivate and device support (hid and usb) for U2F Aug 14, 2017
BUILD.gn Outdated
@@ -121,6 +122,7 @@ repack("packed_extra_resources") {
":atom_resources",
":brave_resources",
"app:brave_strings",
"//chrome/browser/resources:component_extension_resources_grit",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't think be //chrome/browser/resources:component_extension_resources? I don't see a target for component_extension_resources_grit

AtomComponentExtensionResourceManager::
~AtomComponentExtensionResourceManager() {}

bool AtomComponentExtensionResourceManager::IsComponentExtensionResource(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of this code looks identical to ChromeComponentExtensionResourceManager. We want to avoid copying chrome code so can you subclass instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I can subclass since AddComponentResourceEntries and path_to_resource_id_ are private

"//chrome/browser/extensions/event_router_forwarder.cc",
"//chrome/browser/extensions/event_router_forwarder.h",
"//chrome/browser/extensions/window_controller.cc",
Copy link
Collaborator

@bridiver bridiver Aug 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a potential problem to me because along with windows_util above. None of these methods will work correctly with our code so anything that uses them will get the wrong result. I think we need to look at the usage and possibly override with our own implementation

@@ -603,6 +603,28 @@ var windowInfo = function (win, populateTabs) {
}
}

ipcMain.on('chrome-windows-get', function (evt, responseId, windowId, getInfo) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a rebase issue? Doesn't seem related

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chrome.windows.get is needed by the cryptotoken extension, thus I implemented it

@alexwykoff
Copy link
Contributor

What are the next steps @evq ?

@evq
Copy link
Member Author

evq commented Nov 2, 2017

@alexwykoff
I have some local changes to address the requested changes which I was working on pre-Mercury, I need to rebase and finish those off. Barring major stumbling blocks during rebase, it shouldn't take much time at all once I can get back at it. Would really like to target the end of next week.

@evq
Copy link
Member Author

evq commented Dec 22, 2017

@bridiver apologies for the long hiatus on this one... finally got some time to rebase, finish addressing your comments and test!

the primary change avoids copying a bunch of code from ChromeComponentExtensionResourceManager - I am now using it directly and have removed the small shim AtomComponentExtensionResourceManager. I've created a helper method to enable loading the extension manifest from the resources bundle.

@@ -310,6 +310,8 @@ source_set("browser") {
"extensions/api/atom_extensions_api_client.h",
"extensions/atom_browser_client_extensions_part.cc",
"extensions/atom_browser_client_extensions_part.h",
"extensions/atom_component_extensions.cc",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this uses brave_resources.h we need to add a dep for brave_resources here too

@@ -306,6 +308,8 @@ source_set("browser") {
}

if (enable_extensions) {
data_deps += [ "//electron:brave_resources" ]
Copy link
Member Author

@evq evq Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bridiver is this the right way to address your previous comment re: the missing brave_resources.h dependency? wasn't sure since it is generated and I'm not particularly familiar with GN

return NULL;

int resource_id;
if (!IsComponentExtension(path, &resource_id)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use IsComponentExtensionResource here instead? IsComponentExtension is a bit misleading because we have component extensions that are not loaded from resource paks

@@ -19,6 +20,8 @@ MuonBrowserProcessImpl::MuonBrowserProcessImpl(
const base::CommandLine& command_line) :
BrowserProcessImpl(local_state_task_runner, command_line) {
g_browser_process = this;

device_client_.reset(new ChromeDeviceClient);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should actually go in chromium_src browser_process_impl.cc
the muon subclass is for muon-specific stuff

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do a follow-up with the minor remaining changes

@bridiver bridiver merged commit 45f057e into master Jan 9, 2018
bridiver added a commit that referenced this pull request Jan 9, 2018
Add cryptotokenPrivate and device support (hid and usb) for U2F
@bridiver bridiver added this to the 4.6.7 milestone Jan 9, 2018
@bsclifton bsclifton deleted the evq/u2f branch February 7, 2018 21:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants