diff --git a/test/BUILD.gn b/test/BUILD.gn index c856a29d07410f6762367b2c15713fd527d77ca9..e5cb6fa45c39bd07b060a512b7a0f3de40896eb8 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1,28 +1,28 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -group("test") { - testonly = true - - deps = [] - if (support_jsapi) { - deps += [ - "benchmarktest:benchmarktest", - "commonfuzztest:fuzztest", - "interfacesfuzztest:fuzztest", - "servicesfuzztest:fuzztest", - "softbusfuzztest:fuzztest", - "unittest:unittest", - ] - } -} +# Copyright (c) 2022-2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("test") { + testonly = true + + deps = [] + if (support_jsapi) { + deps += [ + "benchmarktest:benchmarktest", + "commonfuzztest:fuzztest", + "interfacesfuzztest:fuzztest", + "servicesfuzztest:fuzztest", + "softbusfuzztest:fuzztest", + "unittest:unittest", + ] + } +} diff --git a/test/commonfuzztest/BUILD.gn b/test/commonfuzztest/BUILD.gn index c88c67ba243daa0e32af9e3f00ab22ec24c2da27..725e52823ec5c842dd721fa0ed98a4c86be6e852 100644 --- a/test/commonfuzztest/BUILD.gn +++ b/test/commonfuzztest/BUILD.gn @@ -15,13 +15,17 @@ group("fuzztest") { testonly = true deps = [ + "authacl_fuzzer:fuzztest", + "authcredential_fuzzer:fuzztest", "authenticatedevice_fuzzer:fuzztest", "authenticatedeviceservice_fuzzer:fuzztest", "authenticatedeviceserviceimpl_fuzzer:fuzztest", "dmauthmanager_fuzzer:fuzztest", "dmauthmanagerv2_fuzzer:fuzztest", + "dmanonyous_fuzzer:fuzztest", "dmcommoneventmanager_fuzzer:fuzztest", "dmcredentialimpl_fuzzer:fuzztest", + "dmfreezeprocess_fuzzer:fuzztest", "generateencrypteduuid_fuzzer:fuzztest", "getdeviceinfo_fuzzer:fuzztest", "hichainconnector_fuzzer:fuzztest", diff --git a/test/commonfuzztest/authacl_fuzzer/BUILD.gn b/test/commonfuzztest/authacl_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6800b459d3b2c731b2f82380c8e4cb6794888e23 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AuthAclFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/commonfuzztest/authacl_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/authentication_v2", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/dependency/timer", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "auth_acl_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutilstest", + ] + + external_deps = [ + "cJSON:cjson", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"AuthAclFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":AuthAclFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..327347467443f73f08d787eefee99ca9c8c0f75b --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "auth_acl_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_auth_state.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +void AuthAclFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); + std::string result = fdp.ConsumeRandomLengthString(); + std::shared_ptr authSink = std::make_shared(); + std::shared_ptr authSrc = std::make_shared(); + + authSink->GetStateType(); + authSrc->GetStateType(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::AuthAclFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..6e30090a78af52782e611ce889b13336f8a51412 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUTH_ACL_FUZZER_H +#define AUTH_ACL_FUZZER_H + +#define FUZZ_PROJECT_NAME "authacl_fuzzer" + +#endif // AUTH_ACL_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/authacl_fuzzer/corpus/init b/test/commonfuzztest/authacl_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8f37f09254457133cae0f828d0a5faee7dcbd779 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/commonfuzztest/authacl_fuzzer/project.xml b/test/commonfuzztest/authacl_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonfuzztest/authcredential_fuzzer/BUILD.gn b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5928e20ddbc15ba59a79f7672472915d72c20ccf --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("AuthCredentialFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/commonfuzztest/authcredential_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/authentication_v2", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/dependency/timer", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "auth_credential_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutilstest", + ] + + external_deps = [ + "cJSON:cjson", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"AuthCredentialFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":AuthCredentialFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f5e040fc21ccf52b21c41c0f30a38a739ceb433 --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "auth_credential_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_auth_state.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +constexpr uint32_t SERVICE = 2; + +void AuthCredentialFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FreezeProcess freezeProcess; + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->transmitData = fdp.ConsumeRandomLengthString(); + context->requestId = fdp.ConsumeIntegral(); + context->accesser.userId = fdp.ConsumeIntegral(); + context->accesser.isGenerateLnnCredential = true; + context->isAppCredentialVerified = false; + context->accesser.bindLevel = SERVICE; + std::shared_ptr authFirst = std::make_shared(); + std::shared_ptr authSecond = std::make_shared(); + std::shared_ptr authThird = std::make_shared(); + std::shared_ptr authForth = std::make_shared(); + std::shared_ptr authFifth = std::make_shared(); + std::shared_ptr authSixth = std::make_shared(); + + authFirst->Action(context); + authSecond->Action(context); + context->isAppCredentialVerified = true; + authSecond->Action(context); + context->accesser.isGenerateLnnCredential = false; + authFirst->GetStateType(); + authSecond->GetStateType(); + authThird->GetStateType(); + authForth->GetStateType(); + authFifth->GetStateType(); + authSixth->GetStateType(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::AuthCredentialFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.h b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..6e30090a78af52782e611ce889b13336f8a51412 --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUTH_ACL_FUZZER_H +#define AUTH_ACL_FUZZER_H + +#define FUZZ_PROJECT_NAME "authacl_fuzzer" + +#endif // AUTH_ACL_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/authcredential_fuzzer/corpus/init b/test/commonfuzztest/authcredential_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8f37f09254457133cae0f828d0a5faee7dcbd779 --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/commonfuzztest/authcredential_fuzzer/project.xml b/test/commonfuzztest/authcredential_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonfuzztest/dmanonyous_fuzzer/BUILD.gn b/test/commonfuzztest/dmanonyous_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dfc1d5b80891605770d7fcc43ddf8f2a858b1833 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DmAnonyousFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = "${devicemanager_path}/test/commonfuzztest/dmanonyous_fuzzer" + + include_dirs = [ + "${common_path}/include", + "${innerkits_path}/native_cpp/include", + "${services_path}/include/softbus", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dm_anonyous_fuzzer.cpp", + "${json_path}/src/json_object_cjson.cpp", ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmAnonyousFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmAnonyousFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/dmanonyous_fuzzer/corpus/init b/test/commonfuzztest/dmanonyous_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8f37f09254457133cae0f828d0a5faee7dcbd779 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dafa558a4119a9cb17ccf2a9d9c53691776d6037 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "device_manager_impl.h" +#include "dm_constants.h" +#include "softbus_listener.h" +#include "dm_anonymous.h" +namespace OHOS { +namespace DistributedHardware { + +void DmAnonyousFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + std::vector strList; + int64_t testNumber = 123; + int64_t decimal = 10; + strList.push_back("test1"); + strList.push_back("test2"); + GetAnonyStringList(strList); + std::vector intList; + intList.push_back(1); + GetAnonyInt32List(intList); + JsonObject jsonObj; + jsonObj["key1"] = testNumber; + jsonObj["key2"] = "value2"; + jsonObj["key3"] = true; + IsUint32(jsonObj, "key1"); + IsUint64(jsonObj, "key1"); + IsBool(jsonObj, "key3"); + std::map paramMap; + paramMap["key1"] = "value1"; + paramMap["key2"] = "value2"; + std::map paramMap2 = {}; + std::string jsonStr = ConvertMapToJsonString(paramMap); + ParseMapFromJsonString(jsonStr, paramMap2); + StringToInt("123", decimal); + StringToInt64("123", decimal); + int32_t versionNum = 0; + GetVersionNumber("1.0.0", versionNum); + GetCallerPkgName("com.example.app#test"); + GetSubscribeId("123#12345"); + std::multimap unorderedmap; + unorderedmap.insert(std::make_pair("key1", testNumber)); + IsValueExist(unorderedmap, "key1", testNumber); + GetSubStr("test#123", "#", 0); + IsJsonValIntegerString(jsonObj, "key2"); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmAnonyousFuzzTest(data, size); + + return 0; +} diff --git a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.h b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8047cdb14f74a49386aaea21f763e61bd3762705 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DM_ANONYOUS_TEST_FUZZER_H +#define DM_ANONYOUS_TEST_FUZZER_H + +#define FUZZ_PROJECT_NAME "dmanonyous_fuzzer" + +#endif // DM_ANONYOUS_TEST_FUZZER_H diff --git a/test/commonfuzztest/dmanonyous_fuzzer/project.xml b/test/commonfuzztest/dmanonyous_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..01ef24d272ca6803d48870076ae9785cf7196113 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DmFreezeProcessFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/commonfuzztest/dmfreezeprocess_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/authentication_v2", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/dependency/timer", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dm_freeze_process_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutilstest", + ] + + external_deps = [ + "cJSON:cjson", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmFreezeProcessFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmFreezeProcessFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init b/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8f37f09254457133cae0f828d0a5faee7dcbd779 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4c2c902eb03d195f1efd24f8f2fe686bbbec7b7 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dm_freeze_process_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { +constexpr const char* BIND_FAILED_EVENTS_KEY = "bindFailedEvents"; +constexpr const char* FREEZE_STATE_KEY = "freezeState"; +constexpr const char* START_FREEZE_TIME_KEY = "startFreezeTimeStamp"; +constexpr const char* STOP_FREEZE_TIME_KEY = "stopFreezeTimeStamp"; +constexpr const char* FAILED_TIMES_STAMPS_KEY = "failedTimeStamps"; +constexpr const char* FREEZE_TIMES_STAMPS_KEY = "freezeTimeStamps"; +constexpr const char* CAST_BUNDLE_NAME = "cast_engine_service"; +constexpr int32_t MAX_CONTINUEOUS_BIND_FAILED_NUM = 2; +constexpr int64_t CONTINUEOUS_FAILED_INTERVAL = 6 * 60; +constexpr int64_t DATA_REFRESH_INTERVAL = 20 * 60; +constexpr int64_t NOT_FREEZE_TIME = 0; +constexpr int64_t FIRST_FREEZE_TIME = 60; +constexpr int64_t SECOND_FREEZE_TIME = 3 * 60; +constexpr int64_t THIRD_FREEZE_TIME = 5 * 60; +constexpr int64_t MAX_FREEZE_TIME = 10 * 60; +} // namespace + +void DmFreezeProcessFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); + std::string result = fdp.ConsumeRandomLengthString(); + DeviceFreezeState freezeStateObj; + BindFailedEvents bindFailedEvents; + std::string bundleName = CAST_BUNDLE_NAME; + int32_t deviceType = DEVICE_TYPE_TV; + int64_t reservedDataTimeStamp = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().ConvertJsonToDeviceFreezeState(result, freezeStateObj); + FreezeProcess::GetInstance().ConvertJsonToBindFailedEvents(result, bindFailedEvents); + bundleName = fdp.ConsumeRandomLengthString(); + deviceType = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().CleanBindFailedEvents(reservedDataTimeStamp); + FreezeProcess::GetInstance().CleanFreezeState(reservedDataTimeStamp); + FreezeProcess::GetInstance().ConvertDeviceFreezeStateToJson(freezeStateObj, result); + int64_t nowTime = NOT_FREEZE_TIME; + + int64_t nextTime = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().CleanFreezeRecord(nowTime); + FreezeProcess::GetInstance().UpdateFreezeState(nowTime); + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = FIRST_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = SECOND_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = MAX_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + FreezeProcess::GetInstance().DeleteFreezeRecord(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmFreezeProcessFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0628940ed1a9f8ec66d9f542b2ed03006d77208b --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DM_FREE_PROCESS_FUZZER_H +#define DM_FREE_PROCESS_FUZZER_H + +#define FUZZ_PROJECT_NAME "dmfreezeprocess_fuzzer" + +#endif // DM_FREE_PROCESS_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml b/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index aff6cb61d2a9874d5b00bdec5957ade828a03fa0..e820998354face4bd70916343a14975c8115c57a 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -1954,46 +1954,6 @@ HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_001, testing::ext::TestS ASSERT_EQ(ret, DM_OK); } -HWTEST_F(DmAuthManagerTest, GetTokenIdByBundleName_001, testing::ext::TestSize.Level1) -{ - int32_t userId = 1; - std::string bundleName = "b********Info"; - int64_t tokenId = 0; - EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(DM_OK)); - int32_t ret = authManager_->GetTokenIdByBundleName(userId, bundleName, tokenId); - ASSERT_EQ(ret, DM_OK); - - EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(ERR_DM_FAILED)); - EXPECT_CALL(*appManagerMock_, GetHapTokenIdByName(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED)); - ret = authManager_->GetTokenIdByBundleName(userId, bundleName, tokenId); - ASSERT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*appManagerMock_, GetHapTokenIdByName(_, _, _, _)).WillOnce(Return(DM_OK)); - ret = authManager_->GetTokenIdByBundleName(userId, bundleName, tokenId); - ASSERT_EQ(ret, DM_OK); - - std::string deviceId = "de*******8"; - authManager_->authResponseContext_ = std::make_shared(); - authManager_->authRequestContext_ = std::make_shared(); - authManager_->authRequestContext_->connSessionType = CONN_SESSION_TYPE_HML; - authManager_->JoinLnn(deviceId, false); - - int32_t errorCode = 0; - std::shared_ptr listener = std::make_shared(); - authManager_->authUiStateMgr_ = std::make_shared(listener); - authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE; - authManager_->UpdateInputPincodeDialog(errorCode); - - authManager_->authResponseContext_->authType = AUTH_TYPE_NFC; - errorCode = ERR_DM_HICHAIN_PROOFMISMATCH; - authManager_->pincodeDialogEverShown_ = false; - authManager_->authRequestContext_->hostPkgName = "hostPkgName"; - authManager_->importAuthCode_ = "14785"; - authManager_->importPkgName_ = "hostPkgName"; - authManager_->UpdateInputPincodeDialog(errorCode); -} - HWTEST_F(DmAuthManagerTest, CheckNeedShowAuthInfoDialog_001, testing::ext::TestSize.Level1) { authManager_->authResponseContext_ = std::make_shared(); diff --git a/test/commonunittest/UTTest_hichain_connector.cpp b/test/commonunittest/UTTest_hichain_connector.cpp old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/BUILD.gn b/test/interfacesfuzztest/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn old mode 100755 new mode 100644 index a706fd85fd9b3811cc8d806586ca0ac77e5abd67..a7e9c70382236ee1d7ae696f97438bb8ea36608b --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn @@ -63,7 +63,7 @@ ohos_fuzztest("DeviceManagerImplFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", + "${utils_path}:devicemanagerutilstest", ] defines = [ diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/corpus/init b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp old mode 100755 new mode 100644 index 69cebe8cfdf924f777e0d2092c2be64143daae33..a42e4514577d312ed45213ae09d403e627c36cd7 --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp @@ -13,253 +13,282 @@ * limitations under the License. */ - #include - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include +#include - #include "device_manager_impl.h" - - namespace OHOS { - namespace DistributedHardware { - - namespace { - - } - - void StopAuthenticateDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); - DeviceManagerImpl::GetInstance().OnDmServiceDied(); - } - - void UnBindDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); - } - - void ShiftLNNGearTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); - } - - void RegDevTrustChangeCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::shared_ptr callback = nullptr; - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); - } - - void GetNetworkIdByUdidTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string udid = fdp.ConsumeRandomLengthString(); - std::string networkId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); - } - - void RegisterCredentialAuthStatusCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); - } - - void GetAllTrustedDeviceListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string extra = fdp.ConsumeRandomLengthString(); - std::vector deviceList; - DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); - } - - void RegisterSinkBindCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); - } - - void GetDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void GetDeviceIconInfoTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void PutDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::vector deviceProfileInfoList; - DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); - } - - void GetLocalDisplayDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string displayName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); - } - - void GetDeviceNetworkIdListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - NetworkIdQueryFilter queryFilter; - std::vector networkIds; - DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); - } - - void SetLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); - } - - void SetRemoteDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); - } - - void RestoreLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); - } - - void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DMLocalServiceInfo info; - DeviceManagerImpl::GetInstance(). - GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); - } - - void UnRegisterPinHolderCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); - } - } - } +#include "device_manager_impl.h" + +namespace OHOS { +namespace DistributedHardware { - /* Fuzzer entry point */ - extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) - { - /* Run your code on data */ - OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); - OHOS::DistributedHardware::UnBindDeviceTest(data, size); - OHOS::DistributedHardware::ShiftLNNGearTest(data, size); - OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); - OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); - OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); - OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); - OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); - OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); - OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); - OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); - OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); - OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); - OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); - return 0; - } - \ No newline at end of file +namespace {} + +void StopAuthenticateDeviceTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); + DeviceManagerImpl::GetInstance().OnDmServiceDied(); +} + +void UnBindDeviceTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); +} + +void ShiftLNNGearTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); +} + +void RegDevTrustChangeCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr callback = nullptr; + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); +} + +void GetNetworkIdByUdidTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string udid = fdp.ConsumeRandomLengthString(); + std::string networkId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); +} + +void RegisterCredentialAuthStatusCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); +} + +void GetAllTrustedDeviceListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + std::vector deviceList; + DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); +} + +void RegisterSinkBindCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); +} + +void GetDeviceProfileInfoListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void GetDeviceIconInfoTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void PutDeviceProfileInfoListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::vector deviceProfileInfoList; + DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); +} + +void GetLocalDisplayDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string displayName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); +} + +void GetDeviceNetworkIdListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + NetworkIdQueryFilter queryFilter; + std::vector networkIds; + DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); +} + +void SetLocalDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); +} + +void SetRemoteDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); +} + +void RestoreLocalDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); +} + +void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DMLocalServiceInfo info; + DeviceManagerImpl::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); +} + +void UnRegisterPinHolderCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); +} + +void DeviceManagerImplFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t pinExchangeType = fdp.ConsumeIntegral(); + OHOS::DistributedHardware::DmDeviceIconInfoFilterOptions filterOptions; + DMLocalServiceInfo localServiceInfo; + DmAccessCaller caller; + DmAccessCallee callee; + DMIpcCmdInterfaceCode ipcCode = REGISTER_DEVICE_MANAGER_LISTENER; + DeviceManagerImpl::GetInstance().GetLocalDeviceName(pkgName, deviceName); + DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId, extra); + DeviceManagerImpl::GetInstance().UnRegisterSinkBindCallback(pkgName); + DeviceManagerImpl::GetInstance().RegisterLocalServiceInfo(localServiceInfo); + DeviceManagerImpl::GetInstance().UnRegisterLocalServiceInfo(bundleName, pinExchangeType); + DeviceManagerImpl::GetInstance().UpdateLocalServiceInfo(localServiceInfo); + DeviceManagerImpl::GetInstance().CheckAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckSrcAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckSinkAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckSrcIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckSinkIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckAclByIpcCode(caller, callee, ipcCode); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); + OHOS::DistributedHardware::UnBindDeviceTest(data, size); + OHOS::DistributedHardware::ShiftLNNGearTest(data, size); + OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); + OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); + OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); + OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); + OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); + OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); + OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); + OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); + OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); + OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); + OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); + OHOS::DistributedHardware::DeviceManagerImplFuzzTest(data, size); + return 0; +} diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.h b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/project.xml b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index 074d1cd33715a9f81bbaddd058e4493560e36ee3..e6a972d7f23f1b823e1fd87fa3308e49dc573888 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -28,6 +28,7 @@ group("fuzztest") { "devicenamemanagerone_fuzzer:fuzztest", "deviceprofileconnector_fuzzer:fuzztest", "devicepublish_fuzzer:fuzztest", + "dmauthattestcommon_fuzzer:fuzztest", "dmcommtool_fuzzer:fuzztest", "dmcommtooltwo_fuzzer:fuzztest", "dmtransport_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp b/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp index 73a030896499aef157bc126129a446879c062779..679739aedb22b4b97ec802892e62a4af6f908dc4 100644 --- a/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp +++ b/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp @@ -151,7 +151,86 @@ void AuthMessageProcessorFuzzTest(const uint8_t* data, size_t size) dmAuthMessageProcessor_ -> SetLnnAccessControlList(context_, accesser, accessee); AuthMessageProcessorFuzzTestNext(jsonObject); } + +void AuthMessageProcessorFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string message = fdp.ConsumeRandomLengthString(); + std::string inputStr = fdp.ConsumeRandomLengthString(); + std::string compressed = fdp.ConsumeRandomLengthString(); + std::string trustDeviceId = fdp.ConsumeRandomLengthString(); + std::string encSyncMsg = fdp.ConsumeRandomLengthString(); + std::string enSyncMsg = fdp.ConsumeRandomLengthString(); + std::string aclStr = fdp.ConsumeRandomLengthString(); + uint32_t keyLen = fdp.ConsumeIntegralInRange(0, 1024); + uint32_t oriLen = fdp.ConsumeIntegralInRange(0, 1024); + std::vector sessionKey = fdp.ConsumeBytes(keyLen); + int32_t userId = fdp.ConsumeIntegral(); + int32_t skId = fdp.ConsumeIntegral(); + DistributedDeviceProfile::AccessControlProfile acl; + DistributedDeviceProfile::Accesser accesser; + DistributedDeviceProfile::Accessee accessee; + acl.SetExtraData(fdp.ConsumeRandomLengthString()); + accesser.SetAccesserExtraData(fdp.ConsumeRandomLengthString()); + accessee.SetAccesseeExtraData(fdp.ConsumeRandomLengthString()); + DmAccess access; + JsonObject jsonObject; + GenerateJsonObject(jsonObject, fdp); + dmAuthMessageProcessor_->CheckLogicalSessionId(jsonObject, context_); + jsonObject[TAG_TRANSMIT_SK_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_TRANSMIT_SK_TIMESTAMP] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_TRANSMIT_CREDENTIAL_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_DMVERSION] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_LNN_SK_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_LNN_SK_TIMESTAMP] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_LNN_CREDENTIAL_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_ACCESS] = fdp.ConsumeRandomLengthString(); + // Run ParseDmAccessToSync + dmAuthMessageProcessor_->ParseSyncMessage(context_, access, jsonObject); + jsonObject[TAG_AUTH_TYPE_LIST] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_EXTRA_INFO] = fdp.ConsumeRandomLengthString(); + // Run stringToVectorAuthType + dmAuthMessageProcessor_->ParseMessageRespUserConfirm(jsonObject, context_); } + +void AuthMessageProcessorSecondFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + JsonItemObject jsonItemObject; + DmAccessToSync sync_table = { .deviceName = fdp.ConsumeRandomLengthString(), + .deviceNameFull = fdp.ConsumeRandomLengthString(), + .deviceId = fdp.ConsumeRandomLengthString(), + .userId = fdp.ConsumeIntegral(), + .accountId = fdp.ConsumeRandomLengthString(), + .tokenId = fdp.ConsumeIntegral(), + .bundleName = fdp.ConsumeRandomLengthString(), + .pkgName = fdp.ConsumeRandomLengthString(), + .bindLevel = fdp.ConsumeIntegral(), + .sessionKeyId = fdp.ConsumeIntegral(), + .skTimeStamp = fdp.ConsumeIntegral() }; + FromJson(jsonItemObject, sync_table); + DmAccessControlTable control_table = { .accessControlId = fdp.ConsumeIntegral(), + .accesserId = fdp.ConsumeIntegral(), + .accesseeId = fdp.ConsumeIntegral(), + .deviceId = fdp.ConsumeRandomLengthString(), + .sessionKey = fdp.ConsumeRandomLengthString(), + .bindType = fdp.ConsumeIntegral(), + .authType = fdp.ConsumeIntegral(), + .deviceType = fdp.ConsumeIntegral(), + .deviceIdHash = fdp.ConsumeRandomLengthString(), + .status = fdp.ConsumeIntegral(), + .validPeriod = fdp.ConsumeIntegral(), + .lastAuthTime = fdp.ConsumeIntegral(), + .bindLevel = fdp.ConsumeIntegral() }; + FromJson(jsonItemObject, control_table); +} +} // namespace DistributedHardware } /* Fuzzer entry point */ @@ -159,6 +238,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::AuthMessageProcessorFuzzTest(data, size); - + OHOS::DistributedHardware::AuthMessageProcessorFirstFuzzTest(data, size); + OHOS::DistributedHardware::AuthMessageProcessorSecondFuzzTest(data, size); return 0; } diff --git a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn index e769025ecf720aa789b5e680076772cf2d957812..a129f111d7fe9d2f2720506ed8ccd23dcbc79f88 100644 --- a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn @@ -63,7 +63,7 @@ ohos_fuzztest("DeviceNameManagerFuzzTest") { deps = [ "${devicemanager_path}/services/service:devicemanagerservice", - "${utils_path}:devicemanagerutils", + "${utils_path}:devicemanagerutilstest", ] defines = [ diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn b/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0b933d849dd8a22bf6cc9e8a3ba530768963403c --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2022-2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DmAuthAttestCommonFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/dmauthattestcommon_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/attest", + "${utils_path}/include/kvadapter", + "${json_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${servicesimpl_path}/src/adapter/standard/dm_adapter_manager.cpp", + "dm_auth_attest_common_fuzzer.cpp", + "${json_path}/src/json_object_cjson.cpp", + ] + + deps = [ + "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmAuthAttestCommonFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "safwk:system_ability_fwk", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmAuthAttestCommonFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init b/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..9c560fe896401f2d179c49f5946f5f1dc4a4b3ea --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..799eed03bb5dc2c0aa7188559a4a56bcb09386c5 --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dm_auth_attest_common_fuzzer.h" + +#include + +#include "dm_auth_attest_common.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmAuthAttestCommonFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + DmCertChain* chain = new DmCertChain; + chain->cert = new DmBlob[1]; + chain->certCount = 1; + int32_t maxLen = 65535; + chain->cert[0].size = size; + if (size > 0 && size <= maxLen) { + chain->cert[0].data = new uint8_t[size]; + *chain->cert[0].data = fdp.ConsumeIntegral(); + } + std::string str_value = fdp.ConsumeRandomLengthString(); + JsonItemObject jsonItem; + jsonItem.PushBack(str_value); + AuthAttestCommon::GetInstance().SerializeDmCertChain(nullptr); + AuthAttestCommon::GetInstance().SerializeDmCertChain(chain); + AuthAttestCommon::GetInstance().FreeDmCertChain(*chain); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmAuthAttestCommonFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e4e5a1fff7cec2c83d9086469918a326e23317dd --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H +#define DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H + +#define FUZZ_PROJECT_NAME "dmauthattestcommon_fuzzer" + +#endif // DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml b/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp index f8b0b9354412c9bd1ac7b07b3f0fae1872009f62..f8d04a6bd24777c55fb35bdd0d39b4ac1ab85418 100644 --- a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp +++ b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp @@ -62,6 +62,32 @@ void DmCommToolFuzzTest(const uint8_t* data, size_t size) dmCommToolPtr_->GetDMTransportPtr(); dmCommToolPtr_->GetEventHandler(); } + +void DmCommToolFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + DMCommTool::DMCommToolEventHandler dmCommToolEventHandler( + AppExecFwk::EventRunner::Create(FUZZ_PROJECT_NAME), dmCommToolPtr_); + + int32_t socketId = fdp.ConsumeIntegral(); + std::string rmtNetworkId = fdp.ConsumeRandomLengthString(); + int32_t code = fdp.ConsumeIntegral(); + std::string msg = fdp.ConsumeRandomLengthString(); + std::shared_ptr commMsg = std::make_shared(code, msg); + std::shared_ptr innrCommMsg = std::make_shared(rmtNetworkId, commMsg, socketId); + UserIdsMsg userIdsMsg; + userIdsMsg.foregroundUserIds.push_back(DATA_LEN); + dmCommToolEventHandler.ParseUserIdsMsg(innrCommMsg, userIdsMsg); + AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(commMsg->code, innrCommMsg); + dmCommToolEventHandler.ProcessEvent(event); + dmCommToolPtr_->ProcessResponseUserStopEvent(innrCommMsg); + std::string commonEventType; + EventCallback eventCallback; + dmCommToolPtr_->StartCommonEvent(commonEventType, eventCallback); +} } } @@ -70,5 +96,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::DmCommToolFuzzTest(data, size); + OHOS::DistributedHardware::DmCommToolFirstFuzzTest(data, size); return 0; } diff --git a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp index 663947393fd90036cde76c0d6d9d4efc114cb1e0..54d374cd781be2c91b577dfc234bf9e45d7350b6 100644 --- a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp +++ b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp @@ -86,6 +86,34 @@ void DmTransPortMsgFuzzTest(const uint8_t* data, size_t size) notifyUserIds.ToString(); cJSON_Delete(jsonObject); } +void DmTransPortMsgFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t code = fdp.ConsumeIntegral(); + std::string msg(reinterpret_cast(data), size); + std::string remoteUdid(reinterpret_cast(data), size); + const char* jsonString = R"({ + "MsgType": "0", + "userId": "12345", + "accountId": "a******3", + "peerUdids": ["u******1", "u******2"], + "peerUdid": "p******d", + "accountName": "t******t", + "syncUserIdFlag": 1, + "userIds": [ + {"type": 1, "userId": 111}, + {"type": 0, "userId": 222} + ] + })"; + cJSON* jsonObject = nullptr; + LogoutAccountMsg accountInfo; + ToJson(jsonObject, accountInfo); + FromJson(jsonObject, accountInfo); + cJSON_Delete(jsonObject); +} } } @@ -94,5 +122,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::DmTransPortMsgFuzzTest(data, size); + OHOS::DistributedHardware::DmTransPortMsgFirstFuzzTest(data, size); return 0; }