Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question, Web dev] Best way for detecting U2F in Web pages #38

Open
My1 opened this issue May 10, 2016 · 10 comments
Open

[Question, Web dev] Best way for detecting U2F in Web pages #38

My1 opened this issue May 10, 2016 · 10 comments

Comments

@My1
Copy link

My1 commented May 10, 2016

I am writing a site that also should work with U2F but there's one important question.

what is the best way to detect U2F functionality for both chrome and users of addons for other browsers?

@KellerFuchs
Copy link

@My1
Copy link
Author

My1 commented Sep 30, 2016

thanks, but last time I tried it certainly didnt work.

screenshot 346

@prefiks
Copy link
Owner

prefiks commented Sep 30, 2016

Hm, if (typeof window.u2f !== "undefined") returns true then it must have some value set right?

@My1
Copy link
Author

My1 commented Sep 30, 2016

yes but for internet explorer (bottom right) it should not be true, I dont think IE does U2F

@prefiks
Copy link
Owner

prefiks commented Sep 30, 2016

Ah interesting, could you see what value it typeof returns for it in IE instead checking if it's not undefined? Also doesn't that script you are loading is defining it by chance (if it's compatibility shim for chrome then i am pretty sure it does that)?

@My1
Copy link
Author

My1 commented Sep 30, 2016

well I used the yubico documentation to do U2F and they said

"Client-side
This section assumes that you are building a web site. If this is not the case, have a look at our U2F host libraries instead. Also note that Chrome is currently the only web browser supporting U2F.
The main part of the client is to be a middle-man between the server and the U2F device.
The easiest way to use U2F in a supported browser is to use the u2f-api.js library, which exposes two functions:
u2f.register Register using a U2F device.
u2f.sign Authenticate using a U2F device. "

https://developers.yubico.com/U2F/Libraries/Using_a_library.html

so at least the text pretty much assumes that the api (or something similar) is needed to expose those fuctions

If I dont load the api prior to checking, a plugged firefox says true but everyone else (including chrome) says false.

@prefiks
Copy link
Owner

prefiks commented Sep 30, 2016

Chrome does expose u2f functionality as extension messaging port, and what that js code does is implement window.u2f.register/sign functions by sending/receiving messages from that port. This firefox extension just makes window.u2f.register/sign always available.

So you check probably should work by checking if window.u2f exists before loading that script, if it's here you good to go, if not check if it's Chrome and you should be good as well (you could also check for browser version in this situation to see if it's one that should have it).

@My1
Copy link
Author

My1 commented Sep 30, 2016

but if a browser goes for a chrome similar approach (it might just be a fork of it) then it wont work which is a bit sad because it needs to stay updated. and that user agent isnt reliable is pretty obvious considering that all browsers have mozilla in their agents to circumvent useragent-based browser switches

@prefiks
Copy link
Owner

prefiks commented Sep 30, 2016

Well there is no real solution for having 100% sure way to be forward compatible, and i doubt that other browsers will implement interface that is compatible with what Chrome does (this will require having message port exposed as window.chrome.extension., and have lot more code that chrome has for extension managing).

@My1
Copy link
Author

My1 commented Sep 30, 2016

okay. it is a bit sad the the there isnt some kind of "featureset" array set by the browser and read-only where any js software can check whether feature x is available.

it would be intresting to know how github did it but when I checked some months agoI couldnt make much sense of their code, honestly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants