1 /*
2 * Copyright (c) 2023 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 "pin_auth_stub_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
27 #include "pin_auth_service.h"
28
29 #define LOG_TAG "PIN_AUTH_SA"
30
31 #undef private
32
33 using namespace std;
34 using namespace OHOS::UserIam::Common;
35
36 namespace OHOS {
37 namespace UserIam {
38 namespace PinAuth {
39 namespace {
40 constexpr uint32_t PIN_AUTH_CODE_MIN = 1;
41 constexpr uint32_t PIN_AUTH_CODE_MAX = 2;
42 const std::u16string PIN_AUTH_INTERFACE_TOKEN = u"ohos.PinAuth.PinAuthInterface";
PinAuthStubFuzzTest(const uint8_t * rawData,size_t size)43 bool PinAuthStubFuzzTest(const uint8_t *rawData, size_t size)
44 {
45 IAM_LOGI("start");
46 if (rawData == nullptr) {
47 return false;
48 }
49
50 PinAuthService pinAuthService;
51 for (uint32_t code = PIN_AUTH_CODE_MIN; code <= PIN_AUTH_CODE_MAX; code++) {
52 MessageParcel data;
53 MessageParcel reply;
54 MessageOption optionSync = MessageOption::TF_SYNC;
55 MessageOption optionAsync = MessageOption::TF_ASYNC;
56 // Sync
57 data.WriteInterfaceToken(PIN_AUTH_INTERFACE_TOKEN);
58 data.WriteBuffer(rawData, size);
59 data.RewindRead(0);
60 (void)pinAuthService.OnRemoteRequest(code, data, reply, optionSync);
61 // Async
62 data.WriteInterfaceToken(PIN_AUTH_INTERFACE_TOKEN);
63 data.WriteBuffer(rawData, size);
64 data.RewindRead(0);
65 (void)pinAuthService.OnRemoteRequest(code, data, reply, optionAsync);
66 }
67 return true;
68 }
69 } // namespace
70 } // namespace PinAuth
71 } // namespace UserIam
72 } // namespace OHOS
73
74 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)75 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
76 {
77 OHOS::UserIam::PinAuth::PinAuthStubFuzzTest(data, size);
78 return 0;
79 }
80