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 "inputer_get_data_proxy_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "inputer_get_data.h"
22 #include "parcel.h"
23 
24 #include "iam_fuzz_test.h"
25 #include "iam_logger.h"
26 #include "iam_ptr.h"
27 #include "i_inputer_data_impl.h"
28 #include "pin_auth_all_in_one_hdi.h"
29 
30 #include "inputer_get_data_proxy.h"
31 
32 #define LOG_TAG "PIN_AUTH_SA"
33 
34 #undef private
35 
36 using namespace std;
37 using namespace OHOS::UserIam::Common;
38 
39 namespace OHOS {
40 namespace UserIam {
41 namespace PinAuth {
42 namespace {
43 
44 constexpr uint64_t SCHEDULE_ID = 123;
InputerGetDataProxyFuzzTest(const uint8_t * rawData,size_t size)45 bool InputerGetDataProxyFuzzTest(const uint8_t *rawData, size_t size)
46 {
47     IAM_LOGI("start");
48     if (rawData == nullptr) {
49         return false;
50     }
51     Parcel parcel;
52     parcel.WriteBuffer(rawData, size);
53     parcel.RewindRead(0);
54     std::vector<uint8_t> algoParmeter;
55     std::vector<uint8_t> challenge;
56     auto hdi = Common::MakeShared<PinAuthAllInOneHdi>(nullptr);
57     sptr<IInputerDataImpl> inputerSetData(new (std::nothrow) IInputerDataImpl(SCHEDULE_ID, hdi));
58     FillFuzzUint8Vector(parcel, algoParmeter);
59     FillFuzzUint8Vector(parcel, challenge);
60     InputerGetDataParam param = {
61         .mode = static_cast<GetDataMode>(parcel.ReadInt32()),
62         .authSubType = parcel.ReadInt32(),
63         .algoVersion = parcel.ReadInt32(),
64         .algoParameter = algoParmeter,
65         .challenge = challenge,
66         .inputerSetData = inputerSetData,
67     };
68     std::shared_ptr<InputerGetDataProxy> inputerGetDataProxy = Common::MakeShared<InputerGetDataProxy>(nullptr);
69     inputerGetDataProxy->OnGetData(param);
70     return true;
71 }
72 } // namespace
73 } // namespace PinAuth
74 } // namespace UserIam
75 } // namespace OHOS
76 
77 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)78 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
79 {
80     OHOS::UserIam::PinAuth::InputerGetDataProxyFuzzTest(data, size);
81     return 0;
82 }