fixed saved yubikeys

This commit is contained in:
antelle 2020-05-30 10:29:02 +02:00
parent b4fe0af53a
commit 51bd80faf4
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
3 changed files with 25 additions and 9 deletions

View File

@ -17,19 +17,35 @@ const ChalRespCalculator = {
challenge = Buffer.from(challenge);
const hexChallenge = challenge.toString('hex');
const key = `${params.vid}:${params.pid}:${params.serial}:${hexChallenge}`;
if (this.cache[key]) {
const deviceCacheKey = `${params.vid}:${params.pid}:${params.serial}`;
const respFromCache = this.cache[deviceCacheKey]?.[hexChallenge];
if (respFromCache) {
logger.debug('Found ChalResp in cache');
return resolve(Buffer.from(this.cache[key], 'hex'));
return resolve(Buffer.from(respFromCache, 'hex'));
}
logger.debug('Calculating ChalResp using a YubiKey');
logger.debug('Calculating ChalResp using a YubiKey', params);
YubiKey.calculateChalResp(params, challenge, (err, response) => {
if (err) {
if (err.noKey) {
logger.debug('No YubiKey');
// TODO
return;
}
if (err.touchRequested) {
logger.debug('YubiKey touch requested');
// TODO
return;
}
return reject(err);
}
this.cache[key] = response.toString('hex');
if (!this.cache[deviceCacheKey]) {
this.cache[deviceCacheKey] = {};
}
this.cache[deviceCacheKey][hexChallenge] = response.toString('hex');
logger.info('Calculated ChalResp', logger.ts(ts));
resolve(response);
});

View File

@ -252,10 +252,9 @@ const YubiKey = {
const yubiKey = { vid, pid, serial };
this.ykChalResp.challengeResponse(yubiKey, challenge, slot, (err, response) => {
if (err) {
if (err.touchRequested) {
return;
if (err.code === this.ykChalResp.YK_ENOKEY) {
err.noKey = true;
}
// TODO: handle touch and missing YubiKeys
return callback(err);
}
callback(null, response);

View File

@ -252,7 +252,8 @@
&-yubikey {
display: none;
&--present {
&--present,
&--active {
display: flex;
}
&__text {