• 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 #include <hdf_base.h>
18 
19 #include "fingerprint_auth_defines.h"
20 #include "iam_logger.h"
21 
22 #define LOG_LABEL OHOS::UserIam::Common::LABEL_FINGERPRINT_AUTH_IMPL
23 
24 namespace OHOS {
25 namespace HDI {
26 namespace FingerprintAuth {
27 namespace V1_0 {
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     static_cast<void>(scheduleId);
99     static_cast<void>(templateIdList);
100     static_cast<void>(extraInfo);
101     if (callbackObj == nullptr) {
102         IAM_LOGE("callbackObj is nullptr");
103         return HDF_ERR_INVALID_PARAM;
104     }
105     IAM_LOGI("authenticate, result is %{public}d", ResultCode::NOT_ENROLLED);
106     int32_t ret = callbackObj->OnResult(ResultCode::NOT_ENROLLED, {});
107     if (ret != HDF_SUCCESS) {
108         IAM_LOGE("callback result is %{public}d", ret);
109         return HDF_FAILURE;
110     }
111     return HDF_SUCCESS;
112 }
113 
Identify(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)114 int32_t ExecutorImpl::Identify(
115     uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
116 {
117     IAM_LOGI("interface mock start");
118     static_cast<void>(scheduleId);
119     static_cast<void>(extraInfo);
120     if (callbackObj == nullptr) {
121         IAM_LOGE("callbackObj is nullptr");
122         return HDF_ERR_INVALID_PARAM;
123     }
124     IAM_LOGI("identify, result is %{public}d", ResultCode::OPERATION_NOT_SUPPORT);
125     int32_t ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
126     if (ret != HDF_SUCCESS) {
127         IAM_LOGE("callback result is %{public}d", ret);
128         return HDF_FAILURE;
129     }
130     return HDF_SUCCESS;
131 }
132 
Delete(const std::vector<uint64_t> & templateIdList)133 int32_t ExecutorImpl::Delete(const std::vector<uint64_t> &templateIdList)
134 {
135     IAM_LOGI("interface mock start");
136     static_cast<void>(templateIdList);
137     IAM_LOGI("delete success");
138     return HDF_SUCCESS;
139 }
140 
Cancel(uint64_t scheduleId)141 int32_t ExecutorImpl::Cancel(uint64_t scheduleId)
142 {
143     IAM_LOGI("interface mock start");
144     static_cast<void>(scheduleId);
145     IAM_LOGI("cancel success");
146     return HDF_SUCCESS;
147 }
148 
SendCommand(int32_t commandId,const std::vector<uint8_t> & extraInfo,const sptr<IExecutorCallback> & callbackObj)149 int32_t ExecutorImpl::SendCommand(
150     int32_t commandId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj)
151 {
152     IAM_LOGI("interface mock start");
153     static_cast<void>(extraInfo);
154     if (callbackObj == nullptr) {
155         IAM_LOGE("callbackObj is nullptr");
156         return HDF_ERR_INVALID_PARAM;
157     }
158     int32_t ret;
159     switch (commandId) {
160         case LOCK_TEMPLATE:
161             IAM_LOGI("lock template, result is %{public}d", ResultCode::SUCCESS);
162             ret = callbackObj->OnResult(ResultCode::SUCCESS, {});
163             if (ret != HDF_SUCCESS) {
164                 IAM_LOGE("callback result is %{public}d", ret);
165                 return HDF_FAILURE;
166             }
167             break;
168         case UNLOCK_TEMPLATE:
169             IAM_LOGI("unlock 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         default:
177             IAM_LOGD("not support CommandId : %{public}d", commandId);
178             ret = callbackObj->OnResult(ResultCode::OPERATION_NOT_SUPPORT, {});
179             if (ret != HDF_SUCCESS) {
180                 IAM_LOGE("callback result is %{public}d", ret);
181                 return HDF_FAILURE;
182             }
183     }
184     return HDF_SUCCESS;
185 }
186 } // namespace V1_0
187 } // namespace FingerprintAuth
188 } // namespace HDI
189 } // namespace OHOS
190