1 /*
2 * Copyright (c) 2021-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 * miscservices under the License is miscservices 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 "screenlockauthmanager_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <string_ex.h>
21 #ifndef IS_SO_CROP_H
22 #include "strongauthmanager.h"
23
24 using namespace OHOS::ScreenLock;
25 #else
26 using namespace OHOS;
27 #endif // IS_SO_CROP_H
28
29 namespace OHOS {
30 constexpr size_t THRESHOLD = 10;
31 constexpr size_t LENGTH = 1;
32
FuzzScreenlockAuthManager(const uint8_t * rawData,size_t size)33 bool FuzzScreenlockAuthManager(const uint8_t *rawData, size_t size)
34 {
35 if (size < LENGTH) {
36 return true;
37 }
38
39 #ifndef IS_SO_CROP_H
40 auto authmanager = DelayedSingleton<StrongAuthManger>::GetInstance();
41 if (authmanager == nullptr) {
42 return false;
43 }
44
45 int32_t userId = 100;
46 int64_t triggerPeriod = 1;
47 int64_t timeInterval = 1000;
48 authmanager->RegistIamEventListener();
49 authmanager->StartStrongAuthTimer(userId);
50 authmanager->GetTimerId(userId);
51 authmanager->ResetStrongAuthTimer(userId, triggerPeriod);
52 authmanager->DestroyStrongAuthTimer(userId);
53 authmanager->DestroyAllStrongAuthTimer();
54 authmanager->UnRegistIamEventListener();
55 int32_t invalidUserId = 102;
56 authmanager->SetStrongAuthStat(invalidUserId, 0);
57 StrongAuthManger::authTimer timer(true, timeInterval, true, true);
58 authmanager->GetStrongAuthStat(invalidUserId);
59 authmanager->DestroyStrongAuthStateInfo(invalidUserId);
60 authmanager->InitStrongAuthStat(invalidUserId, 0);
61 authmanager->ResetStrongAuthTimer(invalidUserId, CRED_CHANGE_SECOND_STRONG_AUTH_TIMEOUT_MS);
62 authmanager->GetStrongAuthTimeTrigger(invalidUserId);
63 authmanager->DestroyStrongAuthStateInfo(invalidUserId);
64 authmanager->DestroyStrongAuthTimer(invalidUserId);
65 #endif // IS_SO_CROP_H
66 return true;
67 }
68
69 } // namespace OHOS
70
71 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)72 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
73 {
74 if (size < OHOS::THRESHOLD) {
75 return 0;
76 }
77
78 /* Run your code on data */
79 OHOS::FuzzScreenlockAuthManager(data, size);
80 return 0;
81 }