fixed challenge-response calculation with padding

This commit is contained in:
antelle 2020-05-31 16:35:36 +02:00
parent a4b22b6c88
commit 176553a674
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 16 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import { Logger } from 'util/logger';
import { UsbListener } from 'comp/app/usb-listener';
import { AppSettingsModel } from 'models/app-settings-model';
import { Timeouts } from 'const/timeouts';
import { YubiKeyProductIds } from 'const/hardware';
import { YubiKeyProductIds, YubiKeyChallengeSize } from 'const/hardware';
import { Locale } from 'util/locale';
const logger = new Logger('yubikey');
@ -250,7 +250,18 @@ const YubiKey = {
calculateChalResp(chalResp, challenge, callback) {
const { vid, pid, serial, slot } = chalResp;
const yubiKey = { vid, pid, serial };
this.ykChalResp.challengeResponse(yubiKey, challenge, slot, (err, response) => {
challenge = Buffer.from(challenge);
// https://github.com/Yubico/yubikey-personalization-gui/issues/86
// https://github.com/keepassxreboot/keepassxc/blob/develop/src/keys/drivers/YubiKey.cpp#L318
const padLen = YubiKeyChallengeSize - challenge.byteLength;
const paddedChallenge = Buffer.alloc(YubiKeyChallengeSize, padLen);
challenge.copy(paddedChallenge);
this.ykChalResp.challengeResponse(yubiKey, paddedChallenge, slot, (err, response) => {
if (err) {
if (err.code === this.ykChalResp.YK_ENOKEY) {
err.noKey = true;

View File

@ -9,4 +9,6 @@ const YubiKeyProductIds = {
YK4: [0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407]
};
export { YubiKeyVendorId, YubiKeyProductIds };
const YubiKeyChallengeSize = 64;
export { YubiKeyVendorId, YubiKeyProductIds, YubiKeyChallengeSize };