From 78ae0f8c5975994f8920c6bf18c44ec878dcfbcb Mon Sep 17 00:00:00 2001 From: Dag Heyman Date: Thu, 3 Aug 2017 12:24:32 +0200 Subject: [PATCH] Add error message for too large keys in slot mode Closes #171 --- py/yubikey.py | 3 +-- qml/AddCredentialSlot.qml | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/py/yubikey.py b/py/yubikey.py index 2e6da5fe..d923dcbd 100644 --- a/py/yubikey.py +++ b/py/yubikey.py @@ -191,8 +191,7 @@ class Controller(object): if len(key) > 64: # Keys longer than 64 bytes are hashed. key = hashlib.sha1(key).digest() if len(key) > 20: - raise ValueError( - 'YubiKey Slots cannot handle TOTP keys over 20 bytes.') + return 'Over 20 bytes' key += b'\x00' * (20 - len(key)) # Keys must be padded to 20 bytes. dev.driver.program_chalresp(int(slot), key, touch) diff --git a/qml/AddCredentialSlot.qml b/qml/AddCredentialSlot.qml index 4d2da7e6..56e8f4da 100644 --- a/qml/AddCredentialSlot.qml +++ b/qml/AddCredentialSlot.qml @@ -115,6 +115,14 @@ DefaultDialog { standardButtons: StandardButton.Ok } + MessageDialog { + id: tooLargeKeyError + icon: StandardIcon.Critical + title: qsTr("Too large key") + text: qsTr("YubiKey Slots cannot handle TOTP keys over 20 bytes.") + standardButtons: StandardButton.Ok + } + MessageDialog { id: confirmOverWrite icon: StandardIcon.Warning @@ -160,6 +168,9 @@ DefaultDialog { if (error === 'Incorrect padding') { paddingError.open() } + if (error === 'Over 20 bytes') { + tooLargeKeyError.open() + } if (error) { console.log(error) }