diff options
author | Nicolas Norvez <norvez@chromium.org> | 2018-09-19 18:41:06 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-09-21 00:51:00 -0700 |
commit | 6e410ccca37239c12b9c5317c8a112e6fba2b0a2 (patch) | |
tree | 6872941a39467379b21787be16a675de24f9a28b /common | |
parent | ae38c0935bd0fd202a18b914a9c2c34670c79279 (diff) | |
download | chrome-ec-6e410ccca37239c12b9c5317c8a112e6fba2b0a2.tar.gz |
fpsensor: add a version to the template format
The first 2 bytes of the metadata structure contain the version of the
format of that structure.
BRANCH=nocturne
BUG=b:73337313
TEST=enroll/logout/unlock
Change-Id: I1838791603df11fdefb373105617f83eec116f89
Signed-off-by: Nicolas Norvez <norvez@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1235413
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/fpsensor.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/common/fpsensor.c b/common/fpsensor.c index 2e12930876..9a634a58b7 100644 --- a/common/fpsensor.c +++ b/common/fpsensor.c @@ -42,6 +42,7 @@ #define FP_MAX_FINGER_COUNT 0 #endif #define SBP_ENC_KEY_LEN 16 +#define FP_TEMPLATE_FORMAT_VERSION 1 #define FP_ALGORITHM_ENCRYPTED_TEMPLATE_SIZE \ (FP_ALGORITHM_TEMPLATE_SIZE + \ sizeof(struct ec_fp_template_encryption_metadata)) @@ -106,6 +107,8 @@ static timestamp_t overall_t0; static uint8_t timestamps_invalid; static int8_t template_matched; +BUILD_ASSERT(sizeof(struct ec_fp_template_encryption_metadata) % 4 == 0); + /* Interrupt line from the fingerprint sensor */ void fps_event(enum gpio_signal signal) { @@ -576,6 +579,7 @@ static int fp_command_frame(struct host_cmd_handler_args *args) memset(fp_enc_buffer, 0, sizeof(fp_enc_buffer)); /* The beginning of the buffer contains nonce/salt/tag. */ enc_info = (void *)fp_enc_buffer; + enc_info->struct_version = FP_TEMPLATE_FORMAT_VERSION; init_trng(); rand_bytes(enc_info->nonce, FP_CONTEXT_NONCE_BYTES); rand_bytes(enc_info->salt, FP_CONTEXT_SALT_BYTES); @@ -622,6 +626,16 @@ static int fp_command_stats(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_FP_STATS, fp_command_stats, EC_VER_MASK(0)); +static int validate_template_format( + struct ec_fp_template_encryption_metadata *enc_info) +{ + if (enc_info->struct_version != FP_TEMPLATE_FORMAT_VERSION) { + CPRINTS("Invalid template format %d", enc_info->struct_version); + return EC_RES_INVALID_PARAM; + } + return EC_RES_SUCCESS; +} + static int fp_command_template(struct host_cmd_handler_args *args) { const struct ec_params_fp_template *params = args->params; @@ -650,6 +664,11 @@ static int fp_command_template(struct host_cmd_handler_args *args) fp_clear_finger_context(idx); /* The beginning of the buffer contains nonce/salt/tag. */ enc_info = (void *)fp_enc_buffer; + ret = validate_template_format(enc_info); + if (ret != EC_RES_SUCCESS) { + CPRINTS("fgr%d: Template format not supported", idx); + return EC_RES_INVALID_PARAM; + } ret = derive_encryption_key(key, enc_info->salt); if (ret != EC_RES_SUCCESS) { CPRINTS("fgr%d: Failed to derive key", idx); |