• 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 "auth_acl_fuzzer.h"
17 
18 #include <fuzzer/FuzzedDataProvider.h>
19 #include <string>
20 
21 #include "device_manager_service_listener.h"
22 #include "dm_auth_state.h"
23 #include "dm_freeze_process.h"
24 
25 namespace OHOS {
26 namespace DistributedHardware {
AuthAclFuzzTest(const uint8_t * data,size_t size)27 void AuthAclFuzzTest(const uint8_t* data, size_t size)
28 {
29     if ((data == nullptr) || (size < sizeof(int32_t))) {
30         return;
31     }
32     FuzzedDataProvider fdp(data, size);
33     int32_t sessionId = fdp.ConsumeIntegral<int32_t>();
34     std::string result = fdp.ConsumeRandomLengthString();
35     std::string peerDeviceId = fdp.ConsumeRandomLengthString();
36     std::shared_ptr<AuthSinkDataSyncState> authSink = std::make_shared<AuthSinkDataSyncState>();
37     std::shared_ptr<AuthSrcDataSyncState> authSrc = std::make_shared<AuthSrcDataSyncState>();
38 
39     authSink->GetStateType();
40     authSrc->GetStateType();
41 
42     std::shared_ptr<DmAuthContext> context = std::make_shared<DmAuthContext>();
43     context->accesser.dmVersion = DM_VERSION_5_1_0;
44     context->accesser.isCommonFlag = true;
45     authSink->VerifyCertificate(context);
46     context->accesser.isCommonFlag = false;
47     authSink->VerifyCertificate(context);
48     authSink->VerifyCertificate(nullptr);
49     context->IsProxyBind = true;
50     authSink->DerivativeSessionKey(context);
51     authSrc->GetPeerDeviceId(context, peerDeviceId);
52 }
53 }
54 }
55 
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59     /* Run your code on data */
60     OHOS::DistributedHardware::AuthAclFuzzTest(data, size);
61     return 0;
62 }