2018-04-14 09:18:00 +00:00
|
|
|
/** global: AJAX */
|
|
|
|
/** global: PMA_messages */
|
|
|
|
/** global: u2f */
|
|
|
|
AJAX.registerOnload('u2f.js', function () {
|
|
|
|
var $inputReg = $('#u2f_registration_response');
|
|
|
|
if ($inputReg.length > 0) {
|
|
|
|
var $formReg = $inputReg.parents('form');
|
|
|
|
$formReg.find('input[type=submit]').hide();
|
2019-12-08 07:14:01 +00:00
|
|
|
setTimeout(function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
// A magic JS function that talks to the USB device. This function will keep polling for the USB device until it finds one.
|
|
|
|
var request = JSON.parse($inputReg.attr('data-request'));
|
2019-12-08 07:14:01 +00:00
|
|
|
u2f.register(request.appId, [request], JSON.parse($inputReg.attr('data-signatures')), function (data) {
|
2018-04-14 09:18:00 +00:00
|
|
|
// Handle returning error data
|
2019-12-08 07:14:01 +00:00
|
|
|
if (data.errorCode && data.errorCode !== 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (data.errorCode === 5) {
|
|
|
|
PMA_ajaxShowMessage(PMA_messages.strU2FTimeout, false);
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(
|
|
|
|
PMA_sprintf(PMA_messages.strU2FError, data.errorCode), false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill and submit form.
|
|
|
|
$inputReg.val(JSON.stringify(data));
|
|
|
|
$formReg.submit();
|
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
var $inputAuth = $('#u2f_authentication_response');
|
|
|
|
if ($inputAuth.length > 0) {
|
|
|
|
var $formAuth = $inputAuth.parents('form');
|
|
|
|
$formAuth.find('input[type=submit]').hide();
|
2019-12-08 07:14:01 +00:00
|
|
|
setTimeout(function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
// Magic JavaScript talking to your HID
|
|
|
|
// appid, challenge, authenticateRequests
|
|
|
|
var request = JSON.parse($inputAuth.attr('data-request'));
|
|
|
|
var handles = [request[0].keyHandle];
|
2019-12-08 07:14:01 +00:00
|
|
|
u2f.sign(request[0].appId, request[0].challenge, request, function (data) {
|
2018-04-14 09:18:00 +00:00
|
|
|
// Handle returning error data
|
2019-12-08 07:14:01 +00:00
|
|
|
if (data.errorCode && data.errorCode !== 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (data.errorCode === 5) {
|
|
|
|
PMA_ajaxShowMessage(PMA_messages.strU2FTimeout, false);
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(
|
|
|
|
PMA_sprintf(PMA_messages.strU2FError, data.errorCode), false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill and submit form.
|
|
|
|
$inputAuth.val(JSON.stringify(data));
|
|
|
|
$formAuth.submit();
|
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
});
|