From 4af3e59174bbb8737c4aa3f901212edc7d7a67ca Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Wed, 22 Apr 2020 18:24:09 +0200 Subject: [PATCH] uru4000: Always detect whether encryption is in use This is based on the patch and observation from Bastien that some URU4000B devices do not use encryption by default (it is a configuration stored within the firmware). As such, it makes sense to always detect whether encryption is in use by inspecting the image. The encryption option would disable flipping of the image for the URU400B device. Retain this behaviour for backward compatibility. --- libfprint/drivers/uru4000.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c index b86c6c8b..45dddd51 100644 --- a/libfprint/drivers/uru4000.c +++ b/libfprint/drivers/uru4000.c @@ -81,7 +81,7 @@ static const struct uru4k_dev_profile { const char *name; gboolean auth_cr; - gboolean encryption; + gboolean image_not_flipped; } uru4k_dev_info[] = { [MS_KBD] = { .name = "Microsoft Keyboard with Fingerprint Reader", @@ -106,7 +106,7 @@ static const struct uru4k_dev_profile [DP_URU4000B] = { .name = "Digital Persona U.are.U 4000B", .auth_cr = FALSE, - .encryption = TRUE, + .image_not_flipped = TRUE, /* See comment in the code where it is used. */ }, }; @@ -680,17 +680,17 @@ imaging_run_state (FpiSsm *ssm, FpDevice *_dev) fpi_ssm_jump_to_state (ssm, IMAGING_CAPTURE); return; } - if (!self->profile->encryption) + + /* Detect whether image is encrypted (by checking how noisy it is) */ + dev2 = calc_dev2 (img); + fp_dbg ("dev2: %d", dev2); + if (dev2 < ENC_THRESHOLD) { - dev2 = calc_dev2 (img); - fp_dbg ("dev2: %d", dev2); - if (dev2 < ENC_THRESHOLD) - { - fpi_ssm_jump_to_state (ssm, IMAGING_REPORT_IMAGE); - return; - } - fp_info ("image seems to be encrypted"); + fpi_ssm_jump_to_state (ssm, IMAGING_REPORT_IMAGE); + return; } + fp_info ("image seems to be encrypted"); + buf[0] = img->key_number; buf[1] = self->img_enc_seed; buf[2] = self->img_enc_seed >> 8; @@ -769,7 +769,13 @@ imaging_run_state (FpiSsm *ssm, FpDevice *_dev) } fpimg->flags = FPI_IMAGE_COLORS_INVERTED; - if (!self->profile->encryption) + /* NOTE: For some reason all but U4000B (or rather U4500?) flipped the + * image, we retain this behaviour here, but it is not clear whether it + * is correct. + * It may be that there are different models with the same USB ID that + * behave differently. + */ + if (self->profile->image_not_flipped) fpimg->flags |= FPI_IMAGE_V_FLIPPED | FPI_IMAGE_H_FLIPPED; fpi_image_device_image_captured (dev, fpimg);