1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

u2f connector updates

This commit is contained in:
Kyle Spearrin 2017-06-26 23:52:49 -04:00
parent 5d87fae906
commit 0ee928cdce

View File

@ -3,9 +3,20 @@
});
var parentUrl = null,
version = null;
parentOrigin = null,
version = null,
stop = false,
sentSuccess = false;
function init() {
start();
onMessage();
info('ready');
}
function start() {
sentSuccess = false;
if (!u2f.isSupported) {
error('U2F is not supported in this browser.');
return;
@ -22,6 +33,11 @@ function init() {
error('No parent.');
return;
}
else {
var link = document.createElement('a');
link.href = parentUrl;
parentOrigin = link.origin;
}
var versionQs = getQsParam('v');
if (!versionQs) {
@ -44,11 +60,15 @@ function init() {
return;
}
stop = false
initU2f(json);
info('ready');
}
function initU2f(obj) {
if (stop) {
return;
}
u2f.sign(obj.appId, obj.challenge, obj.keys, function (data) {
if (data.errorCode) {
if (data.errorCode === 5) {
@ -64,13 +84,33 @@ function initU2f(obj) {
}, 5);
}
function onMessage() {
window.addEventListener('message', function (event) {
if (!event.origin || event.origin === '' || event.origin !== parentOrigin) {
return;
}
if (event.data === 'stop') {
stop = true;
}
else if (event.data === 'start' && stop) {
start();
}
}, false);
}
function error(message) {
parent.postMessage('error|' + message, parentUrl);
}
function success(data) {
if (sentSuccess) {
return;
}
var dataString = JSON.stringify(data);
parent.postMessage('success|' + dataString, parentUrl);
sentSuccess = true;
}
function info(message) {