mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-29 04:14:52 +03:00
Show padding error in GUI
This commit is contained in:
parent
b65653ace9
commit
075b421dd2
@ -101,9 +101,13 @@ class Controller(object):
|
||||
controller = OathController(dev.driver)
|
||||
if controller.locked and password_key is not None:
|
||||
controller.validate(a2b_hex(password_key))
|
||||
key = self._parse_key(key)
|
||||
try:
|
||||
key = self._parse_key(key)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
controller.put(key, name, oath_type, digits, algo=algo, require_touch=touch)
|
||||
|
||||
|
||||
def delete_credential(self, credential, password_key):
|
||||
dev = self._descriptor.open_device(TRANSPORT.CCID)
|
||||
controller = OathController(dev.driver)
|
||||
|
@ -8,7 +8,10 @@ Dialog {
|
||||
title: qsTr("Add credential")
|
||||
standardButtons: StandardButton.Save | StandardButton.Cancel
|
||||
modality: Qt.ApplicationModal
|
||||
onAccepted: { addCredential(); clear(); }
|
||||
onAccepted: {
|
||||
addCredential()
|
||||
clear()
|
||||
}
|
||||
onRejected: clear()
|
||||
|
||||
ColumnLayout {
|
||||
@ -18,7 +21,7 @@ Dialog {
|
||||
Layout.columnSpan: 2
|
||||
text: qsTr("Scan a QR code")
|
||||
Layout.fillWidth: true
|
||||
onClicked: device.parseQr(ScreenShot.capture(), updateForm);
|
||||
onClicked: device.parseQr(ScreenShot.capture(), updateForm)
|
||||
}
|
||||
Label {
|
||||
text: qsTr("Name")
|
||||
@ -127,6 +130,14 @@ Dialog {
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
id: paddingError
|
||||
icon: StandardIcon.Critical
|
||||
title: qsTr("Wrong padding")
|
||||
text: qsTr("The padding of the key is incorrect.")
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
|
||||
function clear() {
|
||||
name.text = ""
|
||||
key.text = ""
|
||||
@ -136,7 +147,6 @@ Dialog {
|
||||
touch.checked = false
|
||||
}
|
||||
|
||||
|
||||
function updateForm(uri) {
|
||||
if (uri) {
|
||||
key.text = uri.secret
|
||||
@ -158,7 +168,11 @@ Dialog {
|
||||
function addCredential() {
|
||||
device.addCredential(name.text, key.text, oathType.current.name,
|
||||
digits.current.digits, algorithm.current.name,
|
||||
touch.checked)
|
||||
touch.checked, function (error) {
|
||||
if (error === 'Incorrect padding') {
|
||||
paddingError.open()
|
||||
}
|
||||
})
|
||||
device.refreshCredentials()
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ ApplicationWindow {
|
||||
MenuItem {
|
||||
text: qsTr("Exit")
|
||||
onTriggered: Qt.quit()
|
||||
shortcut: StandardKey.Quit
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,8 @@ Python {
|
||||
}
|
||||
|
||||
onHasDeviceChanged: {
|
||||
device.passwordKey = null;
|
||||
device.validated = false;
|
||||
device.passwordKey = null
|
||||
device.validated = false
|
||||
}
|
||||
|
||||
onError: {
|
||||
@ -88,39 +88,41 @@ Python {
|
||||
}
|
||||
|
||||
function validate(providedPassword) {
|
||||
do_call('yubikey.controller.validate', [providedPassword], function(res) {
|
||||
if (res !== false) {
|
||||
passwordKey = res
|
||||
validated = true
|
||||
}
|
||||
if (res === false) {
|
||||
wrongPassword()
|
||||
}
|
||||
})
|
||||
do_call('yubikey.controller.validate', [providedPassword],
|
||||
function (res) {
|
||||
if (res !== false) {
|
||||
passwordKey = res
|
||||
validated = true
|
||||
}
|
||||
if (res === false) {
|
||||
wrongPassword()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function promptOrSkip(prompt){
|
||||
do_call('yubikey.controller.needs_validation', [], function(res) {
|
||||
function promptOrSkip(prompt) {
|
||||
do_call('yubikey.controller.needs_validation', [], function (res) {
|
||||
if (res === true) {
|
||||
prompt.open()
|
||||
}
|
||||
if (res === false) {
|
||||
validated = true
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function setPassword(password) {
|
||||
console.log('PROVIDED PW ', password)
|
||||
do_call('yubikey.controller.set_password', [password, passwordKey], function() {
|
||||
validate(password)
|
||||
})
|
||||
do_call('yubikey.controller.set_password', [password, passwordKey],
|
||||
function () {
|
||||
validate(password)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function refreshCredentials() {
|
||||
var now = Math.floor(Date.now() / 1000)
|
||||
do_call('yubikey.controller.refresh_credentials', [now, passwordKey], handleCredentials)
|
||||
do_call('yubikey.controller.refresh_credentials', [now, passwordKey],
|
||||
handleCredentials)
|
||||
}
|
||||
|
||||
function handleCredentials(creds) {
|
||||
@ -170,7 +172,8 @@ Python {
|
||||
|
||||
function calculate(credential) {
|
||||
var now = Math.floor(Date.now() / 1000)
|
||||
do_call('yubikey.controller.calculate', [credential, now, passwordKey], updateCredential)
|
||||
do_call('yubikey.controller.calculate', [credential, now, passwordKey],
|
||||
updateCredential)
|
||||
}
|
||||
|
||||
function updateCredential(cred) {
|
||||
@ -185,17 +188,18 @@ Python {
|
||||
credentials = result
|
||||
}
|
||||
|
||||
|
||||
function addCredential(name, key, oathType, digits, algorithm, touch) {
|
||||
function addCredential(name, key, oathType, digits, algorithm, touch, cb) {
|
||||
do_call('yubikey.controller.add_credential',
|
||||
[name, key, oathType, digits, algorithm, touch, passwordKey])
|
||||
[name, key, oathType, digits, algorithm, touch, passwordKey],
|
||||
cb)
|
||||
}
|
||||
|
||||
function deleteCredential(credential) {
|
||||
do_call('yubikey.controller.delete_credential', [credential, passwordKey])
|
||||
do_call('yubikey.controller.delete_credential',
|
||||
[credential, passwordKey])
|
||||
}
|
||||
|
||||
function parseQr(screenShots, cb){
|
||||
function parseQr(screenShots, cb) {
|
||||
do_call('yubikey.controller.parse_qr', [screenShots], cb)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user