mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Added support for both U2F and OTP hardware login keys.
This commit is contained in:
parent
70bc543699
commit
8c068505cf
15 changed files with 171 additions and 155 deletions
|
@ -1447,38 +1447,44 @@
|
|||
var end = "</table></div></div>";
|
||||
var x = "<a href='https://www.yubico.com/' rel='noreferrer noopener' target='_blank'>Hardware keys</a> are used as secondary login authentication.";
|
||||
x += "";
|
||||
var keyType1 = 0;
|
||||
if (message.keys && message.keys.length > 0) {
|
||||
for (var i in message.keys) {
|
||||
var key = message.keys[i];
|
||||
x += start + '<tr style=margin:5px><td style=width:30px><img src="images/hardware-key-24.png"><td style=width:250px>' + key.name + "<td><input type=button value='Remove' onclick=account_removehkey(" + key.i + ")></input>" + end;
|
||||
var type = 'OTP';
|
||||
if (key.type == 1) { keyType1++; type = 'U2F'; }
|
||||
x += start + '<tr style=margin:5px><td style=width:30px><img width=24 height=18 src="images/hardware-key-' + type + '-24.png" style=margin-top:4px><td style=width:250px>' + key.name + "<td><input type=button value='Remove' onclick=account_removehkey(" + key.i + ")></input>" + end;
|
||||
}
|
||||
} else {
|
||||
x += start + '<tr style=text-align:center><td>No Hardware Keys Configured' + end;
|
||||
}
|
||||
x += "<br />";
|
||||
x += "<div><input type=button value='Close' onclick=setDialogMode(0) style=float:right></input>";
|
||||
//x += "<input type=button value='Add YubiKey' onclick='account_addYubiKey();'></input>";
|
||||
|
||||
if (u2fSupported()) {
|
||||
x += "<input id=d2addkey type=button value='Add Key' onclick='account_addhkey();'></input>";
|
||||
} else {
|
||||
x += "No hardware key support on this browser.";
|
||||
}
|
||||
x += "<input id=d2addkey1 type=button value='Add U2F Key' onclick='account_addhkey(1);'></input>";
|
||||
if ((features & 0x4000) != 0) { x += "<input id=d2addkey2 type=button value='Add OTP Key' onclick='account_addhkey(2);'></input>"; }
|
||||
x += "</div><br />";
|
||||
setDialogMode(2, "Manage Hardware Login Keys", 8, null, x, 'otpauth-hardware-manage');
|
||||
if (u2fSupported() && (message.keys.length > 0)) { QE('d2addkey', false); }
|
||||
if ((u2fSupported() == false) || (keyType1 > 0)) { QE('d2addkey1', false); }
|
||||
break;
|
||||
}
|
||||
case 'otp-hkey-yubikey-add': {
|
||||
if (message.result) {
|
||||
meshserver.send({ action: 'otp-hkey-get' }); // Success, ask for the full list of keys.
|
||||
} else {
|
||||
setDialogMode(2, "Add Hardware Login Key", 1, null, '<br />Error, Unable to add key.<br /><br />');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'otp-hkey-setup-request': {
|
||||
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
|
||||
var x = "Press the key button now.<br /><br /><div style=width:100%;text-align:center><img src='images/hardware-keypress-120.png' /></div><input id=dp1keyname style=display:none value=" + message.name + " />";
|
||||
var x = "Press the key button now.<br /><br /><div style=width:100%;text-align:center><img width=120 height=117 src='images/hardware-keypress-120.png' /></div><input id=dp1keyname style=display:none value=" + message.name + " />";
|
||||
setDialogMode(2, "Add Hardware Login Key", 2, null, x);
|
||||
window.u2f.register(message.request.appId, [message.request], [], function (registrationResponse) {
|
||||
if (registrationResponse.registrationData) {
|
||||
meshserver.send({ action: 'otp-hkey-setup-response', request: message.request, response: registrationResponse, name: Q('dp1keyname').value });
|
||||
setDialogMode(2, "Add Hardware Login Key", 0, null, '<br />Checking...<br /><br /><br />', 'otpauth-hardware-manage');
|
||||
} else {
|
||||
setDialogMode(0);
|
||||
setDialogMode(2, "Add Hardware Login Key", 1, null, '<br />Error code ' + registrationResponse.errorCode + '<br /><br />');
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -5310,38 +5316,32 @@
|
|||
meshserver.send({ action: 'otp-hkey-get' });
|
||||
}
|
||||
|
||||
function account_addhkey() {
|
||||
var x = "Type in the name of the key to add.<br /><br />";
|
||||
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off placeholder="MyKey" onkeyup=account_addhkeyValidate(event) />');
|
||||
setDialogMode(2, "Add Hardware Login Key", 3, account_addhkeyEx, x);
|
||||
function account_addhkey(type) {
|
||||
if (type == 1) {
|
||||
var x = "Type in the name of the key to add.<br /><br />";
|
||||
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off placeholder="MyKey" onkeyup=account_addhkeyValidate(event,2) />');
|
||||
} else if (type == 2) {
|
||||
var x = "Type in a key name, select the OTP box and press the USB key button<br /><br />";
|
||||
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off placeholder="MyKey" onkeyup=account_addhkeyValidate(event,1) />');
|
||||
x += addHtmlValue('OTP from key', '<input id=dp1key style=width:230px autocomplete=off onkeyup=account_addhkeyValidate(event,2) />');
|
||||
}
|
||||
setDialogMode(2, "Add Hardware Login Key", 3, account_addhkeyEx, x, type);
|
||||
Q('dp1keyname').focus();
|
||||
}
|
||||
|
||||
function account_addhkeyValidate(e) {
|
||||
if ((e != null) && (e.keyCode == 13)) { dialogclose(1); }
|
||||
function account_addhkeyValidate(e,action) {
|
||||
if ((e != null) && (e.keyCode == 13)) { if (action == 2) { dialogclose(1); } else { Q('dp1key').focus(); } }
|
||||
}
|
||||
|
||||
function account_addhkeyEx() {
|
||||
function account_addhkeyEx(button, type) {
|
||||
var name = Q('dp1keyname').value;
|
||||
if (name == '') { name = 'MyKey'; }
|
||||
meshserver.send({ action: 'otp-hkey-setup-request', name: name });
|
||||
}
|
||||
|
||||
function account_addYubiKey() {
|
||||
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
|
||||
var x = "Type in a name for the key and press button on the key to register the new hardware key.<br /><br />";
|
||||
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off onchange=account_addYubiKeyValidate() onkeyup=account_addYubiKeyValidate() />');
|
||||
x += addHtmlValue('Key Token', '<input id=dp1keytoken style=width:230px maxlength=2048 autocomplete=off onchange=account_addYubiKeyValidate() onkeyup=account_addYubiKeyValidate() />');
|
||||
setDialogMode(2, "Add Yubikey", 3, account_addYubiKeyEx, x);
|
||||
account_addYubiKeyValidate();
|
||||
}
|
||||
|
||||
function account_addYubiKeyValidate() {
|
||||
QE('idx_dlgOkButton', (Q('dp1keyname').value.length > 0) && (Q('dp1keytoken').value.length > 0));
|
||||
}
|
||||
|
||||
function account_addYubiKeyEx() {
|
||||
meshserver.send({ action: 'otp-hkey-yubikey-add', name: Q('dp1keyname').value, otp: Q('dp1keytoken').value });
|
||||
if (type == 1) {
|
||||
meshserver.send({ action: 'otp-hkey-setup-request', name: name });
|
||||
} else if (type == 2) {
|
||||
meshserver.send({ action: 'otp-hkey-yubikey-add', name: name, otp: Q('dp1key').value });
|
||||
setDialogMode(2, "Add Hardware Login Key", 0, null, "<br />Checking...<br /><br /><br />", 'otpauth-hardware-manage');
|
||||
}
|
||||
}
|
||||
|
||||
function account_removehkey(index) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue