Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HARDWARE_GATEKEEPER_H |
| 18 | #define ANDROID_HARDWARE_GATEKEEPER_H |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 19 | |
| 20 | #include <sys/cdefs.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <hardware/hardware.h> |
| 23 | |
| 24 | __BEGIN_DECLS |
| 25 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 26 | #define GATEKEEPER_HARDWARE_MODULE_ID "gatekeeper" |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 27 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 28 | #define GATEKEEPER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 29 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 30 | #define HARDWARE_GATEKEEPER "gatekeeper" |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 31 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 32 | struct gatekeeper_module { |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 33 | /** |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 34 | * Comon methods of the gatekeeper module. This *must* be the first member of |
| 35 | * gatekeeper_module as users of this structure will cast a hw_module_t to |
| 36 | * a gatekeeper_module pointer in the appropriate context. |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 37 | */ |
| 38 | hw_module_t common; |
| 39 | }; |
| 40 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 41 | struct gatekeeper_device { |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 42 | /** |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 43 | * Common methods of the gatekeeper device. As above, this must be the first |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 44 | * member of keymaster_device. |
| 45 | */ |
| 46 | hw_device_t common; |
| 47 | |
| 48 | /** |
Andres Morales | 8fa2fb7 | 2015-03-19 08:40:41 -0700 | [diff] [blame] | 49 | * Enrolls desired_password, which should be derived from a user selected pin or password, |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 50 | * with the authentication factor private key used only for enrolling authentication |
| 51 | * factor data. |
| 52 | * |
Andres Morales | 8fa2fb7 | 2015-03-19 08:40:41 -0700 | [diff] [blame] | 53 | * If there was already a password enrolled, it should be provided in |
| 54 | * current_password_handle, along with the current password in current_password |
| 55 | * that should validate against current_password_handle. |
| 56 | * |
Andres Morales | 25503bd | 2015-03-30 16:51:50 -0700 | [diff] [blame^] | 57 | * Parameters: |
| 58 | * - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open |
| 59 | * - uid: the Android user identifier |
| 60 | * |
| 61 | * - current_password_handle: the currently enrolled password handle the user |
| 62 | * wants to replace. May be null if there's no currently enrolled password. |
| 63 | * - current_password_handle_length: the length in bytes of the buffer pointed |
| 64 | * at by current_password_handle. Must be 0 if current_password_handle is NULL. |
| 65 | * |
| 66 | * - current_password: the user's current password in plain text. If presented, |
| 67 | * it MUST verify against current_password_handle. |
| 68 | * - current_password_length: the size in bytes of the buffer pointed at by |
| 69 | * current_password. Must be 0 if the current_password is NULL. |
| 70 | * |
| 71 | * - desired_password: the new password the user wishes to enroll in plain-text. |
| 72 | * Cannot be NULL. |
| 73 | * - desired_password_length: the length in bytes of the buffer pointed at by |
| 74 | * desired_password. |
| 75 | * |
| 76 | * - enrolled_password_handle: on success, a buffer will be allocated with the |
| 77 | * new password handle referencing the password provided in desired_password. |
| 78 | * This buffer can be used on subsequent calls to enroll or verify. |
| 79 | * The caller is responsible for deallocating this buffer via a call to free() |
| 80 | * - enrolled_password_handle_length: pointer to the length in bytes of the buffer allocated |
| 81 | * by this function and pointed to by *enrolled_password_handle_length. |
| 82 | * |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 83 | * Returns: 0 on success or an error code less than 0 on error. |
| 84 | * On error, enrolled_password_handle will not be allocated. |
| 85 | */ |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 86 | int (*enroll)(const struct gatekeeper_device *dev, uint32_t uid, |
Andres Morales | 25503bd | 2015-03-30 16:51:50 -0700 | [diff] [blame^] | 87 | const uint8_t *current_password_handle, uint32_t current_password_handle_length, |
| 88 | const uint8_t *current_password, uint32_t current_password_length, |
| 89 | const uint8_t *desired_password, uint32_t desired_password_length, |
| 90 | uint8_t **enrolled_password_handle, uint32_t *enrolled_password_handle_length); |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Verifies provided_password matches enrolled_password_handle. |
| 94 | * |
| 95 | * Implementations of this module may retain the result of this call |
| 96 | * to attest to the recency of authentication. |
| 97 | * |
Andres Morales | 8fa2fb7 | 2015-03-19 08:40:41 -0700 | [diff] [blame] | 98 | * On success, writes the address of a verification token to auth_token, |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 99 | * usable to attest password verification to other trusted services. Clients |
| 100 | * may pass NULL for this value. |
| 101 | * |
Andres Morales | 25503bd | 2015-03-30 16:51:50 -0700 | [diff] [blame^] | 102 | * Parameters: |
| 103 | * - dev: pointer to gatekeeper_device acquired via calls to gatekeeper_open |
| 104 | * - uid: the Android user identifier |
| 105 | * |
| 106 | * - enrolled_password_handle: the currently enrolled password handle that the |
| 107 | * user wishes to verify against. |
| 108 | * - enrolled_password_handle_length: the length in bytes of the buffer pointed |
| 109 | * to by enrolled_password_handle |
| 110 | * |
| 111 | * - provided_password: the plaintext password to be verified against the |
| 112 | * enrolled_password_handle |
| 113 | * - provided_password_length: the length in bytes of the buffer pointed to by |
| 114 | * provided_password |
| 115 | * |
| 116 | * - auth_token: on success, a buffer containing the authentication token |
| 117 | * resulting from this verification is assigned to *auth_token. The caller |
| 118 | * is responsible for deallocating this memory via a call to free() |
| 119 | * - auth_token_length: on success, the length in bytes of the authentication |
| 120 | * token assigned to *auth_token will be assigned to *auth_token_length |
| 121 | * |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 122 | * Returns: 0 on success or an error code less than 0 on error |
Andres Morales | 25503bd | 2015-03-30 16:51:50 -0700 | [diff] [blame^] | 123 | * On error, auth token will not be allocated |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 124 | */ |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 125 | int (*verify)(const struct gatekeeper_device *dev, uint32_t uid, |
Andres Morales | 25503bd | 2015-03-30 16:51:50 -0700 | [diff] [blame^] | 126 | const uint8_t *enrolled_password_handle, uint32_t enrolled_password_handle_length, |
| 127 | const uint8_t *provided_password, uint32_t provided_password_length, |
| 128 | uint8_t **auth_token, uint32_t *auth_token_length); |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 129 | |
| 130 | }; |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 131 | typedef struct gatekeeper_device gatekeeper_device_t; |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 132 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 133 | static inline int gatekeeper_open(const struct hw_module_t *module, |
| 134 | gatekeeper_device_t **device) { |
| 135 | return module->methods->open(module, HARDWARE_GATEKEEPER, |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 136 | (struct hw_device_t **) device); |
| 137 | } |
| 138 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 139 | static inline int gatekeeper_close(gatekeeper_device_t *device) { |
Andres Morales | 3b48ae5 | 2015-01-29 10:53:19 -0800 | [diff] [blame] | 140 | return device->common.close(&device->common); |
| 141 | } |
| 142 | |
| 143 | __END_DECLS |
| 144 | |
Andres Morales | 6c560c0 | 2015-03-19 18:58:58 -0700 | [diff] [blame] | 145 | #endif // ANDROID_HARDWARE_GATEKEEPER_H |