blob: 9150e708bc2aa0f9c0498188fd4c4d47d7d87d71 [file] [log] [blame]
Andres Morales3b48ae52015-01-29 10:53:19 -08001/*
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 Morales6c560c02015-03-19 18:58:58 -070017#ifndef ANDROID_HARDWARE_GATEKEEPER_H
18#define ANDROID_HARDWARE_GATEKEEPER_H
Andres Morales3b48ae52015-01-29 10:53:19 -080019
20#include <sys/cdefs.h>
21#include <sys/types.h>
22#include <hardware/hardware.h>
23
24__BEGIN_DECLS
25
Andres Morales6c560c02015-03-19 18:58:58 -070026#define GATEKEEPER_HARDWARE_MODULE_ID "gatekeeper"
Andres Morales3b48ae52015-01-29 10:53:19 -080027
Andres Morales6c560c02015-03-19 18:58:58 -070028#define GATEKEEPER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
Andres Morales3b48ae52015-01-29 10:53:19 -080029
Andres Morales6c560c02015-03-19 18:58:58 -070030#define HARDWARE_GATEKEEPER "gatekeeper"
Andres Morales3b48ae52015-01-29 10:53:19 -080031
Andres Morales6c560c02015-03-19 18:58:58 -070032struct gatekeeper_module {
Andres Morales3b48ae52015-01-29 10:53:19 -080033 /**
Andres Morales6c560c02015-03-19 18:58:58 -070034 * 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 Morales3b48ae52015-01-29 10:53:19 -080037 */
38 hw_module_t common;
39};
40
Andres Morales6c560c02015-03-19 18:58:58 -070041struct gatekeeper_device {
Andres Morales3b48ae52015-01-29 10:53:19 -080042 /**
Andres Morales6c560c02015-03-19 18:58:58 -070043 * Common methods of the gatekeeper device. As above, this must be the first
Andres Morales3b48ae52015-01-29 10:53:19 -080044 * member of keymaster_device.
45 */
46 hw_device_t common;
47
48 /**
Andres Morales8fa2fb72015-03-19 08:40:41 -070049 * Enrolls desired_password, which should be derived from a user selected pin or password,
Andres Morales3b48ae52015-01-29 10:53:19 -080050 * with the authentication factor private key used only for enrolling authentication
51 * factor data.
52 *
Andres Morales8fa2fb72015-03-19 08:40:41 -070053 * 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 Morales3b48ae52015-01-29 10:53:19 -080057 * Returns: 0 on success or an error code less than 0 on error.
58 * On error, enrolled_password_handle will not be allocated.
59 */
Andres Morales6c560c02015-03-19 18:58:58 -070060 int (*enroll)(const struct gatekeeper_device *dev, uint32_t uid,
Andres Morales8fa2fb72015-03-19 08:40:41 -070061 const uint8_t *current_password_handle, size_t current_password_handle_length,
62 const uint8_t *current_password, size_t current_password_length,
63 const uint8_t *desired_password, size_t desired_password_length,
Andres Moralese956a292015-02-05 10:49:58 -080064 uint8_t **enrolled_password_handle, size_t *enrolled_password_handle_length);
Andres Morales3b48ae52015-01-29 10:53:19 -080065
66 /**
67 * Verifies provided_password matches enrolled_password_handle.
68 *
69 * Implementations of this module may retain the result of this call
70 * to attest to the recency of authentication.
71 *
Andres Morales8fa2fb72015-03-19 08:40:41 -070072 * On success, writes the address of a verification token to auth_token,
Andres Morales3b48ae52015-01-29 10:53:19 -080073 * usable to attest password verification to other trusted services. Clients
74 * may pass NULL for this value.
75 *
76 * Returns: 0 on success or an error code less than 0 on error
77 * On error, verification token will not be allocated
78 */
Andres Morales6c560c02015-03-19 18:58:58 -070079 int (*verify)(const struct gatekeeper_device *dev, uint32_t uid,
Andres Moralese956a292015-02-05 10:49:58 -080080 const uint8_t *enrolled_password_handle, size_t enrolled_password_handle_length,
81 const uint8_t *provided_password, size_t provided_password_length,
Andres Morales8fa2fb72015-03-19 08:40:41 -070082 uint8_t **auth_token, size_t *auth_token_length);
Andres Morales3b48ae52015-01-29 10:53:19 -080083
84};
Andres Morales6c560c02015-03-19 18:58:58 -070085typedef struct gatekeeper_device gatekeeper_device_t;
Andres Morales3b48ae52015-01-29 10:53:19 -080086
Andres Morales6c560c02015-03-19 18:58:58 -070087static inline int gatekeeper_open(const struct hw_module_t *module,
88 gatekeeper_device_t **device) {
89 return module->methods->open(module, HARDWARE_GATEKEEPER,
Andres Morales3b48ae52015-01-29 10:53:19 -080090 (struct hw_device_t **) device);
91}
92
Andres Morales6c560c02015-03-19 18:58:58 -070093static inline int gatekeeper_close(gatekeeper_device_t *device) {
Andres Morales3b48ae52015-01-29 10:53:19 -080094 return device->common.close(&device->common);
95}
96
97__END_DECLS
98
Andres Morales6c560c02015-03-19 18:58:58 -070099#endif // ANDROID_HARDWARE_GATEKEEPER_H