• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "executor_impl.h"
17 
18 #include <hdf_base.h>
19 
20 #include "fingerprint_auth_defines.h"
21 #include "iam_logger.h"
22 
23 #define LOG_LABEL OHOS::UserIam::Common::LABEL_FINGERPRINT_AUTH_IMPL
24 
25 namespace OHOS {
26 namespace HDI {
27 namespace FingerprintAuth {
28 namespace {
29 constexpr uint16_t SENSOR_ID = 1;
30 constexpr uint32_t EXECUTOR_TYPE = 123;
31 constexpr size_t PUBLIC_KEY_LEN = 32;
32 } // namespace
33 
ExecutorImpl()34 ExecutorImpl::ExecutorImpl()
35 {
36     executorInfo_ = {
37         .sensorId = SENSOR_ID,
38         .executorType = EXECUTOR_TYPE,
39         .executorRole = ExecutorRole::ALL_IN_ONE,
40         .authType = AuthType::FINGERPRINT,
41         .esl = ExecutorSecureLevel::ESL0,
42         .publicKey = std::vector<uint8_t>(PUBLIC_KEY_LEN, 0),
43         .extraInfo = {},
44     };
45 }
46 
GetExecutorInfo(ExecutorInfo & executorInfo)47 int32_t ExecutorImpl::GetExecutorInfo(ExecutorInfo &executorInfo)
48 {
49     IAM_LOGI("interface mock start");
50     executorInfo = executorInfo_;
51     IAM_LOGI("get executor information success");
52     return HDF_SUCCESS;
53 }
54 
GetTemplateInfo(uint64_t templateId,TemplateInfo & templateInfo)55 int32_t ExecutorImpl::GetTemplateInfo(uint64_t templateId, TemplateInfo &templateInfo)
56 {
57     IAM_LOGI("interface mock start");
58     static_cast<void>(templateId);
59     templateInfo = {0};
60     IAM_LOGI("get template information success");
61     return HDF_SUCCESS;
62 }
63 
OnRegisterFinish(const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & frameworkPublicKey,const std::vector<uint8_t> & extraInfo)64 int32_t ExecutorImpl::OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
65     const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo)
66 {
67     IAM_LOGI("interface mock start");
68     static_cast<void>(templateIdList);
69     static_cast<void>(extraInfo);
70     static_cast<void>(frameworkPublicKey);
71     IAM_LOGI("register finish");
72     return HDF_SUCCESS;
73 }
74 
Enroll(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)75 int32_t ExecutorImpl::Enroll(
76     uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
77 {
78     IAM_LOGI("interface mock start");
79     static_cast<void>(scheduleId);
80     static_cast<void>(extraInfo);
81     if (callbackObj == nullptr) {
82         IAM_LOGE("callbackObj is nullptr");
83         return HDF_ERR_INVALID_PARAM;
84     }
85     IAM_LOGI("enroll, result is %{public}d", ResultCode::OPERATION_NOT_SUPPORT);
86     int32_t ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
87     if (ret != HDF_SUCCESS) {
88         IAM_LOGE("callback result is %{public}d", ret);
89         return HDF_FAILURE;
90     }
91     return HDF_SUCCESS;
92 }
93 
Authenticate(uint64_t scheduleId,const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)94 int32_t ExecutorImpl::Authenticate(uint64_t scheduleId, const std::vector<uint64_t> &templateIdList,
95     const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
96 {
97     IAM_LOGI("interface mock start");
98     return AuthenticateV1_1(scheduleId, templateIdList, true, extraInfo, callbackObj);
99 }
100 
AuthenticateV1_1(uint64_t scheduleId,const std::vector<uint64_t> & templateIdList,bool endAfterFirstFail,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)101 int32_t ExecutorImpl::AuthenticateV1_1(uint64_t scheduleId, const std::vector<uint64_t> &templateIdList,
102     bool endAfterFirstFail, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
103 {
104     IAM_LOGI("interface mock start");
105     static_cast<void>(scheduleId);
106     static_cast<void>(templateIdList);
107     static_cast<void>(endAfterFirstFail);
108     static_cast<void>(extraInfo);
109     if (callbackObj == nullptr) {
110         IAM_LOGE("callbackObj is nullptr");
111         return HDF_ERR_INVALID_PARAM;
112     }
113     IAM_LOGI("authenticate, result is %{public}d", ResultCode::NOT_ENROLLED);
114     int32_t ret = callbackObj->OnResult(ResultCode::NOT_ENROLLED, {});
115     if (ret != HDF_SUCCESS) {
116         IAM_LOGE("callback result is %{public}d", ret);
117         return HDF_FAILURE;
118     }
119     return HDF_SUCCESS;
120 }
121 
Identify(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)122 int32_t ExecutorImpl::Identify(
123     uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
124 {
125     IAM_LOGI("interface mock start");
126     static_cast<void>(scheduleId);
127     static_cast<void>(extraInfo);
128     if (callbackObj == nullptr) {
129         IAM_LOGE("callbackObj is nullptr");
130         return HDF_ERR_INVALID_PARAM;
131     }
132     IAM_LOGI("identify, result is %{public}d", ResultCode::OPERATION_NOT_SUPPORT);
133     int32_t ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
134     if (ret != HDF_SUCCESS) {
135         IAM_LOGE("callback result is %{public}d", ret);
136         return HDF_FAILURE;
137     }
138     return HDF_SUCCESS;
139 }
140 
Delete(const std::vector<uint64_t> & templateIdList)141 int32_t ExecutorImpl::Delete(const std::vector<uint64_t> &templateIdList)
142 {
143     IAM_LOGI("interface mock start");
144     static_cast<void>(templateIdList);
145     IAM_LOGI("delete success");
146     return HDF_SUCCESS;
147 }
148 
Cancel(uint64_t scheduleId)149 int32_t ExecutorImpl::Cancel(uint64_t scheduleId)
150 {
151     IAM_LOGI("interface mock start");
152     static_cast<void>(scheduleId);
153     IAM_LOGI("cancel success");
154     return HDF_SUCCESS;
155 }
156 
SendCommand(int32_t commandId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)157 int32_t ExecutorImpl::SendCommand(
158     int32_t commandId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
159 {
160     IAM_LOGI("interface mock start");
161     static_cast<void>(extraInfo);
162     if (callbackObj == nullptr) {
163         IAM_LOGE("callbackObj is nullptr");
164         return HDF_ERR_INVALID_PARAM;
165     }
166     int32_t ret;
167     switch (commandId) {
168         case CommandId::LOCK_TEMPLATE:
169             IAM_LOGI("lock template, result is %{public}d", ResultCode::SUCCESS);
170             ret = callbackObj->OnResult(ResultCode::SUCCESS, {});
171             if (ret != HDF_SUCCESS) {
172                 IAM_LOGE("callback result is %{public}d", ret);
173                 return HDF_FAILURE;
174             }
175             break;
176         case CommandId::UNLOCK_TEMPLATE:
177             IAM_LOGI("unlock template, result is %{public}d", ResultCode::SUCCESS);
178             ret = callbackObj->OnResult(ResultCode::SUCCESS, {});
179             if (ret != HDF_SUCCESS) {
180                 IAM_LOGE("callback result is %{public}d", ret);
181                 return HDF_FAILURE;
182             }
183             break;
184         case CommandId::INIT_ALGORITHM:
185             IAM_LOGI("init algorithm, result is %{public}d", ResultCode::SUCCESS);
186             ret = callbackObj->OnResult(ResultCode::SUCCESS, {});
187             if (ret != HDF_SUCCESS) {
188                 IAM_LOGE("callback result is %{public}d", ret);
189                 return HDF_FAILURE;
190             }
191             break;
192         default:
193             IAM_LOGD("not support CommandId : %{public}d", commandId);
194             ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
195             if (ret != HDF_SUCCESS) {
196                 IAM_LOGE("callback result is %{public}d", ret);
197                 return HDF_FAILURE;
198             }
199     }
200     return HDF_SUCCESS;
201 }
202 
GetProperty(const std::vector<uint64_t> & templateIdList,const std::vector<GetPropertyType> & propertyTypes,Property & property)203 int32_t ExecutorImpl::GetProperty(
204     const std::vector<uint64_t> &templateIdList, const std::vector<GetPropertyType> &propertyTypes, Property &property)
205 {
206     IAM_LOGI("interface mock start");
207     property = {};
208     IAM_LOGI("get property success");
209     return HDF_SUCCESS;
210 }
211 
SetCachedTemplates(const std::vector<uint64_t> & templateIdList)212 int32_t ExecutorImpl::SetCachedTemplates(const std::vector<uint64_t> &templateIdList)
213 {
214     IAM_LOGI("interface mock start");
215     IAM_LOGI("set cached templates success");
216     return HDF_SUCCESS;
217 }
218 
RegisterSaCommandCallback(const sptr<ISaCommandCallback> & callbackObj)219 int32_t ExecutorImpl::RegisterSaCommandCallback(const sptr<ISaCommandCallback> &callbackObj)
220 {
221     IAM_LOGI("interface mock start");
222     IAM_LOGI("register sa command callback success");
223     return HDF_SUCCESS;
224 }
225 
226 } // namespace FingerprintAuth
227 } // namespace HDI
228 } // namespace OHOS
229