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 "user_auth_executor_fuzzer.h"
17
18 #include <cstdint>
19 #include <functional>
20
21 #include "executor.h"
22 #include "executor_mgr_wrapper.h"
23 #include "iam_fuzz_test.h"
24 #include "iam_logger.h"
25 #include "iam_ptr.h"
26 #include "iam_executor_iauth_executor_hdi.h"
27 #include "framework_executor_callback.h"
28 #include "collect_command.h"
29
30 #undef private
31
32 #define LOG_TAG "USER_AUTH_EXECUTOR"
33
34 namespace OHOS {
35 namespace UserIam {
36 namespace UserAuth {
37 namespace {
38 using namespace std;
39 using namespace OHOS::UserIam::Common;
40 using namespace OHOS::UserIam::UserAuth;
41
42 vector<std::function<void(void)>> g_callbackToReply;
43 std::mutex g_callbackToReplyMutex;
44 std::shared_ptr<ExecutorRegisterCallback> g_executorCallback = nullptr;
45
46 class DummyAuthExecutorHdi : public IAuthExecutorHdi {
47 public:
48 DummyAuthExecutorHdi() = default;
49 ~DummyAuthExecutorHdi() override = default;
50
SendMessage(uint64_t scheduleId,int32_t srcRole,const std::vector<uint8_t> & msg)51 ResultCode SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t> &msg) override
52 {
53 std::lock_guard<std::mutex> lock(mutex_);
54 if (fuzzParcel_ == nullptr) {
55 return ResultCode::GENERAL_ERROR;
56 }
57 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
58 }
59
GetExecutorInfo(ExecutorInfo & executorInfo)60 ResultCode GetExecutorInfo(ExecutorInfo &executorInfo) override
61 {
62 std::lock_guard<std::mutex> lock(mutex_);
63 // GetExecutorInfo is called in Executor constructor, when fuzzParcel_ is null
64 // SUCCESS is returned to generate executor description
65 if (fuzzParcel_ == nullptr) {
66 return ResultCode::SUCCESS;
67 }
68 executorInfo.executorSensorHint = fuzzParcel_->ReadInt32();
69 executorInfo.authType = static_cast<AuthType>(fuzzParcel_->ReadInt32());
70 executorInfo.executorRole = static_cast<ExecutorRole>(fuzzParcel_->ReadInt32());
71 executorInfo.executorMatcher = fuzzParcel_->ReadInt32();
72 executorInfo.esl = static_cast<ExecutorSecureLevel>(fuzzParcel_->ReadInt32());
73 FillFuzzUint8Vector(*fuzzParcel_, executorInfo.publicKey);
74 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
75 }
76
OnRegisterFinish(const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & frameworkPublicKey,const std::vector<uint8_t> & extraInfo)77 ResultCode OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
78 const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) override
79 {
80 std::lock_guard<std::mutex> lock(mutex_);
81 if (fuzzParcel_ == nullptr) {
82 return ResultCode::GENERAL_ERROR;
83 }
84 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
85 }
86
Enroll(uint64_t scheduleId,const EnrollParam & param,const std::shared_ptr<UserAuth::IExecuteCallback> & callbackObj)87 ResultCode Enroll(uint64_t scheduleId, const EnrollParam ¶m,
88 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override
89 {
90 std::lock_guard<std::mutex> lock(mutex_);
91 if (fuzzParcel_ == nullptr) {
92 return ResultCode::GENERAL_ERROR;
93 }
94 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
95 }
96
Authenticate(uint64_t scheduleId,const AuthenticateParam & param,const std::shared_ptr<UserAuth::IExecuteCallback> & callbackObj)97 ResultCode Authenticate(uint64_t scheduleId, const AuthenticateParam ¶m,
98 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override
99 {
100 std::lock_guard<std::mutex> lock(mutex_);
101 if (fuzzParcel_ == nullptr) {
102 return ResultCode::GENERAL_ERROR;
103 }
104 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
105 }
106
Identify(uint64_t scheduleId,const IdentifyParam & param,const std::shared_ptr<UserAuth::IExecuteCallback> & callbackObj)107 ResultCode Identify(uint64_t scheduleId, const IdentifyParam ¶m,
108 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override
109 {
110 std::lock_guard<std::mutex> lock(mutex_);
111 if (fuzzParcel_ == nullptr) {
112 return ResultCode::GENERAL_ERROR;
113 }
114 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
115 }
116
Delete(const std::vector<uint64_t> & templateIdList)117 ResultCode Delete(const std::vector<uint64_t> &templateIdList) override
118 {
119 std::lock_guard<std::mutex> lock(mutex_);
120 if (fuzzParcel_ == nullptr) {
121 return ResultCode::GENERAL_ERROR;
122 }
123 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
124 }
125
Cancel(uint64_t scheduleId)126 ResultCode Cancel(uint64_t scheduleId) override
127 {
128 std::lock_guard<std::mutex> lock(mutex_);
129 if (fuzzParcel_ == nullptr) {
130 return ResultCode::GENERAL_ERROR;
131 }
132 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
133 }
134
SendCommand(PropertyMode commandId,const std::vector<uint8_t> & extraInfo,const std::shared_ptr<UserAuth::IExecuteCallback> & callbackObj)135 ResultCode SendCommand(PropertyMode commandId, const std::vector<uint8_t> &extraInfo,
136 const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj) override
137 {
138 std::lock_guard<std::mutex> lock(mutex_);
139 if (fuzzParcel_ == nullptr) {
140 return ResultCode::GENERAL_ERROR;
141 }
142 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
143 }
144
GetProperty(const std::vector<uint64_t> & templateIdList,const std::vector<Attributes::AttributeKey> & keys,Property & property)145 ResultCode GetProperty(const std::vector<uint64_t> &templateIdList,
146 const std::vector<Attributes::AttributeKey> &keys, Property &property) override
147 {
148 std::lock_guard<std::mutex> lock(mutex_);
149 if (fuzzParcel_ == nullptr) {
150 return ResultCode::GENERAL_ERROR;
151 }
152 property.authSubType = fuzzParcel_->ReadUint64();
153 property.lockoutDuration = fuzzParcel_->ReadInt32();
154 property.remainAttempts = fuzzParcel_->ReadInt32();
155 property.enrollmentProgress = fuzzParcel_->ReadString();
156 property.sensorInfo = fuzzParcel_->ReadString();
157 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
158 }
159
SetCachedTemplates(const std::vector<uint64_t> & templateIdList)160 ResultCode SetCachedTemplates(const std::vector<uint64_t> &templateIdList) override
161 {
162 std::lock_guard<std::mutex> lock(mutex_);
163 if (fuzzParcel_ == nullptr) {
164 return ResultCode::GENERAL_ERROR;
165 }
166 return static_cast<ResultCode>(fuzzParcel_->ReadInt32());
167 }
168
SetParcel(const std::shared_ptr<Parcel> & parcel)169 void SetParcel(const std::shared_ptr<Parcel> &parcel)
170 {
171 std::lock_guard<std::mutex> lock(mutex_);
172 fuzzParcel_ = parcel;
173 }
174
175 private:
FuzzTriggerIExecuteCallback(const std::shared_ptr<UserAuth::IExecuteCallback> & callbackObj)176 void FuzzTriggerIExecuteCallback(const std::shared_ptr<UserAuth::IExecuteCallback> &callbackObj)
177 {
178 auto reply = [fuzzParcel(this->fuzzParcel_), callbackObj]() {
179 const uint32_t maxTriggerCount = 5;
180 uint32_t triggerCount = fuzzParcel->ReadUint32() % maxTriggerCount;
181 vector<uint8_t> extraInfo;
182 for (uint32_t i = 0; i < triggerCount; i++) {
183 FillFuzzUint8Vector(*fuzzParcel, extraInfo);
184 bool triggerOnResult = fuzzParcel->ReadBool();
185 if (triggerOnResult) {
186 callbackObj->OnAcquireInfo(fuzzParcel->ReadInt32(), extraInfo);
187 } else {
188 callbackObj->OnResult(static_cast<ResultCode>(fuzzParcel->ReadInt32()), extraInfo);
189 }
190 }
191 };
192
193 bool instantReply = fuzzParcel_->ReadBool();
194 if (instantReply) {
195 reply();
196 }
197 bool delayedReply = fuzzParcel_->ReadBool();
198 if (delayedReply) {
199 std::lock_guard<std::mutex> guard(g_callbackToReplyMutex);
200 g_callbackToReply.push_back(reply);
201 }
202 }
203 std::mutex mutex_;
204 std::shared_ptr<Parcel> fuzzParcel_ {nullptr};
205 };
206
207 class DummyExecutorMgrWrapper : public ExecutorMgrWrapper {
208 public:
209 virtual ~DummyExecutorMgrWrapper() = default;
Register(const ExecutorInfo & info,std::shared_ptr<ExecutorRegisterCallback> callback)210 uint64_t Register(const ExecutorInfo &info, std::shared_ptr<ExecutorRegisterCallback> callback) override
211 {
212 g_executorCallback = callback;
213 return 0;
214 }
215 };
216
217 class DummyExecutorMessenger : public ExecutorMessenger {
218 public:
219 virtual ~DummyExecutorMessenger() = default;
SendData(uint64_t scheduleId,ExecutorRole dstRole,const std::shared_ptr<AuthMessage> & msg)220 int32_t SendData(uint64_t scheduleId, ExecutorRole dstRole, const std::shared_ptr<AuthMessage> &msg) override
221 {
222 static_cast<void>(scheduleId);
223 static_cast<void>(dstRole);
224 static_cast<void>(msg);
225 return fuzzParcel_->ReadInt32();
226 }
227
Finish(uint64_t scheduleId,int32_t resultCode,const Attributes & finalResult)228 int32_t Finish(uint64_t scheduleId, int32_t resultCode, const Attributes &finalResult) override
229 {
230 static_cast<void>(scheduleId);
231 static_cast<void>(resultCode);
232 static_cast<void>(finalResult);
233 return fuzzParcel_->ReadInt32();
234 }
235
SetParcel(const std::shared_ptr<Parcel> & parcel)236 void SetParcel(const std::shared_ptr<Parcel> &parcel)
237 {
238 fuzzParcel_ = parcel;
239 }
240
241 private:
242 std::shared_ptr<Parcel> fuzzParcel_;
243 };
244
245 auto g_executorHdi = UserIam::Common::MakeShared<DummyAuthExecutorHdi>();
246 auto g_executorMgrWrapper = UserIam::Common::MakeShared<DummyExecutorMgrWrapper>();
247 auto g_executor = UserIam::Common::MakeShared<Executor>(g_executorMgrWrapper, g_executorHdi, 1);
248 auto g_executorMessenger = UserIam::Common::MakeShared<DummyExecutorMessenger>();
249
FuzzExecutorResetExecutor(std::shared_ptr<Parcel> parcel)250 void FuzzExecutorResetExecutor(std::shared_ptr<Parcel> parcel)
251 {
252 IAM_LOGI("begin");
253 static uint32_t id = 0;
254 id++;
255 g_executor = UserIam::Common::MakeShared<Executor>(g_executorMgrWrapper, g_executorHdi, id);
256 IAM_LOGI("end");
257 }
258
FuzzExecutorOnHdiConnect(std::shared_ptr<Parcel> parcel)259 void FuzzExecutorOnHdiConnect(std::shared_ptr<Parcel> parcel)
260 {
261 IAM_LOGI("begin");
262 g_executor->OnHdiConnect();
263 IAM_LOGI("end");
264 }
265
FuzzExecutorOnHdiDisconnect(std::shared_ptr<Parcel> parcel)266 void FuzzExecutorOnHdiDisconnect(std::shared_ptr<Parcel> parcel)
267 {
268 IAM_LOGI("begin");
269 static int32_t skip_count = 1000;
270 // OnHdiDisconnect affects test of other function, skip it in the first phase
271 if (skip_count > 0) {
272 skip_count--;
273 return;
274 }
275 g_executor->OnHdiDisconnect();
276 g_executorCallback = nullptr;
277 IAM_LOGI("end");
278 }
279
FuzzExecutorOnFrameworkReady(std::shared_ptr<Parcel> parcel)280 void FuzzExecutorOnFrameworkReady(std::shared_ptr<Parcel> parcel)
281 {
282 IAM_LOGI("begin");
283 g_executor->OnFrameworkReady();
284 IAM_LOGI("end");
285 }
286
FuzzExecutorGetExecutorHdi(std::shared_ptr<Parcel> parcel)287 void FuzzExecutorGetExecutorHdi(std::shared_ptr<Parcel> parcel)
288 {
289 IAM_LOGI("begin");
290 g_executor->GetExecutorHdi();
291 IAM_LOGI("end");
292 }
293
FuzzExecutorGetDescription(std::shared_ptr<Parcel> parcel)294 void FuzzExecutorGetDescription(std::shared_ptr<Parcel> parcel)
295 {
296 IAM_LOGI("begin");
297 g_executor->GetDescription();
298 IAM_LOGI("end");
299 }
300
FuzzExecutorUnregisterExecutorCallback(std::shared_ptr<Parcel> parcel)301 void FuzzExecutorUnregisterExecutorCallback(std::shared_ptr<Parcel> parcel)
302 {
303 IAM_LOGI("begin");
304 g_executor->UnregisterExecutorCallback();
305 IAM_LOGI("end");
306 }
307
FuzzExecutorRespondCallbackOnDisconnect(std::shared_ptr<Parcel> parcel)308 void FuzzExecutorRespondCallbackOnDisconnect(std::shared_ptr<Parcel> parcel)
309 {
310 IAM_LOGI("begin");
311 g_executor->RespondCallbackOnDisconnect();
312 IAM_LOGI("end");
313 }
314
FuzzExecutorGetAuthType(std::shared_ptr<Parcel> parcel)315 void FuzzExecutorGetAuthType(std::shared_ptr<Parcel> parcel)
316 {
317 IAM_LOGI("begin");
318 g_executor->GetAuthType();
319 IAM_LOGI("end");
320 }
321
FuzzExecutorGetExecutorRole(std::shared_ptr<Parcel> parcel)322 void FuzzExecutorGetExecutorRole(std::shared_ptr<Parcel> parcel)
323 {
324 IAM_LOGI("begin");
325 g_executor->GetExecutorRole();
326 IAM_LOGI("end");
327 }
328
FillIExecutorMessenger(std::shared_ptr<Parcel> parcel,shared_ptr<ExecutorMessenger> & messenger)329 void FillIExecutorMessenger(std::shared_ptr<Parcel> parcel, shared_ptr<ExecutorMessenger> &messenger)
330 {
331 bool fillNull = parcel->ReadBool();
332 if (fillNull) {
333 messenger = nullptr;
334 return;
335 }
336 messenger = g_executorMessenger;
337 }
338
FillIAttributes(std::shared_ptr<Parcel> parcel,Attributes & attributes)339 void FillIAttributes(std::shared_ptr<Parcel> parcel, Attributes &attributes)
340 {
341 bool fillNull = parcel->ReadBool();
342 if (fillNull) {
343 return;
344 }
345
346 attributes.SetUint64Value(Attributes::ATTR_TEMPLATE_ID, parcel->ReadUint64());
347 attributes.SetUint64Value(Attributes::ATTR_CALLER_UID, parcel->ReadUint64());
348 attributes.SetUint32Value(Attributes::ATTR_PROPERTY_MODE, parcel->ReadUint32());
349 std::vector<uint64_t> templateIdList;
350 FillFuzzUint64Vector(*parcel, templateIdList);
351 attributes.GetUint64ArrayValue(Attributes::ATTR_TEMPLATE_ID_LIST, templateIdList);
352 std::vector<uint8_t> extraInfo;
353 FillFuzzUint8Vector(*parcel, extraInfo);
354 attributes.GetUint64ArrayValue(Attributes::ATTR_EXTRA_INFO, templateIdList);
355 attributes.SetUint64Value(Attributes::ATTR_CALLER_UID, parcel->ReadUint64());
356 attributes.SetUint32Value(Attributes::ATTR_SCHEDULE_MODE, parcel->ReadUint32());
357 }
358
FuzzExecutorCommand(std::shared_ptr<Parcel> parcel)359 void FuzzExecutorCommand(std::shared_ptr<Parcel> parcel)
360 {
361 IAM_LOGI("begin");
362 uint64_t scheduleId = parcel->ReadUint64();
363 Attributes properties;
364 FillIAttributes(parcel, properties);
365 std::shared_ptr<IAsyncCommand> command =
366 Common::MakeShared<CollectCommand>(g_executor, scheduleId, properties, g_executorMessenger);
367 g_executor->AddCommand(command);
368 g_executor->RemoveCommand(command);
369 IAM_LOGI("end");
370 }
371
FuzzFrameworkOnMessengerReady(std::shared_ptr<Parcel> parcel)372 void FuzzFrameworkOnMessengerReady(std::shared_ptr<Parcel> parcel)
373 {
374 IAM_LOGI("begin");
375 // g_executorCallback may be not set
376 if (g_executorCallback == nullptr) {
377 return;
378 }
379 shared_ptr<ExecutorMessenger> messenger = nullptr;
380 FillIExecutorMessenger(parcel, messenger);
381 std::vector<uint8_t> publicKey;
382 FillFuzzUint8Vector(*parcel, publicKey);
383 std::vector<uint64_t> templateIds;
384 FillFuzzUint64Vector(*parcel, templateIds);
385 g_executorCallback->OnMessengerReady(messenger, publicKey, templateIds);
386 IAM_LOGI("end");
387 }
388
FuzzFrameworkOnBeginExecute(std::shared_ptr<Parcel> parcel)389 void FuzzFrameworkOnBeginExecute(std::shared_ptr<Parcel> parcel)
390 {
391 IAM_LOGI("begin");
392 // g_executorCallback may be not set
393 if (g_executorCallback == nullptr) {
394 return;
395 }
396 uint64_t scheduleId = parcel->ReadUint64();
397 std::vector<uint8_t> publicKey;
398 FillFuzzUint8Vector(*parcel, publicKey);
399 Attributes commandAttrs;
400 FillIAttributes(parcel, commandAttrs);
401 g_executorCallback->OnBeginExecute(scheduleId, publicKey, commandAttrs);
402 IAM_LOGI("end");
403 }
404
FuzzFrameworkOnEndExecute(std::shared_ptr<Parcel> parcel)405 void FuzzFrameworkOnEndExecute(std::shared_ptr<Parcel> parcel)
406 {
407 IAM_LOGI("begin");
408 // g_executorCallback may be not set
409 if (g_executorCallback == nullptr) {
410 return;
411 }
412 uint64_t scheduleId = parcel->ReadUint64();
413 Attributes consumerAttr;
414 FillIAttributes(parcel, consumerAttr);
415 g_executorCallback->OnEndExecute(scheduleId, consumerAttr);
416 IAM_LOGI("end");
417 }
418
FuzzFrameworkOnSetProperty(std::shared_ptr<Parcel> parcel)419 void FuzzFrameworkOnSetProperty(std::shared_ptr<Parcel> parcel)
420 {
421 IAM_LOGI("begin");
422 // g_executorCallback may be not set
423 if (g_executorCallback == nullptr) {
424 return;
425 }
426 Attributes properties;
427 FillIAttributes(parcel, properties);
428 g_executorCallback->OnSetProperty(properties);
429 IAM_LOGI("end");
430 }
431
FuzzFrameworkOnGetProperty(std::shared_ptr<Parcel> parcel)432 void FuzzFrameworkOnGetProperty(std::shared_ptr<Parcel> parcel)
433 {
434 IAM_LOGI("begin");
435 // g_executorCallback may be not set
436 if (g_executorCallback == nullptr) {
437 return;
438 }
439 Attributes conditions;
440 FillIAttributes(parcel, conditions);
441 Attributes values;
442 FillIAttributes(parcel, values);
443 g_executorCallback->OnGetProperty(conditions, values);
444 IAM_LOGI("end");
445 }
446
FuzzTriggerCallback(std::shared_ptr<Parcel> parcel)447 void FuzzTriggerCallback(std::shared_ptr<Parcel> parcel)
448 {
449 IAM_LOGI("begin");
450 std::lock_guard<std::mutex> guard(g_callbackToReplyMutex);
451 IAM_LOGI("trigger callback num %{public}zu", g_callbackToReply.size());
452 for (const auto &reply : g_callbackToReply) {
453 reply();
454 }
455 g_callbackToReply.clear();
456 IAM_LOGI("end");
457 }
458
459 std::shared_ptr<FrameworkExecutorCallback> g_frameworkExecutorCallback =
460 UserIam::Common::MakeShared<FrameworkExecutorCallback>(g_executor);
461
FuzzOnSendData(std::shared_ptr<Parcel> parcel)462 void FuzzOnSendData(std::shared_ptr<Parcel> parcel)
463 {
464 IAM_LOGI("begin");
465 uint64_t scheduleId = parcel->ReadUint64();
466 Attributes data;
467 FillIAttributes(parcel, data);
468 g_frameworkExecutorCallback->OnSendData(scheduleId, data);
469 IAM_LOGI("end");
470 }
471
FuzzProcessAuthCommand(std::shared_ptr<Parcel> parcel)472 void FuzzProcessAuthCommand(std::shared_ptr<Parcel> parcel)
473 {
474 IAM_LOGI("begin");
475 uint64_t scheduleId = parcel->ReadUint64();
476 Attributes properties;
477 FillIAttributes(parcel, properties);
478 g_frameworkExecutorCallback->ProcessAuthCommand(scheduleId, properties);
479 IAM_LOGI("end");
480 }
481
FuzzProcessIdentifyCommand(std::shared_ptr<Parcel> parcel)482 void FuzzProcessIdentifyCommand(std::shared_ptr<Parcel> parcel)
483 {
484 IAM_LOGI("begin");
485 uint64_t scheduleId = parcel->ReadUint64();
486 Attributes properties;
487 FillIAttributes(parcel, properties);
488 g_frameworkExecutorCallback->ProcessIdentifyCommand(scheduleId, properties);
489 IAM_LOGI("end");
490 }
491
FuzzProcessTemplateCommand(std::shared_ptr<Parcel> parcel)492 void FuzzProcessTemplateCommand(std::shared_ptr<Parcel> parcel)
493 {
494 IAM_LOGI("begin");
495 Attributes properties;
496 FillIAttributes(parcel, properties);
497 g_frameworkExecutorCallback->ProcessDeleteTemplateCommand(properties);
498 g_frameworkExecutorCallback->ProcessSetCachedTemplates(properties);
499 IAM_LOGI("end");
500 }
501
FuzzProcessNotifyExecutorReady(std::shared_ptr<Parcel> parcel)502 void FuzzProcessNotifyExecutorReady(std::shared_ptr<Parcel> parcel)
503 {
504 IAM_LOGI("begin");
505 Attributes properties;
506 FillIAttributes(parcel, properties);
507 g_frameworkExecutorCallback->ProcessNotifyExecutorReady(properties);
508 IAM_LOGI("end");
509 }
510
FuzzProcessGetPropertyCommand(std::shared_ptr<Parcel> parcel)511 void FuzzProcessGetPropertyCommand(std::shared_ptr<Parcel> parcel)
512 {
513 IAM_LOGI("begin");
514 std::shared_ptr<Attributes> conditions = UserIam::Common::MakeShared<Attributes>();
515 std::shared_ptr<Attributes> values = UserIam::Common::MakeShared<Attributes>();
516 g_frameworkExecutorCallback->ProcessGetPropertyCommand(conditions, values);
517 IAM_LOGI("end");
518 }
519
FuzzFillPropertyToAttribute(std::shared_ptr<Parcel> parcel)520 void FuzzFillPropertyToAttribute(std::shared_ptr<Parcel> parcel)
521 {
522 IAM_LOGI("begin");
523 std::vector<Attributes::AttributeKey> keyList = {
524 Attributes::ATTR_PIN_SUB_TYPE,
525 Attributes::ATTR_FREEZING_TIME,
526 Attributes::ATTR_REMAIN_TIMES,
527 Attributes::ATTR_ENROLL_PROGRESS,
528 Attributes::ATTR_SENSOR_INFO,
529 Attributes::ATTR_NEXT_FAIL_LOCKOUT_DURATION,
530 Attributes::ATTR_ROOT
531 };
532 Property property = {};
533 std::shared_ptr<Attributes> values = UserIam::Common::MakeShared<Attributes>();
534 g_frameworkExecutorCallback->FillPropertyToAttribute(keyList, property, values);
535 IAM_LOGI("end");
536 }
537
538 using FuzzFunc = decltype(FuzzFrameworkOnGetProperty);
539 FuzzFunc *g_fuzzFuncs[] = {
540 FuzzExecutorResetExecutor,
541 FuzzExecutorOnHdiConnect,
542 FuzzExecutorOnHdiDisconnect,
543 FuzzExecutorOnFrameworkReady,
544 FuzzExecutorGetExecutorHdi,
545 FuzzExecutorGetDescription,
546 FuzzExecutorUnregisterExecutorCallback,
547 FuzzExecutorRespondCallbackOnDisconnect,
548 FuzzExecutorGetAuthType,
549 FuzzExecutorGetExecutorRole,
550 FuzzExecutorCommand,
551 FuzzFrameworkOnMessengerReady,
552 FuzzFrameworkOnBeginExecute,
553 FuzzFrameworkOnEndExecute,
554 FuzzFrameworkOnSetProperty,
555 FuzzFrameworkOnGetProperty,
556 FuzzTriggerCallback,
557 FuzzOnSendData,
558 FuzzProcessAuthCommand,
559 FuzzProcessIdentifyCommand,
560 FuzzProcessTemplateCommand,
561 FuzzProcessNotifyExecutorReady,
562 FuzzProcessGetPropertyCommand,
563 FuzzFillPropertyToAttribute,
564 };
565
UserAuthExecutorFuzzTest(const uint8_t * data,size_t size)566 void UserAuthExecutorFuzzTest(const uint8_t *data, size_t size)
567 {
568 auto parcel = UserIam::Common::MakeShared<Parcel>();
569 if (parcel == nullptr) {
570 IAM_LOGI("parcel is null");
571 return;
572 }
573 parcel->WriteBuffer(data, size);
574 parcel->RewindRead(0);
575 uint32_t index = parcel->ReadUint32() % (sizeof(g_fuzzFuncs)) / sizeof(FuzzFunc *);
576 g_executorHdi->SetParcel(parcel);
577 g_executorMessenger->SetParcel(parcel);
578 auto fuzzFunc = g_fuzzFuncs[index];
579 fuzzFunc(parcel);
580 return;
581 }
582 } // namespace
583 } // namespace UserAuth
584 } // namespace UserIam
585 } // namespace OHOS
586
587 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)588 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
589 {
590 OHOS::UserIam::UserAuth::UserAuthExecutorFuzzTest(data, size);
591 return 0;
592 }
593