Add cooldown period for HOTP creds

This commit is contained in:
Dag Heyman 2017-02-17 10:14:37 +01:00
parent 084191e467
commit f11d3874bb
No known key found for this signature in database
GPG Key ID: 06FC004369E7D338

View File

@ -17,6 +17,7 @@ ApplicationWindow {
property var credentials: device.credentials property var credentials: device.credentials
property bool validated: device.validated property bool validated: device.validated
property bool hasDevice: device.hasDevice property bool hasDevice: device.hasDevice
property var cooldowns: []
PasswordPrompt { PasswordPrompt {
id: passwordPrompt id: passwordPrompt
@ -34,7 +35,6 @@ ApplicationWindow {
onCredentialsChanged: { onCredentialsChanged: {
updateExpiration() updateExpiration()
touchYourYubikey.close() touchYourYubikey.close()
console.log('CREDENTIALS ', JSON.stringify(credentials))
} }
SystemPalette { SystemPalette {
@ -167,9 +167,18 @@ ApplicationWindow {
visible: repeater.selected != null visible: repeater.selected != null
&& (repeater.selected.oath_type === "hotp" && (repeater.selected.oath_type === "hotp"
|| repeater.selected.touch === true) || repeater.selected.touch === true)
enabled: repeater.selected != null && !isInCoolDown(repeater.selected.name)
text: qsTr('Generate code') text: qsTr('Generate code')
shortcut: "Space" shortcut: "Space"
onTriggered: calculateCredential(repeater.selected) onTriggered: {
if (!isInCoolDown(repeater.selected.name)) {
calculateCredential(repeater.selected)
if (repeater.selected.oath_type === "hotp") {
cooldowns.push(repeater.selected.name)
coolDownTimer.restart()
}
}
}
} }
MenuItem { MenuItem {
text: qsTr('Delete') text: qsTr('Delete')
@ -178,6 +187,12 @@ ApplicationWindow {
} }
} }
Timer {
id: coolDownTimer
interval: 5000
onTriggered: cooldowns = []
}
Item { Item {
id: arrowKeys id: arrowKeys
focus: true focus: true
@ -298,6 +313,7 @@ ApplicationWindow {
font.pointSize: 13 font.pointSize: 13
} }
Text { Text {
opacity: isInCoolDown(modelData.name) ? 0.6 : 1
visible: modelData.code != null visible: modelData.code != null
text: qsTr('') + modelData.code text: qsTr('') + modelData.code
font.family: "Verdana" font.family: "Verdana"
@ -416,6 +432,9 @@ ApplicationWindow {
return result return result
} }
function isInCoolDown(name) {
return cooldowns.indexOf(name) !== -1
}
function hasIssuer(name) { function hasIssuer(name) {
return name.indexOf(':') !== -1 return name.indexOf(':') !== -1
} }