Changes to bio add, delete, list

This commit is contained in:
Dennis Fokin 2021-05-21 08:50:18 +02:00
parent ddfb079d07
commit 7ceca60bf5
No known key found for this signature in database
GPG Key ID: 870B88256690D8BC
4 changed files with 51 additions and 22 deletions

View File

@ -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:
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...")
template_id = enroller.capture()
remaining = enroller.remaining
if remaining:
logger.debug(f"{remaining} more scans needed.")
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.")
bio.set_name(template_id, name)
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]

View File

@ -32,10 +32,20 @@ StyledExpansionPanel {
function enroll() {
yubiKey.bioEnroll(currentPinField.text, nameField.text, function (resp) {
if (resp.success) {
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"))
}
})
}

View File

@ -34,8 +34,13 @@ StyledExpansionPanel {
navigator.goToSettings()
navigator.snackBar(qsTr("Fingerprint deleted"))
} else {
if (resp.error_id === "multiple_matches") {
navigator.snackBarError(qsTr("Multiple matches. Delete by template ID instead"))
} else {
navigator.snackBarError(qsTr("Fingerprint not deleted"))
}
}
})
}
}

View File

@ -17,7 +17,6 @@ StyledExpansionPanel {
StyledButton {
id: applyField
text: qsTr("List")
enabled: nameField.text.length > 15 ? false : true
onClicked: yubiKey.fidoList(currentPinField.text)
}