This commit is contained in:
antelle 2020-04-19 20:55:38 +02:00
parent f79bb90b69
commit eb577d61d5
No known key found for this signature in database
GPG Key ID: 094A2F2D6136A4EE
2 changed files with 37 additions and 21 deletions

View File

@ -2,9 +2,9 @@ import { ExternalOtpDeviceModel } from 'models/external/external-otp-device-mode
import { ExternalOtpEntryModel } from 'models/external/external-otp-entry-model';
import { Launcher } from 'comp/launcher';
class YubiKeyOtpModel extends ExternalOtpDeviceModel {
ykmanStatus = null;
let ykmanStatus;
class YubiKeyOtpModel extends ExternalOtpDeviceModel {
constructor(props) {
super({
shortName: 'YubiKey',
@ -12,6 +12,10 @@ class YubiKeyOtpModel extends ExternalOtpDeviceModel {
});
}
static get ykmanStatus() {
return ykmanStatus;
}
open(callback) {
this.openProcess = Launcher.spawn({
cmd: 'ykman',
@ -77,17 +81,20 @@ class YubiKeyOtpModel extends ExternalOtpDeviceModel {
}
static checkToolStatus() {
if (ykmanStatus === 'ok') {
return Promise.resolve();
}
return new Promise(resolve => {
YubiKeyOtpModel.ykmanStatus = 'checking';
ykmanStatus = 'checking';
Launcher.spawn({
cmd: 'ykman',
args: ['-v'],
noStdOutLogging: true,
complete: (err, stdout, code) => {
if (err || code !== 0) {
YubiKeyOtpModel.ykmanStatus = 'error';
ykmanStatus = 'error';
} else {
YubiKeyOtpModel.ykmanStatus = 'ok';
ykmanStatus = 'ok';
}
resolve();
}

View File

@ -9,6 +9,7 @@ import { SecureInput } from 'comp/browser/secure-input';
import { Launcher } from 'comp/launcher';
import { Alerts } from 'comp/ui/alerts';
import { UsbListener } from 'comp/app/usb-listener';
import { YubiKeyOtpModel } from 'models/external/yubikey-otp-model';
import { Keys } from 'const/keys';
import { Comparators } from 'util/data/comparators';
import { Features } from 'util/features';
@ -986,30 +987,38 @@ class OpenView extends View {
}
openYubiKey() {
return Events.emit('toggle-settings', 'devices');
if (this.busy && this.otpDevice) {
this.otpDevice.cancelOpen();
}
if (!this.busy) {
this.busy = true;
this.inputEl.attr('disabled', 'disabled');
const icon = this.$el.find('.open__icon-otp-device');
const icon = this.$el.find('.open__icon-yubikey');
icon.toggleClass('flip3d', true);
this.otpDevice = this.model.openOtpDevice(err => {
if (err && !this.otpDevice.openAborted) {
Alerts.error({
header: Locale.openError,
body:
Locale.openErrorDescription +
'<pre class="modal__pre">' +
escape(err.toString()) +
'</pre>'
});
YubiKeyOtpModel.checkToolStatus().then(() => {
if (YubiKeyOtpModel.ykmanStatus !== 'ok') {
icon.toggleClass('flip3d', false);
this.inputEl.removeAttr('disabled');
this.busy = false;
return Events.emit('toggle-settings', 'devices');
}
this.otpDevice = null;
icon.toggleClass('flip3d', false);
this.inputEl.removeAttr('disabled');
this.busy = false;
this.otpDevice = this.model.openOtpDevice(err => {
if (err && !this.otpDevice.openAborted) {
Alerts.error({
header: Locale.openError,
body:
Locale.openErrorDescription +
'<pre class="modal__pre">' +
escape(err.toString()) +
'</pre>'
});
}
this.otpDevice = null;
icon.toggleClass('flip3d', false);
this.inputEl.removeAttr('disabled');
this.busy = false;
});
});
}
}