diff --git a/app/scripts/comp/app/chal-resp-calculator.js b/app/scripts/comp/app/chal-resp-calculator.js index 44713cf5..675d3c1b 100644 --- a/app/scripts/comp/app/chal-resp-calculator.js +++ b/app/scripts/comp/app/chal-resp-calculator.js @@ -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); }); diff --git a/app/scripts/comp/app/yubikey.js b/app/scripts/comp/app/yubikey.js index f5e61d41..7730d685 100644 --- a/app/scripts/comp/app/yubikey.js +++ b/app/scripts/comp/app/yubikey.js @@ -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); diff --git a/app/styles/areas/_open.scss b/app/styles/areas/_open.scss index 1c8620d1..d4c870a7 100644 --- a/app/styles/areas/_open.scss +++ b/app/styles/areas/_open.scss @@ -252,7 +252,8 @@ &-yubikey { display: none; - &--present { + &--present, + &--active { display: flex; } &__text {