restarting the yubikey application if it's stuck

This commit is contained in:
antelle 2020-05-05 22:36:23 +02:00
parent 46710aead4
commit 235ceae228
No known key found for this signature in database
GPG Key ID: 094A2F2D6136A4EE
2 changed files with 23 additions and 3 deletions

View File

@ -248,7 +248,7 @@ const Launcher = {
logger.info(msg + (stdout && !config.noStdOutLogging ? '\n' + stdout : ''));
}
if (complete) {
complete(code !== 0 ? 'Exit code ' + code : null, stdout, code);
complete(code !== 0 ? 'Exit code ' + code : null, stdout, code, stderr);
complete = null;
}
});

View File

@ -28,14 +28,34 @@ class YubiKeyOtpModel extends ExternalOtpDeviceModel {
};
open(callback) {
this._open(callback, true);
}
_open(callback, canRetry) {
this.openProcess = Launcher.spawn({
cmd: 'ykman',
args: ['oath', 'code'],
noStdOutLogging: true,
complete: (err, stdout, code) => {
complete: (err, stdout, code, stderr) => {
this.openProcess = null;
if (this.openAborted) {
err = 'Open aborted';
return callback('Open aborted');
}
const isStuck =
code === 2 && stderr && stderr.includes('Make sure the application');
if (isStuck && canRetry) {
this.openProcess = Launcher.spawn({
cmd: 'ykman',
args: ['config', 'usb', '-e', 'oath', '-f'],
noStdOutLogging: true,
complete: err => {
if (err) {
return callback(err);
}
this._open(callback, false);
}
});
return;
}
if (err) {
return callback(err);