From 835d96eae59aefeaa32fda3218246db51bf22fab Mon Sep 17 00:00:00 2001 From: Andres Morales Date: Wed, 3 Jun 2015 15:06:24 -0700 Subject: [PATCH] [gatekeeperd] handle upgrades from software version to HAL Certain devices, like Shamu, are currently running an interim software-only gatekeeper. When the HAL for those devices is merged, we need to handle upgrading to the HAL smoothly. Bug: 21090356 Change-Id: I5352bc547a43671a08249eae532e8b3ce6b90087 --- gatekeeperd/gatekeeperd.cpp | 40 +++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/gatekeeperd/gatekeeperd.cpp b/gatekeeperd/gatekeeperd.cpp index c0f227929..adfec1ecc 100644 --- a/gatekeeperd/gatekeeperd.cpp +++ b/gatekeeperd/gatekeeperd.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include // For error code @@ -119,8 +120,19 @@ public: int ret; if (device) { - ret = device->enroll(device, uid, - current_password_handle, current_password_handle_length, + const gatekeeper::password_handle_t *handle = + reinterpret_cast(current_password_handle); + + if (handle != NULL && !handle->hardware_backed) { + // handle is being re-enrolled from a software version. HAL probably won't accept + // the handle as valid, so we nullify it and enroll from scratch + current_password_handle = NULL; + current_password_handle_length = 0; + current_password = NULL; + current_password_length = 0; + } + + ret = device->enroll(device, uid, current_password_handle, current_password_handle_length, current_password, current_password_length, desired_password, desired_password_length, enrolled_password_handle, enrolled_password_handle_length); @@ -174,10 +186,26 @@ public: int ret; if (device) { - ret = device->verify(device, uid, challenge, - enrolled_password_handle, enrolled_password_handle_length, - provided_password, provided_password_length, auth_token, auth_token_length, - request_reenroll); + const gatekeeper::password_handle_t *handle = + reinterpret_cast(enrolled_password_handle); + if (handle->hardware_backed) { + ret = device->verify(device, uid, challenge, + enrolled_password_handle, enrolled_password_handle_length, + provided_password, provided_password_length, auth_token, auth_token_length, + request_reenroll); + } else { + // upgrade scenario, a HAL has been added to this device where there was none before + SoftGateKeeperDevice soft_dev; + ret = soft_dev.verify(uid, challenge, + enrolled_password_handle, enrolled_password_handle_length, + provided_password, provided_password_length, auth_token, auth_token_length, + request_reenroll); + + if (ret == 0) { + // success! re-enroll with HAL + *request_reenroll = true; + } + } } else { ret = soft_device->verify(uid, challenge, enrolled_password_handle, enrolled_password_handle_length,