• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_access_ctrl_client_fuzzer.h"
17 
18 #include "parcel.h"
19 
20 #include "user_access_ctrl_client_impl.h"
21 #include "user_access_ctrl_callback_service.h"
22 #include "iam_fuzz_test.h"
23 #include "iam_logger.h"
24 #include "iam_ptr.h"
25 
26 #define LOG_TAG "USER_AUTH_SDK"
27 
28 namespace OHOS {
29 namespace UserIam {
30 namespace UserAuth {
31 namespace {
32 class DummyVerifyTokenCallback final : public VerifyTokenCallback {
33 public:
OnResult(int32_t result,const Attributes & extraInfo)34     void OnResult(int32_t result, const Attributes &extraInfo)
35     {
36         IAM_LOGI("start");
37         static_cast<void>(result);
38         static_cast<void>(extraInfo);
39     }
40 };
41 
42 
FuzzClientVerifyAuthToken(Parcel & parcel)43 void FuzzClientVerifyAuthToken(Parcel &parcel)
44 {
45     IAM_LOGI("start");
46     std::vector<uint8_t> tokenIn = {};
47     Common::FillFuzzUint8Vector(parcel, tokenIn);
48     uint64_t allowableDuration = parcel.ReadInt32();
49     auto callback = Common::MakeShared<DummyVerifyTokenCallback>();
50     UserAccessCtrlClient::GetInstance().VerifyAuthToken(tokenIn, allowableDuration, callback);
51     UserAccessCtrlClient::GetInstance().VerifyAuthToken(tokenIn, allowableDuration, nullptr);
52     IAM_LOGI("end");
53 }
54 
55 using FuzzFunc = decltype(FuzzClientVerifyAuthToken);
56 FuzzFunc *g_fuzzFuncs[] = {
57     FuzzClientVerifyAuthToken,
58 };
59 
UserAccessCtrlClientFuzzTest(const uint8_t * data,size_t size)60 void UserAccessCtrlClientFuzzTest(const uint8_t *data, size_t size)
61 {
62     Parcel parcel;
63     parcel.WriteBuffer(data, size);
64     parcel.RewindRead(0);
65     uint32_t index = parcel.ReadUint32() % (sizeof(g_fuzzFuncs) / sizeof(FuzzFunc *));
66     auto fuzzFunc = g_fuzzFuncs[index];
67     fuzzFunc(parcel);
68     return;
69 }
70 } // namespace
71 } // namespace UserAuth
72 } // namespace UserIam
73 } // namespace OHOS
74 
75 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)76 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
77 {
78     OHOS::UserIam::UserAuth::UserAccessCtrlClientFuzzTest(data, size);
79     return 0;
80 }
81