1 /*
2  * Copyright 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 
17 #ifndef SOFT_GATEKEEPER_DEVICE_H_
18 #define SOFT_GATEKEEPER_DEVICE_H_
19 
20 #include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
21 #include <hidl/Status.h>
22 
23 #include <memory>
24 #include "SoftGateKeeper.h"
25 
26 namespace android {
27 
28 /**
29  * Software based GateKeeper implementation
30  */
31 class SoftGateKeeperDevice : public ::android::hardware::gatekeeper::V1_0::IGatekeeper {
32   public:
SoftGateKeeperDevice()33     SoftGateKeeperDevice() { impl_.reset(new ::gatekeeper::SoftGateKeeper()); }
34 
35     // Wrappers to translate the gatekeeper HAL API to the Kegyuard Messages API.
36 
37     /**
38      * Enrolls password_payload, which should be derived from a user selected pin or password,
39      * with the authentication factor private key used only for enrolling authentication
40      * factor data.
41      *
42      * Returns: 0 on success or an error code less than 0 on error.
43      * On error, enrolled_password_handle will not be allocated.
44      */
45     ::android::hardware::Return<void> enroll(
46             uint32_t uid, const ::android::hardware::hidl_vec<uint8_t>& currentPasswordHandle,
47             const ::android::hardware::hidl_vec<uint8_t>& currentPassword,
48             const ::android::hardware::hidl_vec<uint8_t>& desiredPassword,
49             enroll_cb _hidl_cb) override;
50 
51     /**
52      * Verifies provided_password matches enrolled_password_handle.
53      *
54      * Implementations of this module may retain the result of this call
55      * to attest to the recency of authentication.
56      *
57      * On success, writes the address of a verification token to auth_token,
58      * usable to attest password verification to other trusted services. Clients
59      * may pass NULL for this value.
60      *
61      * Returns: 0 on success or an error code less than 0 on error
62      * On error, verification token will not be allocated
63      */
64     ::android::hardware::Return<void> verify(
65             uint32_t uid, uint64_t challenge,
66             const ::android::hardware::hidl_vec<uint8_t>& enrolledPasswordHandle,
67             const ::android::hardware::hidl_vec<uint8_t>& providedPassword,
68             verify_cb _hidl_cb) override;
69 
70     ::android::hardware::Return<void> deleteUser(uint32_t uid, deleteUser_cb _hidl_cb) override;
71 
72     ::android::hardware::Return<void> deleteAllUsers(deleteAllUsers_cb _hidl_cb) override;
73 
74   private:
75     std::unique_ptr<::gatekeeper::SoftGateKeeper> impl_;
76 };
77 
78 }  // namespace android
79 
80 #endif  // SOFT_GATEKEEPER_DEVICE_H_
81