• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "registerpininputer_fuzzer.h"
17 
18 #include <string>
19 #include <vector>
20 #include "access_token.h"
21 #include "access_token_error.h"
22 #include "accesstoken_kit.h"
23 #include "nativetoken_kit.h"
24 #include "account_iam_client.h"
25 #include "fuzz_data.h"
26 #include "token_setproc.h"
27 
28 using namespace std;
29 using namespace OHOS::AccountSA;
30 using namespace OHOS::Security::AccessToken;
31 
32 class MockIInputer : public OHOS::AccountSA::IInputer {
33 public:
~MockIInputer()34     virtual ~MockIInputer() {}
OnGetData(int32_t authSubType,std::vector<uint8_t> challenge,std::shared_ptr<IInputerData> inputerData)35     void OnGetData(
36         int32_t authSubType, std::vector<uint8_t> challenge, std::shared_ptr<IInputerData> inputerData) override
37     {
38         return;
39     }
40 };
41 namespace OHOS {
RegisterPinInputerFuzzTest(const uint8_t * data,size_t size)42 bool RegisterPinInputerFuzzTest(const uint8_t *data, size_t size)
43 {
44     FuzzData fuzzData(data, size);
45     std::shared_ptr<IInputer> inputer = fuzzData.GetData<bool>() ? make_shared<MockIInputer>() : nullptr;
46     AccountIAMClient::GetInstance().RegisterPINInputer(inputer);
47     AccountIAMClient::GetInstance().UnregisterPINInputer();
48     return true;
49 }
50 } // namespace OHOS
51 
NativeTokenGet()52 void NativeTokenGet()
53 {
54     uint64_t tokenId;
55     const char **perms = new const char *[1];
56     perms[0] = "ohos.permission.ACCESS_PIN_AUTH";
57     NativeTokenInfoParams infoInstance = {
58         .dcapsNum = 0,
59         .permsNum = 1,
60         .aclsNum = 0,
61         .perms = perms,
62         .acls = nullptr,
63         .aplStr = "system_core",
64     };
65     infoInstance.processName = "RegisterPinInputerFuzzTest";
66     tokenId = GetAccessTokenId(&infoInstance);
67     SetSelfTokenID(tokenId);
68     AccessTokenKit::ReloadNativeTokenInfo();
69     delete[] perms;
70 }
71 
72 /* Fuzzer entry point */
LLVMFuzzerInitialize(int * argc,char *** argv)73 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
74 {
75     NativeTokenGet();
76     return 0;
77 }
78 
79 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)80 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
81 {
82     /* Run your code on data */
83     OHOS::RegisterPinInputerFuzzTest(data, size);
84     return 0;
85 }
86