From 7ceca60bf581398bd351b8bfee7f5e0854f74018 Mon Sep 17 00:00:00 2001 From: Dennis Fokin Date: Fri, 21 May 2021 08:50:18 +0200 Subject: [PATCH] Changes to bio add, delete, list --- py/yubikey.py | 49 ++++++++++++++++++++++------------ qml/SettingsPanelBioAdd.qml | 16 ++++++++--- qml/SettingsPanelBioDelete.qml | 7 ++++- qml/SettingsPanelBioList.qml | 1 - 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/py/yubikey.py b/py/yubikey.py index e95ff872..3f96cbd5 100644 --- a/py/yubikey.py +++ b/py/yubikey.py @@ -153,6 +153,12 @@ class Controller(object): _state = None + _enroller = None + _template_id = None + _remaining = None + _bio = None + _conn = None + def __init__(self): self.settings = Settings('oath') @@ -931,27 +937,35 @@ class Controller(object): def bio_enroll(self, pin, name): try: - with self._open_device([FidoConnection]) as conn: - ctap2 = Ctap2(conn) + if self._conn is None: + self._conn = self._open_device([FidoConnection]) + if self._enroller is None : + ctap2 = Ctap2(self._conn) client_pin = ClientPin(ctap2) token = client_pin.get_pin_token(pin, ClientPin.PERMISSION.BIO_ENROLL) - bio = FPBioEnrollment(ctap2, client_pin.protocol, token) + self._bio = FPBioEnrollment(ctap2, client_pin.protocol, token) - enroller = bio.enroll() - template_id = None - while template_id is None: - try: - logger.debug("Place your finger against the sensor now...") - template_id = enroller.capture() - remaining = enroller.remaining - if remaining: - logger.debug(f"{remaining} more scans needed.") - except: - logger.debug("Failed to capture") - logger.debug("Capture complete.") - bio.set_name(template_id, name) - return success() + self._enroller = self._bio.enroll() + self._template_id = None + if self._template_id is None: + try: + + logger.debug("Place your finger against the sensor now...") + self._template_id = self._enroller.capture() + self._remaining = self._enroller.remaining + if self._remaining: + logger.debug(f"{self._remaining} more scans needed.") + return success({'remaining': self._remaining}) + except: + logger.debug("Failed to capture") + logger.debug(f"{self._remaining} more scans needed.") + return failure(self._remaining) + logger.debug("Capture complete.") + self._bio.set_name(self._template_id, name) + self._conn.close() + return success() except CtapError as e: + self._conn.close() if e.code == CtapError.ERR.PIN_AUTH_BLOCKED: return failure('PIN authentication is currently blocked. ' 'Remove and re-insert the YubiKey.') @@ -983,6 +997,7 @@ class Controller(object): f"Multiple matches for NAME={template_id}. " "Delete by template ID instead." ) + return failure("multiple_matches") key = matches[0] name = enrollments[key] diff --git a/qml/SettingsPanelBioAdd.qml b/qml/SettingsPanelBioAdd.qml index 51ef9a86..f7f59a99 100644 --- a/qml/SettingsPanelBioAdd.qml +++ b/qml/SettingsPanelBioAdd.qml @@ -32,10 +32,20 @@ StyledExpansionPanel { function enroll() { yubiKey.bioEnroll(currentPinField.text, nameField.text, function (resp) { if (resp.success) { - navigator.goToSettings() - navigator.snackBar(qsTr("Fingerprint added")) + if (resp.remaining > 0) { + console.log("success") + enroll() + } else { + + navigator.goToSettings() + navigator.snackBar(qsTr("Fingerprint added")) + } } else { - navigator.snackBarError(qsTr("Fingerprint not added")) + if (resp.error_id > 0) { + console.log("fail") + enroll() + } + //navigator.snackBarError(qsTr("Fingerprint not added")) } }) } diff --git a/qml/SettingsPanelBioDelete.qml b/qml/SettingsPanelBioDelete.qml index 14d2ea7e..7107f052 100644 --- a/qml/SettingsPanelBioDelete.qml +++ b/qml/SettingsPanelBioDelete.qml @@ -34,7 +34,12 @@ StyledExpansionPanel { navigator.goToSettings() navigator.snackBar(qsTr("Fingerprint deleted")) } else { - navigator.snackBarError(qsTr("Fingerprint not deleted")) + if (resp.error_id === "multiple_matches") { + navigator.snackBarError(qsTr("Multiple matches. Delete by template ID instead")) + } else { + + navigator.snackBarError(qsTr("Fingerprint not deleted")) + } } }) } diff --git a/qml/SettingsPanelBioList.qml b/qml/SettingsPanelBioList.qml index feeb6303..8bab5969 100644 --- a/qml/SettingsPanelBioList.qml +++ b/qml/SettingsPanelBioList.qml @@ -17,7 +17,6 @@ StyledExpansionPanel { StyledButton { id: applyField text: qsTr("List") - enabled: nameField.text.length > 15 ? false : true onClicked: yubiKey.fidoList(currentPinField.text) }