verify/enroll: Save and use locally saved prints also for devices with storage
Some devices have storage but that's is limited enough not to be able to store all the metadata, but just a fingerprint id. In such case we also need to use the local storage to be able to verify. Fprintd does this already, but we don't do it in the libfprint examples. So, in in case we enroll, always save the print information to the disk, while in case we verify we try to load the print from disk and we use that in case its private data matches the one provided by the device.
This commit is contained in:
parent
0c56e0de6d
commit
3b993fabb6
2 changed files with 46 additions and 19 deletions
|
@ -76,15 +76,19 @@ on_enroll_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||
{
|
||||
enroll_data->ret_value = EXIT_SUCCESS;
|
||||
|
||||
if (!fp_device_has_storage (dev))
|
||||
if (fp_device_has_storage (dev))
|
||||
g_debug ("Device has storage, saving a print reference locally");
|
||||
else
|
||||
g_debug ("Device has not storage, saving print only locally");
|
||||
|
||||
/* Even if the device has storage, it may not be able to save all the
|
||||
* metadata that the print contains, so we can always save a local copy
|
||||
* containing the handle to the device print */
|
||||
int r = print_data_save (print, enroll_data->finger);
|
||||
if (r < 0)
|
||||
{
|
||||
g_debug ("Device has not storage, saving locally");
|
||||
int r = print_data_save (print, enroll_data->finger);
|
||||
if (r < 0)
|
||||
{
|
||||
g_warning ("Data save failed, code %d", r);
|
||||
enroll_data->ret_value = EXIT_FAILURE;
|
||||
}
|
||||
g_warning ("Data save failed, code %d", r);
|
||||
enroll_data->ret_value = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -152,6 +152,26 @@ on_match_cb (FpDevice *dev, FpPrint *match, FpPrint *print,
|
|||
}
|
||||
}
|
||||
|
||||
static FpPrint *
|
||||
get_stored_print (FpDevice *dev, VerifyData *verify_data)
|
||||
{
|
||||
FpPrint *verify_print;
|
||||
|
||||
g_print ("Loading previously enrolled %s finger data...\n",
|
||||
finger_to_string (verify_data->finger));
|
||||
|
||||
verify_print = print_data_load (dev, verify_data->finger);
|
||||
|
||||
if (!verify_print)
|
||||
{
|
||||
g_warning ("Failed to load fingerprint data");
|
||||
g_warning ("Did you remember to enroll your %s finger first?",
|
||||
finger_to_string (verify_data->finger));
|
||||
}
|
||||
|
||||
return verify_print;
|
||||
}
|
||||
|
||||
static void
|
||||
on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
|
@ -165,15 +185,27 @@ on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
|
|||
if (!error)
|
||||
{
|
||||
FpPrint *verify_print = NULL;
|
||||
g_autoptr(FpPrint) stored_print = NULL;
|
||||
guint i;
|
||||
|
||||
if (!prints->len)
|
||||
g_warning ("No prints saved on device");
|
||||
{
|
||||
g_warning ("No prints saved on device");
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
||||
stored_print = get_stored_print (dev, verify_data);
|
||||
|
||||
for (i = 0; i < prints->len; ++i)
|
||||
{
|
||||
FpPrint *print = prints->pdata[i];
|
||||
|
||||
if (stored_print && fp_print_equal (stored_print, print))
|
||||
/* If the private print data matches, let's use the stored print
|
||||
* as it contains more metadata to show */
|
||||
print = stored_print;
|
||||
|
||||
if (fp_print_get_finger (print) == verify_data->finger &&
|
||||
g_strcmp0 (fp_print_get_username (print), g_get_user_name ()) == 0)
|
||||
{
|
||||
|
@ -191,8 +223,6 @@ on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
|
|||
|
||||
if (!verify_print)
|
||||
{
|
||||
g_warning ("Did you remember to enroll your %s finger first?",
|
||||
finger_to_string (verify_data->finger));
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
@ -239,17 +269,10 @@ start_verification (FpDevice *dev, VerifyData *verify_data)
|
|||
}
|
||||
else
|
||||
{
|
||||
g_print ("Loading previously enrolled %s finger data...\n",
|
||||
finger_to_string (verify_data->finger));
|
||||
g_autoptr(FpPrint) verify_print = NULL;
|
||||
|
||||
verify_print = print_data_load (dev, verify_data->finger);
|
||||
g_autoptr(FpPrint) verify_print = get_stored_print (dev, verify_data);
|
||||
|
||||
if (!verify_print)
|
||||
{
|
||||
g_warning ("Failed to load fingerprint data");
|
||||
g_warning ("Did you remember to enroll your %s finger first?",
|
||||
finger_to_string (verify_data->finger));
|
||||
verify_quit (dev, verify_data);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue