1 /*
2 * Copyright (c) 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 * 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 "verifycredential_fuzzer.h"
17
18 #include "app_account_manager.h"
19 #include "app_account_common.h"
20 #include "account_log_wrapper.h"
21 #include <string>
22 #include <vector>
23
24 using namespace std;
25 using namespace OHOS::AccountSA;
26
27 class MockAuthenticatorCallback : public OHOS::AccountSA::IAppAccountAuthenticatorCallback {
28 public:
OnResult(int32_t resultCode,const OHOS::AAFwk::Want & result)29 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result) override
30 {
31 return;
32 }
OnRequestRedirected(OHOS::AAFwk::Want & request)33 void OnRequestRedirected(OHOS::AAFwk::Want& request) override
34 {
35 return;
36 }
OnRequestContinued()37 void OnRequestContinued() override
38 {
39 return;
40 }
AsObject()41 OHOS::sptr<OHOS::IRemoteObject> AsObject() override
42 {
43 return nullptr;
44 }
45 };
46
47 namespace OHOS {
VerifyCredentialFuzzTest(const uint8_t * data,size_t size)48 bool VerifyCredentialFuzzTest(const uint8_t* data, size_t size)
49 {
50 bool result = false;
51 if (size > 0) {
52 std::string testName(reinterpret_cast<const char*>(data), size);
53 std::string testOwner(reinterpret_cast<const char*>(data), size);
54 std::string testValue(reinterpret_cast<const char*>(data), size);
55 VerifyCredentialOptions options;
56 options.credentialType = testValue;
57 options.credential = testValue;
58 sptr<MockAuthenticatorCallback> callback = new (std::nothrow) MockAuthenticatorCallback();
59 result = AppAccountManager::VerifyCredential(testName, testOwner, options, callback);
60 }
61 return result;
62 }
63 }
64
65 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)66 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
67 {
68 /* Run your code on data */
69 OHOS::VerifyCredentialFuzzTest(data, size);
70 return 0;
71 }
72
73