Add error message for too large keys in slot mode

Closes #171
This commit is contained in:
Dag Heyman 2017-08-03 12:24:32 +02:00
parent c373419f9f
commit 78ae0f8c59
No known key found for this signature in database
GPG Key ID: 06FC004369E7D338
2 changed files with 12 additions and 2 deletions

View File

@ -191,8 +191,7 @@ class Controller(object):
if len(key) > 64: # Keys longer than 64 bytes are hashed. if len(key) > 64: # Keys longer than 64 bytes are hashed.
key = hashlib.sha1(key).digest() key = hashlib.sha1(key).digest()
if len(key) > 20: if len(key) > 20:
raise ValueError( return 'Over 20 bytes'
'YubiKey Slots cannot handle TOTP keys over 20 bytes.')
key += b'\x00' * (20 - len(key)) # Keys must be padded to 20 bytes. key += b'\x00' * (20 - len(key)) # Keys must be padded to 20 bytes.
dev.driver.program_chalresp(int(slot), key, touch) dev.driver.program_chalresp(int(slot), key, touch)

View File

@ -115,6 +115,14 @@ DefaultDialog {
standardButtons: StandardButton.Ok 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 { MessageDialog {
id: confirmOverWrite id: confirmOverWrite
icon: StandardIcon.Warning icon: StandardIcon.Warning
@ -160,6 +168,9 @@ DefaultDialog {
if (error === 'Incorrect padding') { if (error === 'Incorrect padding') {
paddingError.open() paddingError.open()
} }
if (error === 'Over 20 bytes') {
tooLargeKeyError.open()
}
if (error) { if (error) {
console.log(error) console.log(error)
} }