• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "user_cert_plugin_fuzzer.h"
17 
18 #include <system_ability_definition.h>
19 
20 #include "common_fuzzer.h"
21 #include "edm_ipc_interface_code.h"
22 #include "ienterprise_device_mgr.h"
23 #include "func_code.h"
24 #include "message_parcel.h"
25 #include "utils.h"
26 
27 namespace OHOS {
28 namespace EDM {
29 constexpr size_t MIN_SIZE = 24;
30 constexpr size_t WITHOUT_USERID = 0;
31 
32 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
34 {
35     if (data == nullptr) {
36         return 0;
37     }
38     if (size < MIN_SIZE) {
39         return 0;
40     }
41     int32_t pos = 0;
42     int32_t stringSize = (size - pos) / 9;
43     for (uint32_t operateType = static_cast<uint32_t>(FuncOperateType::GET);
44         operateType <= static_cast<uint32_t>(FuncOperateType::REMOVE); operateType++) {
45         uint32_t code = EdmInterfaceCode::INSTALL_CERTIFICATE;
46         code = POLICY_FUNC_CODE(operateType, code);
47 
48         AppExecFwk::ElementName admin;
49         admin.SetBundleName(CommonFuzzer::GetString(data, pos, stringSize, size));
50         admin.SetAbilityName(CommonFuzzer::GetString(data, pos, stringSize, size));
51         MessageParcel parcel;
52         parcel.WriteInterfaceToken(IEnterpriseDeviceMgrIdl::GetDescriptor());
53         parcel.WriteInt32(WITHOUT_USERID);
54         if (operateType == static_cast<uint32_t>(FuncOperateType::SET)) {
55             parcel.WriteParcelable(&admin);
56             std::vector <uint8_t> certArray{(*data)};
57             parcel.WriteUInt8Vector(certArray);
58             parcel.WriteString(CommonFuzzer::GetString(data, pos, stringSize, size));
59         } else if (operateType == static_cast<uint32_t>(FuncOperateType::REMOVE)) {
60             parcel.WriteParcelable(&admin);
61             parcel.WriteString(CommonFuzzer::GetString(data, pos, stringSize, size));
62         } else {
63             parcel.WriteString("");
64             parcel.WriteInt32(0);
65             parcel.WriteParcelable(&admin);
66         }
67         CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel);
68     }
69     return 0;
70 }
71 } // namespace EDM
72 } // namespace OHOS