From b7fd6678b72933f71b8ca015878a7c0dd9215adb Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 4 Jun 2025 18:07:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?dp=20idl=E5=8C=96=20=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL Change-Id: I0763935508e92fb08d43e1fa6c896b78327c7112 --- test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn b/test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn index 85a96b54a..edf37af8e 100644 --- a/test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/dpinitcallback_fuzzer/BUILD.gn @@ -81,6 +81,7 @@ ohos_fuzztest("DpInitCallbackFuzzTest") { "ipc:ipc_single", "napi:ace_napi", "safwk:system_ability_fwk", + "c_utils:utils", ] } -- Gitee From 9c705adc860adef4cf3af9111aca4c2b44e80768 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 5 Jun 2025 14:05:12 +0800 Subject: [PATCH 2/4] add dp idl depence. Signed-off-by: BrainL Change-Id: I4cca2608e82a584a64915de673230b02a5049ef5 --- .../authenticatedeviceservice_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../dmauthmanager_fuzzer/BUILD.gn | 1 + .../dmauthmanagerv2_fuzzer/BUILD.gn | 1 + .../hichainconnector_fuzzer/BUILD.gn | 1 + .../ondatareceived_fuzzer/BUILD.gn | 1 + .../ondatareceivedv2_fuzzer/BUILD.gn | 1 + test/commonfuzztest/onerror_fuzzer/BUILD.gn | 1 + test/commonfuzztest/onfinish_fuzzer/BUILD.gn | 1 + test/commonfuzztest/onrequest_fuzzer/BUILD.gn | 1 + test/commonfuzztest/pinauth_fuzzer/BUILD.gn | 1 + test/commonfuzztest/pinauthui_fuzzer/BUILD.gn | 1 + test/commonfuzztest/pinholder_fuzzer/BUILD.gn | 1 + .../cryptomgr_fuzzer/BUILD.gn | 1 + .../devicemanagerservice_fuzzer/BUILD.gn | 1 + .../devicenamemanager_fuzzer/BUILD.gn | 1 + .../devicenamemanagerone_fuzzer/BUILD.gn | 1 + .../dmsoftbuslistener_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../shiftlnngeardeviceservice_fuzzer/BUILD.gn | 1 + .../onbytesreceived_fuzzer/BUILD.gn | 1 + .../onsessionopened_fuzzer/BUILD.gn | 1 + .../softbusconnector_fuzzer/BUILD.gn | 1 + .../softbusconnectorcommon_fuzzer/BUILD.gn | 1 + .../softbusconnectorpublish_fuzzer/BUILD.gn | 1 + .../softbusconnectorstate_fuzzer/BUILD.gn | 1 + .../softbusconnectorstatic_fuzzer/BUILD.gn | 1 + .../softbussession_fuzzer/BUILD.gn | 1 + .../softbussessionobject_fuzzer/BUILD.gn | 1 + test/unittest/BUILD.gn | 43 +++++++++++++++++++ 30 files changed, 72 insertions(+) diff --git a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn index cab2d2cd6..dd637cbe3 100644 --- a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn @@ -83,6 +83,7 @@ ohos_fuzztest("AuthenticateDeviceServiceFuzzTest") { "ipc:ipc_single", "safwk:system_ability_fwk", "selinux_adapter:librestorecon", + "c_utils:utils", ] } diff --git a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn index 6a4dccbc0..7ff74bcad 100644 --- a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn @@ -84,6 +84,7 @@ ohos_fuzztest("AuthenticateDeviceServiceImplFuzzTest") { "ipc:ipc_single", "safwk:system_ability_fwk", "selinux_adapter:librestorecon", + "c_utils:utils", ] } diff --git a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn b/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn index 1d394b8ad..ad822cef1 100644 --- a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("DmAuthManagerFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn b/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn index fb2de39ca..d2a2b272b 100644 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn @@ -62,6 +62,7 @@ ohos_fuzztest("DmAuthManagerV2FuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn b/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn index 17b0edcfd..ce75c34f0 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn +++ b/test/commonfuzztest/hichainconnector_fuzzer/BUILD.gn @@ -62,6 +62,7 @@ ohos_fuzztest("HichainConnectorFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn index dd8015779..8a55bc048 100644 --- a/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn +++ b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("OnDataReceivedFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn b/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn index b81e1b472..c0484bc82 100644 --- a/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn +++ b/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("OnDataReceivedV2FuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/onerror_fuzzer/BUILD.gn b/test/commonfuzztest/onerror_fuzzer/BUILD.gn index 9d9d2801d..e7f3b6c15 100644 --- a/test/commonfuzztest/onerror_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onerror_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("OnErrorFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn index 3881335e7..bf6fbc200 100644 --- a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("OnFinishFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn index 34a301d7a..b4f835c7a 100644 --- a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("OnRequestFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/commonfuzztest/pinauth_fuzzer/BUILD.gn b/test/commonfuzztest/pinauth_fuzzer/BUILD.gn index f8ad7083e..ba1c5a56e 100644 --- a/test/commonfuzztest/pinauth_fuzzer/BUILD.gn +++ b/test/commonfuzztest/pinauth_fuzzer/BUILD.gn @@ -90,6 +90,7 @@ ohos_fuzztest("PinAuthFuzzTest") { "ipc:ipc_single", "resource_management:resmgr_napi_core", "safwk:system_ability_fwk", + "c_utils:utils", ] } diff --git a/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn b/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn index c24e87558..c1c110a37 100644 --- a/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn +++ b/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn @@ -90,6 +90,7 @@ ohos_fuzztest("PinAuthUiFuzzTest") { "init:libbegetutil", "resource_management:resmgr_napi_core", "safwk:system_ability_fwk", + "c_utils:utils", ] } diff --git a/test/commonfuzztest/pinholder_fuzzer/BUILD.gn b/test/commonfuzztest/pinholder_fuzzer/BUILD.gn index c673b1edc..1cb5503a3 100644 --- a/test/commonfuzztest/pinholder_fuzzer/BUILD.gn +++ b/test/commonfuzztest/pinholder_fuzzer/BUILD.gn @@ -90,6 +90,7 @@ ohos_fuzztest("PinHolderFuzzTest") { "init:libbegetutil", "resource_management:resmgr_napi_core", "safwk:system_ability_fwk", + "c_utils:utils", ] } diff --git a/test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn b/test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn index 5d38cb5fc..8689770ed 100644 --- a/test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/cryptomgr_fuzzer/BUILD.gn @@ -80,6 +80,7 @@ ohos_fuzztest("CryptoMgrFuzzTest") { "ipc:ipc_single", "napi:ace_napi", "safwk:system_ability_fwk", + "c_utils:utils", ] } diff --git a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn index 21041b11a..3e388d489 100644 --- a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn @@ -80,6 +80,7 @@ ohos_fuzztest("DeviceManagerServiceFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] } diff --git a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn index e769025ec..68fa9fb00 100644 --- a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn @@ -84,6 +84,7 @@ ohos_fuzztest("DeviceNameManagerFuzzTest") { "napi:ace_napi", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "c_utils:utils", ] } diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn b/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn index 4de76326b..28d3221cb 100644 --- a/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn @@ -81,6 +81,7 @@ ohos_fuzztest("DeviceNameManagerOneFuzzTest") { "hilog:libhilog", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] } diff --git a/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn b/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn index 414caff5a..25e741705 100644 --- a/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn @@ -82,6 +82,7 @@ ohos_fuzztest("DmSoftbusListenerFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] } diff --git a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn index 7c353daa9..a8c67c492 100644 --- a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn @@ -74,6 +74,7 @@ ohos_fuzztest("GetTrustedDeviceListServiceFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn index a43f96e63..3e2229974 100644 --- a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn @@ -74,6 +74,7 @@ ohos_fuzztest("ShiftLNNGearDeviceServiceFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn b/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn index 872e0c8a2..c1de5afe0 100644 --- a/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn @@ -64,6 +64,7 @@ ohos_fuzztest("OnBytesReceivedFuzzTest") { "dsoftbus:softbus_client", "init:libbegetutil", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/onsessionopened_fuzzer/BUILD.gn b/test/softbusfuzztest/onsessionopened_fuzzer/BUILD.gn index cb057edf6..c04f59be8 100644 --- a/test/softbusfuzztest/onsessionopened_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsessionopened_fuzzer/BUILD.gn @@ -66,6 +66,7 @@ ohos_fuzztest("OnSessionOpenedFuzzTest") { "hilog:libhilog", "init:libbegetutil", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/softbusconnector_fuzzer/BUILD.gn b/test/softbusfuzztest/softbusconnector_fuzzer/BUILD.gn index 278ad04ea..506a15750 100644 --- a/test/softbusfuzztest/softbusconnector_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbusconnector_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("SoftbusConnectorFuzzTest") { "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/softbusconnectorcommon_fuzzer/BUILD.gn b/test/softbusfuzztest/softbusconnectorcommon_fuzzer/BUILD.gn index a9b8b5aa6..8da9b07e5 100644 --- a/test/softbusfuzztest/softbusconnectorcommon_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbusconnectorcommon_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("SoftbusConnectorCommonFuzzTest") { "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/softbusconnectorpublish_fuzzer/BUILD.gn b/test/softbusfuzztest/softbusconnectorpublish_fuzzer/BUILD.gn index 9669c6d31..cf7afb2c9 100644 --- a/test/softbusfuzztest/softbusconnectorpublish_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbusconnectorpublish_fuzzer/BUILD.gn @@ -58,6 +58,7 @@ ohos_fuzztest("SoftbusConnectorPublishFuzzTest") { "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/softbusconnectorstate_fuzzer/BUILD.gn b/test/softbusfuzztest/softbusconnectorstate_fuzzer/BUILD.gn index b8f593bcb..6aa349c41 100644 --- a/test/softbusfuzztest/softbusconnectorstate_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbusconnectorstate_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("SoftbusConnectorStateFuzzTest") { "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/softbusconnectorstatic_fuzzer/BUILD.gn b/test/softbusfuzztest/softbusconnectorstatic_fuzzer/BUILD.gn index 07cf961cb..35069542b 100644 --- a/test/softbusfuzztest/softbusconnectorstatic_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbusconnectorstatic_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("SoftbusConnectorStaticFuzzTest") { "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/softbussession_fuzzer/BUILD.gn b/test/softbusfuzztest/softbussession_fuzzer/BUILD.gn index 158f1f9a9..88461a689 100644 --- a/test/softbusfuzztest/softbussession_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbussession_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("SoftbusSessionFuzzTest") { "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn b/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn index 7f61cc161..73fe761c4 100644 --- a/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("SoftbusSessionObjectFuzzTest") { "dsoftbus:softbus_client", "init:libbegetutil", "safwk:system_ability_fwk", + "c_utils:utils", ] defines = [ diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index f0af8d78f..8b4763203 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -124,6 +124,7 @@ ohos_unittest("UTTest_pin_auth") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -151,6 +152,7 @@ ohos_unittest("UTTest_pin_auth_ui") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -177,6 +179,7 @@ ohos_unittest("UTTest_ipc_cmd_parser_client") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] cflags = [ @@ -217,6 +220,7 @@ ohos_unittest("UTTest_ipc_cmd_parser_service") { "hicollie:libhicollie", "hilog:libhilog", "safwk:system_ability_fwk", + "c_utils:utils", ] cflags = [ @@ -399,6 +403,7 @@ ohos_unittest("UTTest_device_manager_service") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "c_utils:utils", ] } @@ -426,6 +431,7 @@ ohos_unittest("UTTest_dm_softbus_cache") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "c_utils:utils", ] } @@ -459,6 +465,7 @@ ohos_unittest("UTTest_device_manager_service_three") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "c_utils:utils", ] } @@ -483,6 +490,7 @@ ohos_unittest("UTTest_device_manager_service_notify") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -505,6 +513,7 @@ ohos_unittest("UTTest_hichain_auth_connector") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -530,6 +539,7 @@ ohos_unittest("UTTest_hichain_connector") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -552,6 +562,7 @@ ohos_unittest("UTTest_mine_hichain_connector") { "dsoftbus:softbus_client", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -588,6 +599,7 @@ ohos_unittest("UTTest_mine_softbus_listener") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "openssl:libcrypto_shared", + "c_utils:utils", ] } @@ -620,6 +632,7 @@ ohos_unittest("UTTest_softbus_connector") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "os_account:libaccountkits", + "c_utils:utils", ] } @@ -658,6 +671,7 @@ ohos_unittest("UTTest_softbus_listener") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -690,6 +704,7 @@ ohos_unittest("UTTest_softbus_listener_two") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -721,6 +736,7 @@ ohos_unittest("UTTest_softbus_publish") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -748,6 +764,7 @@ ohos_unittest("UTTest_softbus_session") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -945,6 +962,7 @@ ohos_unittest("UTTest_ipc_server_client_proxy") { "hicollie:libhicollie", "hilog:libhilog", "safwk:system_ability_fwk", + "c_utils:utils", ] } @@ -990,6 +1008,7 @@ ohos_unittest("UTTest_ipc_server_stub") { "googletest:gmock", "hilog:libhilog", "safwk:system_ability_fwk", + "c_utils:utils", ] } @@ -1168,6 +1187,7 @@ ohos_unittest("UTTest_dm_device_state_manager") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -1197,6 +1217,7 @@ ohos_unittest("UTTest_dm_device_state_manager_two") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -1249,6 +1270,7 @@ ohos_unittest("UTTest_device_manager_service_impl") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "c_utils:utils", ] } @@ -1279,6 +1301,7 @@ ohos_unittest("UTTest_device_manager_service_impl_first") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "c_utils:utils", ] } @@ -1308,6 +1331,7 @@ ohos_unittest("UTTest_device_manager_service_listener") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -1333,6 +1357,7 @@ ohos_unittest("UTTest_auth_message_processor") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -1354,6 +1379,7 @@ ohos_unittest("UTTest_auth_response_state") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -1375,6 +1401,7 @@ ohos_unittest("UTTest_auth_request_state") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -1426,6 +1453,7 @@ ohos_unittest("UTTest_dm_auth_manager_first") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] cflags = [ @@ -1468,6 +1496,7 @@ ohos_unittest("UTTest_dm_auth_manager_second") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -1492,6 +1521,7 @@ ohos_unittest("UTTest_dm_auth_manager_third") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] cflags = [ @@ -1551,6 +1581,7 @@ ohos_unittest("UTTest_discovery_filter") { "device_info_manager:distributed_device_profile_sdk", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -1578,6 +1609,7 @@ ohos_unittest("UTTest_discovery_manager") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -1609,6 +1641,7 @@ ohos_unittest("UTTest_dm_deviceprofile_connector") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -1638,6 +1671,7 @@ ohos_unittest("UTTest_dm_deviceprofile_connector_second") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -1662,6 +1696,7 @@ ohos_unittest("UTTest_dm_distributed_hardware_load") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "c_utils:utils", ] } @@ -1832,6 +1867,7 @@ ohos_unittest("UTTest_dp_inited_callback") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -1972,6 +2008,7 @@ ohos_unittest("UTTest_advertise_manager") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "c_utils:utils", ] } @@ -2036,6 +2073,7 @@ ohos_unittest("UTTest_auth_pin_auth_state") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -2063,6 +2101,7 @@ ohos_unittest("UTTest_dm_auth_message_processor") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -2094,6 +2133,7 @@ ohos_unittest("UTTest_auth_credential_state") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -2125,6 +2165,7 @@ ohos_unittest("UTTest_auth_acl") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -2158,6 +2199,7 @@ ohos_unittest("UTTest_auth_negotiate") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } @@ -2187,6 +2229,7 @@ ohos_unittest("UTTest_auth_confirm") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "c_utils:utils", ] } -- Gitee From 88f083830513f5540f3b788463819364053beb1f Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 5 Jun 2025 15:50:56 +0800 Subject: [PATCH 3/4] dp idl depence. Signed-off-by: BrainL Change-Id: Iec817e1619ff8b130e6c70504412a54f4bf7eb3e --- .../main/resources/en_GB/element/string.json | 7 + .../main/resources/zh_CN/element/string.json | 7 + .../kits/js/src/native_devicemanager_js.cpp | 2 + .../js4.0/src/native_devicemanager_js.cpp | 2 + .../include/cryptomgr/crypto_mgr.h | 2 +- .../include/device_manager_service_impl.h | 14 +- .../src/cryptomgr/crypto_mgr.cpp | 10 +- .../src/device_manager_service_impl.cpp | 319 +++++++++----- .../service/src/device_manager_service.cpp | 1 + test/servicesfuzztest/BUILD.gn | 1 + .../authmanager_fuzzer/BUILD.gn | 77 ++++ .../auth_manager_fuzzer.cpp | 410 ++++++++++++++++++ .../authmanager_fuzzer/auth_manager_fuzzer.h | 21 + .../authmanager_fuzzer/corpus/init | 13 + .../authmanager_fuzzer/project.xml | 25 ++ .../authmessageprocessor_fuzzer/BUILD.gn | 1 + .../UTTest_device_manager_service_impl.cpp | 58 +++ 17 files changed, 860 insertions(+), 110 deletions(-) create mode 100644 test/servicesfuzztest/authmanager_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp create mode 100644 test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.h create mode 100644 test/servicesfuzztest/authmanager_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/authmanager_fuzzer/project.xml diff --git a/display/entry/src/main/resources/en_GB/element/string.json b/display/entry/src/main/resources/en_GB/element/string.json index 29fb79aa7..c073b4dad 100644 --- a/display/entry/src/main/resources/en_GB/element/string.json +++ b/display/entry/src/main/resources/en_GB/element/string.json @@ -55,6 +55,13 @@ "attr":{ "priority":"translate" } + }, + { + "name":"dm_confirm_proxy", + "value":"%1$s on %2$s requests to connect to this device.Please select the authorized service:", + "attr":{ + "priority":"translate" + } } ] } \ No newline at end of file diff --git a/display/entry/src/main/resources/zh_CN/element/string.json b/display/entry/src/main/resources/zh_CN/element/string.json index db3d6d3a2..2c49b86ce 100644 --- a/display/entry/src/main/resources/zh_CN/element/string.json +++ b/display/entry/src/main/resources/zh_CN/element/string.json @@ -111,6 +111,13 @@ { "name":"dm_password_error", "value":"密码错误,连接失败。" + }, + { + "name":"dm_confirm_proxy", + "value":"%2$s的%1$s请求连接本机。请选择授权的业务:", + "attr":{ + "priority":"translate" + } } ] } \ No newline at end of file diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 2c619595f..633b02b6b 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -2084,6 +2084,8 @@ napi_value DeviceManagerNapi::GetTrustedDeviceList(napi_env env, napi_callback_i return CallDeviceList(env, info, deviceInfoListAsyncCallbackInfo); } else if (argc == DM_NAPI_ARGS_TWO) { return GetTrustedDeviceListByFilter(env, info, deviceInfoListAsyncCallbackInfo); + } else { + DeleteAsyncCallbackInfo(deviceInfoListAsyncCallbackInfo); } napi_get_undefined(env, &result); return result; diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 909fc4fc9..005d39c8a 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1346,6 +1346,8 @@ napi_value DeviceManagerNapi::GetAvailableDeviceList(napi_env env, napi_callback return nullptr; } return CallDeviceList(env, info, deviceBasicInfoListAsyncCallbackInfo); + } else { + DeleteAsyncCallbackInfo(deviceBasicInfoListAsyncCallbackInfo); } napi_get_undefined(env, &result); return result; diff --git a/services/implementation/include/cryptomgr/crypto_mgr.h b/services/implementation/include/cryptomgr/crypto_mgr.h index e31e27c15..da5ae1500 100644 --- a/services/implementation/include/cryptomgr/crypto_mgr.h +++ b/services/implementation/include/cryptomgr/crypto_mgr.h @@ -57,7 +57,7 @@ private: int32_t DoDecryptData(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen, unsigned char *decryptData, uint32_t *decryptLen); int32_t MbedAesGcmDecrypt(const AesGcmCipherKey *cipherKey, const unsigned char *cipherText, - uint32_t cipherTextSize, unsigned char *plain, uint32_t plainLen); + uint32_t cipherTextSize, unsigned char *plain, uint32_t &plainLen); private: std::mutex sessionKeyMtx_; DMSessionKey sessionKey_; diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 9fb44f256..914f152ec 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -289,10 +289,15 @@ private: void SetBindCallerInfoToBindParam(const std::map &bindParam, std::map &bindParamTmp, const DmBindCallerInfo &bindCallerInfo); std::string GetBundleLable(const std::string &bundleName); + int32_t GetLogicalIdAndTokenIdBySessionId(uint64_t &logicalSessionId, uint64_t &tokenId, int32_t sessionId); + void SaveTokenIdAndSessionId(uint64_t &tokenId, int32_t &sessionId, uint64_t &logicalSessionId); + void ReleaseMaps(); + int32_t InitNewProtocolAuthMgr(bool isSrcSide, uint64_t tokenId, uint64_t logicalSessionId, + const std::string &pkgName); + int32_t InitOldProtocolAuthMgr(uint64_t tokenId, const std::string &pkgName); private: std::shared_ptr authMgr_; // Old protocol only - std::mutex authMgrMtx_; - std::map> authMgrMap_; // New protocol sharing + std::shared_ptr hiChainConnector_; std::shared_ptr hiChainAuthConnector_; std::shared_ptr deviceStateMgr_; @@ -313,9 +318,14 @@ private: std::map sessionEnableCvMap_; // Condition variable corresponding to the session std::map sessionEnableMutexMap_; // Lock corresponding to the session std::map sessionEnableCvReadyMap_; // Condition variable ready flag + std::mutex logicalSessionId2TokenIdMapMtx_; std::map logicalSessionId2TokenIdMap_; // The relationship between logicalSessionId and tokenId + std::mutex logicalSessionId2SessionIdMapMtx_; std::map logicalSessionId2SessionIdMap_; // The relationship logicalSessionId and physical sessionId + std::mutex configsMapMutex_; std::map> configsMap_; // Import when authMgr is not initialized + std::mutex authMgrMapMtx_; + std::map> authMgrMap_; // New protocol sharing std::thread thread_; std::atomic running_; diff --git a/services/implementation/src/cryptomgr/crypto_mgr.cpp b/services/implementation/src/cryptomgr/crypto_mgr.cpp index 4af9f65f9..6cba98ca7 100644 --- a/services/implementation/src/cryptomgr/crypto_mgr.cpp +++ b/services/implementation/src/cryptomgr/crypto_mgr.cpp @@ -242,7 +242,7 @@ int32_t CryptoMgr::DecryptMessage(const std::string &inputMsg, std::string &outp } int32_t CryptoMgr::MbedAesGcmDecrypt(const AesGcmCipherKey *cipherKey, const unsigned char *cipherText, - uint32_t cipherTextSize, unsigned char *plain, uint32_t plainLen) + uint32_t cipherTextSize, unsigned char *plain, uint32_t &plainLen) { if ((cipherKey == NULL) || (cipherText == NULL) || (cipherTextSize <= OVERHEAD_LEN) || plain == NULL || (plainLen < cipherTextSize - OVERHEAD_LEN)) { @@ -268,9 +268,9 @@ int32_t CryptoMgr::MbedAesGcmDecrypt(const AesGcmCipherKey *cipherKey, const uns mbedtls_gcm_free(&aesContext); return ERR_DM_CRYPTO_OPT_FAILED; } - + plainLen = (uint32_t)actualPlainLen; mbedtls_gcm_free(&aesContext); - return actualPlainLen; + return DM_OK; } int32_t CryptoMgr::DoDecryptData(AesGcmCipherKey *cipherKey, const unsigned char *input, uint32_t inLen, @@ -286,10 +286,10 @@ int32_t CryptoMgr::DoDecryptData(AesGcmCipherKey *cipherKey, const unsigned char } uint32_t outLen = inLen - OVERHEAD_LEN; int32_t result = MbedAesGcmDecrypt(cipherKey, input, inLen, decryptData, outLen); - if (result <= 0) { + if (result != DM_OK) { return ERR_DM_CRYPTO_OPT_FAILED; } - *decryptLen = (uint32_t)result; + *decryptLen = outLen; return DM_OK; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 0b8b831ac..f76e29201 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -234,6 +234,7 @@ void DeviceManagerServiceImpl::ImportConfig(std::shared_ptr aut const std::string &pkgName) { // Import configuration + std::lock_guard configsLock(configsMapMutex_); if (configsMap_.find(tokenId) != configsMap_.end()) { authMgr->ImportAuthCode(configsMap_[tokenId]->pkgName, configsMap_[tokenId]->authCode); authMgr->RegisterAuthenticationType(configsMap_[tokenId]->authenticationType); @@ -266,6 +267,7 @@ void DeviceManagerServiceImpl::ImportAuthCodeToConfig(std::shared_ptrGetAuthCodeAndPkgName(pkgName, authCode); + std::lock_guard configsLock(configsMapMutex_); if (configsMap_.find(tokenId) == configsMap_.end()) { configsMap_[tokenId] = std::make_shared(); } @@ -273,6 +275,63 @@ void DeviceManagerServiceImpl::ImportAuthCodeToConfig(std::shared_ptrauthCode = authCode; } +int32_t DeviceManagerServiceImpl::InitNewProtocolAuthMgr(bool isSrcSide, uint64_t tokenId, uint64_t logicalSessionId, + const std::string &pkgName) +{ + if (pkgName.empty()) { + LOGE("pkgName is empty"); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("isSrcSide:%{public}d, tokenId: %{public}" PRIu64 ", logicalSesId: %{public}" PRIu64 ", pkgname:%{public}s", + isSrcSide, tokenId, logicalSessionId, pkgName.c_str()); + std::shared_ptr authMgr = nullptr; + // Create a new auth_mgr, create authMgr + if (isSrcSide) { + // src end + authMgr = std::make_shared(softbusConnector_, hiChainConnector_, + listener_, hiChainAuthConnector_); + } else { + // sink end + authMgr = std::make_shared(softbusConnector_, hiChainConnector_, + listener_, hiChainAuthConnector_); + } + // Register resource destruction notification function + authMgr->RegisterCleanNotifyCallback(&DeviceManagerServiceImpl::NotifyCleanEvent); + CHECK_NULL_RETURN(hiChainAuthConnector_, ERR_DM_POINT_NULL); + hiChainAuthConnector_->RegisterHiChainAuthCallbackById(logicalSessionId, authMgr); + LOGI("Initialize authMgr token: %{public}" PRId64 ".", tokenId); + ImportConfig(authMgr, tokenId, pkgName); + { + std::lock_guard lock(authMgrMapMtx_); + authMgrMap_[tokenId] = authMgr; + } + return DM_OK; +} + +int32_t DeviceManagerServiceImpl::InitOldProtocolAuthMgr(uint64_t tokenId, const std::string &pkgName) +{ + if (pkgName.empty()) { + LOGE("pkgName is empty"); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("tokenId: %{public}" PRIu64 ", pkgname:%{public}s", tokenId, pkgName.c_str()); + if (authMgr_ == nullptr) { + CreateGlobalClassicalAuthMgr(); + } + authMgr_->PrepareSoftbusSessionCallback(); + { + std::lock_guard lock(authMgrMapMtx_); + authMgrMap_[tokenId] = authMgr_; + } + ImportConfig(authMgr_, tokenId, pkgName); + { + // The value of logicalSessionId in the old protocol is always 0. + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); + logicalSessionId2TokenIdMap_[0] = tokenId; + } + return DM_OK; +} + int32_t DeviceManagerServiceImpl::InitAndRegisterAuthMgr(bool isSrcSide, uint64_t tokenId, std::shared_ptr session, uint64_t logicalSessionId, const std::string &pkgName) { @@ -292,47 +351,24 @@ int32_t DeviceManagerServiceImpl::InitAndRegisterAuthMgr(bool isSrcSide, uint64_ return ERR_DM_AUTH_BUSINESS_BUSY; } } - - std::lock_guard lock(authMgrMtx_); - if (authMgrMap_.find(tokenId) == authMgrMap_.end()) { - if (session->version_ == "" || CompareVersion(session->version_, DM_VERSION_5_0_OLD_MAX)) { - if (authMgrMap_.size() > MAX_NEW_PROC_SESSION_COUNT_TEMP) { - LOGE("Other bind session exist, can not start new one."); - return ERR_DM_AUTH_BUSINESS_BUSY; - } - // Create a new auth_mgr, create authMgrMap_[tokenId] - if (isSrcSide) { - // src end - authMgrMap_[tokenId] = std::make_shared(softbusConnector_, hiChainConnector_, - listener_, hiChainAuthConnector_); - } else { - // sink end - authMgrMap_[tokenId] = std::make_shared(softbusConnector_, hiChainConnector_, - listener_, hiChainAuthConnector_); - } - // Register resource destruction notification function - authMgrMap_[tokenId]->RegisterCleanNotifyCallback(&DeviceManagerServiceImpl::NotifyCleanEvent); - hiChainAuthConnector_->RegisterHiChainAuthCallbackById(logicalSessionId, authMgrMap_[tokenId]); - LOGI("Initialize authMgrMap_ token: %{public}" PRId64 ".", tokenId); - ImportConfig(authMgrMap_[tokenId], tokenId, pkgName); - return DM_OK; - } else { - LOGI("InitAndRegisterAuthMgr old authMgr."); - if (authMgr_ == nullptr) { - CreateGlobalClassicalAuthMgr(); - } - authMgr_->PrepareSoftbusSessionCallback(); - authMgrMap_[tokenId] = authMgr_; - ImportConfig(authMgr_, tokenId, pkgName); - // The value of logicalSessionId in the old protocol is always 0. - logicalSessionId2TokenIdMap_[0] = tokenId; - return DM_OK; + { + std::lock_guard lock(authMgrMapMtx_); + if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { + // authMgr_ has been created, indicating that a binding event already exists. + // Other requests are rejected, and an error code is returned. + LOGE("BindTarget failed, this device is being bound. Please try again later."); + return ERR_DM_AUTH_BUSINESS_BUSY; } + if (authMgrMap_.size() > MAX_NEW_PROC_SESSION_COUNT_TEMP) { + LOGE("Other bind session exist, can not start new one."); + return ERR_DM_AUTH_BUSINESS_BUSY; + } + } + if (session->version_ == "" || CompareVersion(session->version_, DM_VERSION_5_0_OLD_MAX)) { + return InitNewProtocolAuthMgr(isSrcSide, tokenId, logicalSessionId, pkgName); } - // authMgr_ has been created, indicating that a binding event already exists. - // Other requests are rejected, and an error code is returned. - LOGE("BindTarget failed, this device is being bound. Please try again later."); - return ERR_DM_AUTH_BUSINESS_BUSY; + LOGI("InitAndRegisterAuthMgr old authMgr."); + return InitOldProtocolAuthMgr(tokenId, pkgName); } void DeviceManagerServiceImpl::CleanSessionMap(int sessionId, std::shared_ptr session) @@ -356,26 +392,37 @@ void DeviceManagerServiceImpl::CleanSessionMap(int sessionId, std::shared_ptr tokenIdLock(logicalSessionId2TokenIdMapMtx_); + logicalSessionId2TokenIdMap_.erase(logicalSessionId); + } + int32_t sessionId = 0; + { + std::lock_guard sessionIdLock(logicalSessionId2SessionIdMapMtx_); + if (logicalSessionId2SessionIdMap_.find(logicalSessionId) == logicalSessionId2SessionIdMap_.end()) { + return; } + sessionId = logicalSessionId2SessionIdMap_[logicalSessionId]; logicalSessionId2SessionIdMap_.erase(logicalSessionId); } - logicalSessionId2TokenIdMap_.erase(logicalSessionId); + auto session = GetCurSession(sessionId); + if (session != nullptr) { + CleanSessionMap(sessionId, session); + } return; } void DeviceManagerServiceImpl::CleanAuthMgrByLogicalSessionId(uint64_t logicalSessionId) { uint64_t tokenId = 0; - if (logicalSessionId2TokenIdMap_.find(logicalSessionId) != logicalSessionId2TokenIdMap_.end()) { - tokenId = logicalSessionId2TokenIdMap_[logicalSessionId]; - } else { - LOGE("logicalSessionId(%{public}" PRIu64 ") can not find the tokenId.", logicalSessionId); - return; + { + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); + if (logicalSessionId2TokenIdMap_.find(logicalSessionId) != logicalSessionId2TokenIdMap_.end()) { + tokenId = logicalSessionId2TokenIdMap_[logicalSessionId]; + } else { + LOGE("logicalSessionId(%{public}" PRIu64 ") can not find the tokenId.", logicalSessionId); + return; + } } CleanSessionMapByLogicalSessionId(logicalSessionId); @@ -384,9 +431,12 @@ void DeviceManagerServiceImpl::CleanAuthMgrByLogicalSessionId(uint64_t logicalSe authMgr_->ClearSoftbusSessionCallback(); } hiChainAuthConnector_->UnRegisterHiChainAuthCallbackById(logicalSessionId); - if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { - authMgrMap_[tokenId] = nullptr; - authMgrMap_.erase(tokenId); + { + std::lock_guard lock(authMgrMapMtx_); + if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { + authMgrMap_[tokenId] = nullptr; + authMgrMap_.erase(tokenId); + } } return; } @@ -394,9 +444,12 @@ void DeviceManagerServiceImpl::CleanAuthMgrByLogicalSessionId(uint64_t logicalSe std::shared_ptr DeviceManagerServiceImpl::GetAuthMgr() { uint64_t tokenId = IPCSkeleton::GetCallingTokenID(); - if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { - LOGI("authMgrMap_ token: %{public}" PRId64 ".", tokenId); - return authMgrMap_[tokenId]; + { + std::lock_guard lock(authMgrMapMtx_); + if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { + LOGI("authMgrMap_ token: %{public}" PRId64 ".", tokenId); + return authMgrMap_[tokenId]; + } } LOGE("authMgrMap_ not found, token: %{public}" PRId64 ".", tokenId); return nullptr; @@ -405,9 +458,12 @@ std::shared_ptr DeviceManagerServiceImpl::GetAuthMgr() // Needed in the callback function std::shared_ptr DeviceManagerServiceImpl::GetAuthMgrByTokenId(uint64_t tokenId) { - if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { - LOGI("authMgrMap_ token: %{public}" PRId64 ".", tokenId); - return authMgrMap_[tokenId]; + { + std::lock_guard lock(authMgrMapMtx_); + if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { + LOGI("authMgrMap_ token: %{public}" PRId64 ".", tokenId); + return authMgrMap_[tokenId]; + } } LOGE("authMgrMap_ not found, token: %{public}" PRId64 ".", tokenId); return nullptr; @@ -416,12 +472,18 @@ std::shared_ptr DeviceManagerServiceImpl::GetAuthMgrByTokenId(u std::shared_ptr DeviceManagerServiceImpl::GetCurrentAuthMgr() { uint64_t tokenId = 0; - if (logicalSessionId2TokenIdMap_.find(0) != logicalSessionId2TokenIdMap_.end()) { - tokenId = logicalSessionId2TokenIdMap_[0]; + { + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); + if (logicalSessionId2TokenIdMap_.find(0) != logicalSessionId2TokenIdMap_.end()) { + tokenId = logicalSessionId2TokenIdMap_[0]; + } } - for (auto &pair : authMgrMap_) { - if (pair.first != tokenId) { - return pair.second; + { + std::lock_guard lock(authMgrMapMtx_); + for (auto &pair : authMgrMap_) { + if (pair.first != tokenId) { + return pair.second; + } } } return authMgr_; @@ -483,6 +545,40 @@ int32_t DeviceManagerServiceImpl::Initialize(const std::shared_ptr lock(authMgrMapMtx_); + for (auto& pair : authMgrMap_) { + pair.second = nullptr; + } + authMgrMap_.clear(); + } + for (auto& pair : sessionsMap_) { + pair.second = nullptr; + } + sessionsMap_.clear(); + { + std::lock_guard configsLock(configsMapMutex_); + for (auto& pair : configsMap_) { + pair.second = nullptr; + } + configsMap_.clear(); + } + deviceId2SessionIdMap_.clear(); + deviceIdMutexMap_.clear(); + sessionEnableMutexMap_.clear(); + sessionEnableCvMap_.clear(); + { + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); + logicalSessionId2TokenIdMap_.clear(); + } + { + std::lock_guard sessionIdLock(logicalSessionId2SessionIdMapMtx_); + logicalSessionId2SessionIdMap_.clear(); + } +} + void DeviceManagerServiceImpl::Release() { LOGI("Release"); @@ -503,24 +599,7 @@ void DeviceManagerServiceImpl::Release() hiChainAuthConnector_->UnRegisterHiChainAuthCallback(); } authMgr_ = nullptr; - for (auto& pair : authMgrMap_) { - pair.second = nullptr; - } - authMgrMap_.clear(); - for (auto& pair : sessionsMap_) { - pair.second = nullptr; - } - sessionsMap_.clear(); - for (auto& pair : configsMap_) { - pair.second = nullptr; - } - configsMap_.clear(); - deviceId2SessionIdMap_.clear(); - deviceIdMutexMap_.clear(); - sessionEnableMutexMap_.clear(); - sessionEnableCvMap_.clear(); - logicalSessionId2TokenIdMap_.clear(); - logicalSessionId2SessionIdMap_.clear(); + ReleaseMaps(); deviceStateMgr_ = nullptr; softbusConnector_ = nullptr; abilityMgr_ = nullptr; @@ -886,6 +965,7 @@ std::shared_ptr DeviceManagerServiceImpl::GetAuthMgrByMessage(i return nullptr; } curSession->logicalSessionSet_.insert(logicalSessionId); + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); if (logicalSessionId2TokenIdMap_.find(logicalSessionId) != logicalSessionId2TokenIdMap_.end()) { LOGE("GetAuthMgrByMessage, logicalSessionId exists in logicalSessionId2TokenIdMap_."); return nullptr; @@ -896,29 +976,44 @@ std::shared_ptr DeviceManagerServiceImpl::GetAuthMgrByMessage(i LOGE("GetAuthMgrByMessage, The logical session ID does not exist in the physical session."); return nullptr; } + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); tokenId = logicalSessionId2TokenIdMap_[logicalSessionId]; } return GetAuthMgrByTokenId(tokenId); } -int32_t DeviceManagerServiceImpl::TransferSrcOldAuthMgr(std::shared_ptr curSession) +int32_t DeviceManagerServiceImpl::GetLogicalIdAndTokenIdBySessionId(uint64_t &logicalSessionId, + uint64_t &tokenId, int32_t sessionId) { - // New Old Receive 90, destroy new authMgr, create old authMgr, source side - // The old protocol has only one session, reverse lookup logicalSessionId and tokenId - int sessionId = curSession->sessionId_; - uint64_t logicalSessionId = 0; - uint64_t tokenId = 0; + std::lock_guard sessionIdLock(logicalSessionId2SessionIdMapMtx_); for (auto& pair : logicalSessionId2SessionIdMap_) { if (pair.second == sessionId) { logicalSessionId = pair.first; + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); tokenId = logicalSessionId2TokenIdMap_[logicalSessionId]; } } if (logicalSessionId == 0 || tokenId == 0) { - LOGE("DeviceManagerServiceImpl::TransferSrcOldAuthMgr can not find logicalSessionId and tokenId."); + LOGE("can not find logicalSessionId and tokenId."); return ERR_DM_AUTH_FAILED; } + return DM_OK; +} + +int32_t DeviceManagerServiceImpl::TransferSrcOldAuthMgr(std::shared_ptr curSession) +{ + // New Old Receive 90, destroy new authMgr, create old authMgr, source side + // The old protocol has only one session, reverse lookup logicalSessionId and tokenId + CHECK_NULL_RETURN(curSession, ERR_DM_POINT_NULL); + int sessionId = curSession->sessionId_; + uint64_t logicalSessionId = 0; + uint64_t tokenId = 0; + int32_t ret = GetLogicalIdAndTokenIdBySessionId(logicalSessionId, tokenId, sessionId); + if (ret != DM_OK) { + LOGE("failed, logicalSessionId: %{public}" PRIu64 ", tokenId: %{public}" PRIu64 "", logicalSessionId, tokenId); + return ret; + } std::string pkgName; PeerTargetId peerTargetId; std::map bindParam; @@ -931,12 +1026,15 @@ int32_t DeviceManagerServiceImpl::TransferSrcOldAuthMgr(std::shared_ptr int32_t authType = -1; authMgr->ParseAuthType(bindParam, authType); ImportAuthCodeToConfig(authMgr, tokenId); - authMgrMap_.erase(tokenId); + { + std::lock_guard lock(authMgrMapMtx_); + authMgrMap_.erase(tokenId); + } if (InitAndRegisterAuthMgr(true, tokenId, curSession, logicalSessionId, "") != DM_OK) { return ERR_DM_AUTH_FAILED; } - int ret = TransferByAuthType(authType, curSession, authMgr, bindParam, logicalSessionId); + ret = TransferByAuthType(authType, curSession, authMgr, bindParam, logicalSessionId); if (ret != DM_OK) { LOGE("DeviceManagerServiceImpl::TransferByAuthType TransferByAuthType failed."); return ret; @@ -966,7 +1064,10 @@ int32_t DeviceManagerServiceImpl::TransferByAuthType(int32_t authType, if (authType == DmAuthType::AUTH_TYPE_IMPORT_AUTH_CODE) { authMgr_->EnableInsensibleSwitching(); curSession->logicalSessionSet_.insert(0); - logicalSessionId2SessionIdMap_[0] = sessionId; + { + std::lock_guard sessionIdLock(logicalSessionId2SessionIdMapMtx_); + logicalSessionId2SessionIdMap_[0] = sessionId; + } authMgr->OnSessionDisable(); } else { authMgr_->DisableInsensibleSwitching(); @@ -1368,6 +1469,7 @@ int32_t DeviceManagerServiceImpl::GetUdidHashByNetWorkId(const char *networkId, std::shared_ptr DeviceManagerServiceImpl::GetConfigByTokenId() { uint64_t tokenId = IPCSkeleton::GetCallingTokenID(); + std::lock_guard configsLock(configsMapMutex_); if (configsMap_.find(tokenId) == configsMap_.end()) { configsMap_[tokenId] = std::make_shared(); } @@ -1624,6 +1726,19 @@ int32_t DeviceManagerServiceImpl::ParseConnectAddr(const PeerTargetId &targetId, return DM_OK; } +void DeviceManagerServiceImpl::SaveTokenIdAndSessionId(uint64_t &tokenId, + int32_t &sessionId, uint64_t &logicalSessionId) +{ + { + std::lock_guard tokenIdLock(logicalSessionId2TokenIdMapMtx_); + logicalSessionId2TokenIdMap_[logicalSessionId] = tokenId; + } + { + std::lock_guard sessionIdLock(logicalSessionId2SessionIdMapMtx_); + logicalSessionId2SessionIdMap_[logicalSessionId] = sessionId; + } +} + void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::string &pkgName, const PeerTargetId &targetId, const std::map &bindParam) { @@ -1665,9 +1780,7 @@ void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::strin } curSession->logicalSessionSet_.insert(logicalSessionId); curSession->logicalSessionCnt_.fetch_add(1); - logicalSessionId2TokenIdMap_[logicalSessionId] = tokenId; - logicalSessionId2SessionIdMap_[logicalSessionId] = sessionId; - + SaveTokenIdAndSessionId(tokenId, sessionId, logicalSessionId); auto authMgr = GetAuthMgrByTokenId(tokenId); if (authMgr == nullptr) { CleanAuthMgrByLogicalSessionId(logicalSessionId); @@ -1694,14 +1807,15 @@ int32_t DeviceManagerServiceImpl::BindTarget(const std::string &pkgName, const P std::map bindParamTmp; SetBindCallerInfoToBindParam(bindParam, bindParamTmp, bindCallerInfo); uint64_t tokenId = IPCSkeleton::GetCallingTokenID(); - if (authMgrMap_.find(tokenId) == authMgrMap_.end()) { - std::thread newThread(&DeviceManagerServiceImpl::BindTargetImpl, this, tokenId, pkgName, - targetId, bindParamTmp); - newThread.detach(); - } else { - LOGE("BindTarget failed, this device is being bound. please try again later."); - return ERR_DM_AUTH_BUSINESS_BUSY; + { + std::lock_guard lock(authMgrMapMtx_); + if (authMgrMap_.find(tokenId) != authMgrMap_.end()) { + LOGE("BindTarget failed, this device is being bound. please try again later."); + return ERR_DM_AUTH_BUSINESS_BUSY; + } } + std::thread newThread(&DeviceManagerServiceImpl::BindTargetImpl, this, tokenId, pkgName, targetId, bindParamTmp); + newThread.detach(); return DM_OK; } @@ -1843,6 +1957,7 @@ void DeviceManagerServiceImpl::ScreenCommonEventCallback(std::string commonEvent { if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED) { LOGI("on screen locked."); + std::lock_guard lock(authMgrMapMtx_); for (auto& pair : authMgrMap_) { if (pair.second != nullptr) { LOGI("tokenId: %{public}" PRId64 ".", pair.first); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 0c88ab78f..e4e004064 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1171,6 +1171,7 @@ bool DeviceManagerService::IsDMServiceImplReady() if (isImplsoLoaded_ && (dmServiceImpl_ != nullptr)) { return true; } + LOGI("libdevicemanagerserviceimpl start load."); void *so_handle = dlopen(LIB_IMPL_NAME, RTLD_NOW | RTLD_NODELETE | RTLD_NOLOAD); if (so_handle == nullptr) { so_handle = dlopen(LIB_IMPL_NAME, RTLD_NOW | RTLD_NODELETE); diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index c189eb8b0..074d1cd33 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -16,6 +16,7 @@ group("fuzztest") { deps = [ "authconfirm_fuzzer:fuzztest", + "authmanager_fuzzer:fuzztest", "authmessageprocessor_fuzzer:fuzztest", "cryptomgr_fuzzer:fuzztest", "devicediscovery_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn b/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn new file mode 100644 index 000000000..c2add4c2d --- /dev/null +++ b/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn @@ -0,0 +1,77 @@ +# 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("AuthManagerFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/authmanager_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/ipc/standard", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "auth_manager_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${json_path}:devicemanagerjson", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + ] + + external_deps = [ + "bounds_checking_function:libsec_shared", + "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", + "kv_store:distributeddata_inner", + "samgr:samgr_proxy", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"AuthManagerFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":AuthManagerFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp new file mode 100644 index 000000000..f5026935e --- /dev/null +++ b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp @@ -0,0 +1,410 @@ +/* + * 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 "auth_manager_fuzzer.h" + +#include "auth_manager.h" +#include "deviceprofile_connector.h" +#include "device_manager_service_listener.h" +#include "dm_anonymous.h" +#include "dm_auth_context.h" +#include "dm_auth_manager_base.h" +#include "auth_manager.h" +#include "dm_auth_state_machine.h" +#include "dm_constants.h" +#include "dm_crypto.h" +#include "dm_log.h" + + +namespace OHOS { +namespace DistributedHardware { +namespace { + std::shared_ptr dmAuthMessageProcessor_ = std::make_shared(); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr hiChainAuthConnector = std::make_shared(); + std::shared_ptr hiChainConnector = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, + hiChainConnector, listener, hiChainAuthConnector); + std::shared_ptr context_ = authManager->GetAuthContext(); + std::shared_ptr authSinkManager = std::make_shared(softbusConnector, hiChainConnector, + listener, hiChainAuthConnector); +} + +void ConvertSrcVersionFuzzTest(FuzzedDataProvider &fdp) +{ + std::string version = fdp.ConsumeRandomLengthString(); + std::string edition = fdp.ConsumeRandomLengthString(); + CleanNotifyCallback cleanNotifyCallback; + authManager->RegisterCleanNotifyCallback(cleanNotifyCallback); + authManager->SetAuthContext(context_); + authManager->GetAuthContext(); + authManager->GeneratePincode(); + authManager->ConvertSrcVersion(version, edition); +} + +void RegisterUiStateCallbackFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + authManager->RegisterUiStateCallback(pkgName); +} + +void UnRegisterUiStateCallbackFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + authManager->UnRegisterUiStateCallback(pkgName); +} + +void UnAuthenticateDeviceFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string udid = fdp.ConsumeRandomLengthString(); + int32_t bindLevel = fdp.ConsumeIntegral(); + authManager->UnAuthenticateDevice(pkgName, udid, bindLevel); +} + +void ImportAuthCodeFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string authCode = fdp.ConsumeRandomLengthString(); + authManager->ImportAuthCode(pkgName, authCode); +} + +void UnBindDeviceFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + int32_t bindLevel = fdp.ConsumeIntegral(); + std::string udid = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + authManager->UnBindDevice(pkgName, udid, bindLevel, extra); +} + +void StopAuthenticateDeviceFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + authManager->StopAuthenticateDevice(pkgName); + authManager->OnScreenLocked(); +} + +void HandleDeviceNotTrustFuzzTest(FuzzedDataProvider &fdp) +{ + std::string udid = fdp.ConsumeRandomLengthString(); + authManager->HandleDeviceNotTrust(udid); +} + +void RegisterAuthenticationTypeFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t authenticationType = fdp.ConsumeIntegral(); + authManager->RegisterAuthenticationType(authenticationType); + authManager->GetReason(); +} + +void AuthDeviceSessionKeyFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + uint8_t sessionKey = fdp.ConsumeIntegral(); + uint32_t sessionKeyLen = fdp.ConsumeIntegral(); + authManager->AuthDeviceSessionKey(requestId, &sessionKey, sessionKeyLen); +} + +void AuthDeviceRequestFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + int operationCode = fdp.ConsumeIntegral(); + const char* reqParams = fdp.ConsumeRandomLengthString().c_str(); + authManager->AuthDeviceRequest(requestId, operationCode, reqParams); +} + +void SetAuthTypeFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t authType = fdp.ConsumeIntegral(); + authManager->SetAuthType(authType); +} + +void IsAuthTypeSupportedFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t authType = fdp.ConsumeIntegral(); + authManager->IsAuthTypeSupported(authType); +} + +void CheckAuthParamVaildFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + int32_t authType = fdp.ConsumeIntegral(); + authManager->CheckAuthParamVaild(pkgName, authType, deviceId, extra); +} + +void ParseHmlInfoInJsonObjectFuzzTest(FuzzedDataProvider &fdp) +{ + JsonObject jsonObject; + jsonObject[PARAM_KEY_CONN_SESSIONTYPE] = fdp.ConsumeRandomLengthString(); + jsonObject[PARAM_KEY_HML_ENABLE_160M] = fdp.ConsumeBool(); + jsonObject[PARAM_KEY_HML_ACTIONID] = fdp.ConsumeRandomLengthString(); + authManager->ParseHmlInfoInJsonObject(jsonObject); +} + +void ParseJsonObjectFuzzTest(FuzzedDataProvider &fdp) +{ + JsonObject jsonObject; + jsonObject[APP_OPERATION_KEY] = fdp.ConsumeRandomLengthString(); + jsonObject[CUSTOM_DESCRIPTION_KEY] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_APP_THUMBNAIL2] = fdp.ConsumeRandomLengthString(); + jsonObject[PARAM_CLOSE_SESSION_DELAY_SECONDS] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_PEER_PKG_NAME] = fdp.ConsumeRandomLengthString(); + authManager->ParseJsonObject(jsonObject); +} + +void GetTokenIdByBundleNameFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t userId = fdp.ConsumeIntegral(); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int64_t tokenId = fdp.ConsumeIntegral(); + authManager->GetTokenIdByBundleName(userId, bundleName, tokenId); +} + +void GetBindLevelFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t bindLevel = fdp.ConsumeIntegral(); + authManager->GetBindLevel(bindLevel); +} + +void GetAuthParamFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t authType = fdp.ConsumeIntegral(); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + authManager->GetAuthParam(pkgName, authType, deviceId, extra); +} + +void InitAuthStateFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t authType = fdp.ConsumeIntegral(); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + authManager->InitAuthState(pkgName, authType, deviceId, extra); +} + +void AuthenticateDeviceFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t authType = fdp.ConsumeIntegral(); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); +} + +void AuthDeviceErrorFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + int32_t errorCode = fdp.ConsumeIntegral(); + authManager->AuthDeviceError(requestId, errorCode); +} + +void AuthDeviceFinishFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + authManager->AuthDeviceFinish(requestId); +} + +void GetPinCodeFuzzTest(FuzzedDataProvider &fdp) +{ + std::string code = fdp.ConsumeRandomLengthString(); + authManager->GetPinCode(code); +} + +void GetAuthCodeAndPkgNameFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string authCode = fdp.ConsumeRandomLengthString(); + authManager->GetAuthCodeAndPkgName(pkgName, authCode); +} + +void IsAuthCodeReadyFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + authManager->IsAuthCodeReady(pkgName); +} + +void ParseUltrasonicSideFuzzTest(FuzzedDataProvider &fdp) +{ + JsonObject jsonObject; + jsonObject[TAG_ULTRASONIC_SIDE] = fdp.ConsumeRandomLengthString(); + authManager->ParseUltrasonicSide(jsonObject); +} + +void BindTargetFuzzTest(FuzzedDataProvider &fdp) +{ + std::string pkgName = fdp.ConsumeRandomLengthString(); + PeerTargetId targetId; + std::map bindParam; + int sessionId = fdp.ConsumeIntegral(); + uint64_t logicalSessionId = fdp.ConsumeIntegral(); + authManager->BindTarget(pkgName, targetId, bindParam, sessionId, logicalSessionId); +} + +void OnSessionClosedFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t sessionId = fdp.ConsumeIntegral(); + authSinkManager->OnSessionClosed(sessionId); +} + +void OnDataReceivedFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t sessionId = fdp.ConsumeIntegral(); + std::string message = fdp.ConsumeRandomLengthString(); + authSinkManager->OnDataReceived(sessionId, message); + authSinkManager->GetIsCryptoSupport(); +} + +void GetRemoteDeviceIdFuzzTest(FuzzedDataProvider &fdp) +{ + std::string deviceId = fdp.ConsumeRandomLengthString(); + authManager->GetRemoteDeviceId(deviceId); +} + +void OnUserOperationFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t action = fdp.ConsumeIntegral(); + std::string params = fdp.ConsumeRandomLengthString(); + authSinkManager->OnUserOperation(action, params); +} + +void OnSessionOpenedFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t sessionId = fdp.ConsumeIntegral(); + int32_t sessionSide = fdp.ConsumeIntegral(); + int32_t result = fdp.ConsumeIntegral(); + authManager->OnSessionOpened(sessionId, sessionSide, result); +} + +void OnSrcSessionClosedFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t sessionId = fdp.ConsumeIntegral(); + authManager->OnSessionClosed(sessionId); +} + +void OnSrcDataReceivedFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t sessionId = fdp.ConsumeIntegral(); + std::string message = fdp.ConsumeRandomLengthString(); + authManager->OnDataReceived(sessionId, message); + authManager->OnSessionDisable(); + authManager->GetIsCryptoSupport(); +} + +void OnSrcUserOperationFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t action = fdp.ConsumeIntegral(); + std::string params = fdp.ConsumeRandomLengthString(); + authManager->OnUserOperation(action, params); +} + +void AuthDeviceTransmitFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + uint8_t data = fdp.ConsumeIntegral(); + uint32_t dataLen = fdp.ConsumeIntegral(); + authManager->AuthDeviceTransmit(requestId, &data, dataLen); +} + +void AuthSinkDeviceTransmitFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + uint8_t data = fdp.ConsumeIntegral(); + uint32_t dataLen = fdp.ConsumeIntegral(); + authSinkManager->AuthDeviceTransmit(requestId, &data, dataLen); +} + +void AuthSinkDeviceSessionKeyFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + uint8_t sessionKey = fdp.ConsumeIntegral(); + uint32_t sessionKeyLen = fdp.ConsumeIntegral(); + authSinkManager->AuthDeviceSessionKey(requestId, &sessionKey, sessionKeyLen); +} + +void AuthSinkDeviceRequestFuzzTest(FuzzedDataProvider &fdp) +{ + int64_t requestId = fdp.ConsumeIntegral(); + int operationCode = fdp.ConsumeIntegral(); + const char* reqParams = fdp.ConsumeRandomLengthString().c_str(); + authSinkManager->AuthDeviceRequest(requestId, operationCode, reqParams); + authManager->DeleteTimer(); + authManager->GetBindCallerInfo(); +} + +void AuthManagerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + ConvertSrcVersionFuzzTest(fdp); + RegisterUiStateCallbackFuzzTest(fdp); + UnRegisterUiStateCallbackFuzzTest(fdp); + UnAuthenticateDeviceFuzzTest(fdp); + ImportAuthCodeFuzzTest(fdp); + UnBindDeviceFuzzTest(fdp); + StopAuthenticateDeviceFuzzTest(fdp); + HandleDeviceNotTrustFuzzTest(fdp); + RegisterAuthenticationTypeFuzzTest(fdp); + AuthDeviceSessionKeyFuzzTest(fdp); + AuthDeviceRequestFuzzTest(fdp); + SetAuthTypeFuzzTest(fdp); + IsAuthTypeSupportedFuzzTest(fdp); + ParseHmlInfoInJsonObjectFuzzTest(fdp); + CheckAuthParamVaildFuzzTest(fdp); + ParseJsonObjectFuzzTest(fdp); + GetBindLevelFuzzTest(fdp); + GetAuthParamFuzzTest(fdp); + InitAuthStateFuzzTest(fdp); + AuthDeviceErrorFuzzTest(fdp); + AuthDeviceFinishFuzzTest(fdp); + GetAuthCodeAndPkgNameFuzzTest(fdp); + GetPinCodeFuzzTest(fdp); + GetTokenIdByBundleNameFuzzTest(fdp); + AuthenticateDeviceFuzzTest(fdp); + BindTargetFuzzTest(fdp); + ParseUltrasonicSideFuzzTest(fdp); + IsAuthCodeReadyFuzzTest(fdp); + AuthSinkDeviceSessionKeyFuzzTest(fdp); + OnSessionClosedFuzzTest(fdp); + OnDataReceivedFuzzTest(fdp); + GetRemoteDeviceIdFuzzTest(fdp); + OnUserOperationFuzzTest(fdp); + OnSessionOpenedFuzzTest(fdp); + OnSrcSessionClosedFuzzTest(fdp); + OnSrcUserOperationFuzzTest(fdp); + AuthDeviceTransmitFuzzTest(fdp); + AuthSinkDeviceTransmitFuzzTest(fdp); + AuthSinkDeviceSessionKeyFuzzTest(fdp); + AuthSinkDeviceRequestFuzzTest(fdp); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::AuthManagerFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.h b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.h new file mode 100644 index 000000000..175ded707 --- /dev/null +++ b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_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_MANAGER_FUZZER_H +#define AUTH_MANAGER_FUZZER_H + +#define FUZZ_PROJECT_NAME "authmanager_fuzzer" + +#endif // AUTH_MANAGER_FUZZER_H diff --git a/test/servicesfuzztest/authmanager_fuzzer/corpus/init b/test/servicesfuzztest/authmanager_fuzzer/corpus/init new file mode 100644 index 000000000..490dc4356 --- /dev/null +++ b/test/servicesfuzztest/authmanager_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/authmanager_fuzzer/project.xml b/test/servicesfuzztest/authmanager_fuzzer/project.xml new file mode 100644 index 000000000..0aef325cd --- /dev/null +++ b/test/servicesfuzztest/authmanager_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn b/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn index 03a5e37e8..1cf89be7f 100644 --- a/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("AuthMessageProcessorFuzzTest") { "ipc:ipc_single", "kv_store:distributeddata_inner", "samgr:samgr_proxy", + "c_utils:utils", ] defines = [ diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index fae4ecbfe..c2c5a453e 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -2073,6 +2073,64 @@ HWTEST_F(DeviceManagerServiceImplTest, ChangeUltrasonicTypeToPin_002, testing::e int32_t ret = deviceManagerServiceImpl_->ChangeUltrasonicTypeToPin(bindParam); EXPECT_EQ(ret, DM_OK); } + +HWTEST_F(DeviceManagerServiceImplTest, ReleaseMaps_001, testing::ext::TestSize.Level1) +{ + int32_t sessionId = 100012; + uint64_t logicalSessionId = 456789102; + deviceManagerServiceImpl_->logicalSessionId2SessionIdMap_[logicalSessionId] = sessionId; + deviceManagerServiceImpl_->ReleaseMaps(); + EXPECT_EQ(deviceManagerServiceImpl_->logicalSessionId2SessionIdMap_.size(), 0); +} + +HWTEST_F(DeviceManagerServiceImplTest, GetLogicalIdAndTokenIdBySessionId_001, testing::ext::TestSize.Level1) +{ + int32_t sessionId = 10001; + uint64_t tokenId = 1000023; + uint64_t logicalSessionId = 45678910; + int32_t ret = deviceManagerServiceImpl_->GetLogicalIdAndTokenIdBySessionId(logicalSessionId, tokenId, sessionId); + EXPECT_EQ(ret, DM_OK); + + logicalSessionId = 0; + ret = deviceManagerServiceImpl_->GetLogicalIdAndTokenIdBySessionId(logicalSessionId, tokenId, sessionId); + EXPECT_EQ(ret, ERR_DM_AUTH_FAILED); + + logicalSessionId = 45678910; + tokenId = 0; + ret = deviceManagerServiceImpl_->GetLogicalIdAndTokenIdBySessionId(logicalSessionId, tokenId, sessionId); + EXPECT_EQ(ret, ERR_DM_AUTH_FAILED); + + deviceManagerServiceImpl_->logicalSessionId2SessionIdMap_[logicalSessionId] = sessionId; + deviceManagerServiceImpl_->logicalSessionId2TokenIdMap_[logicalSessionId] = tokenId; + ret = deviceManagerServiceImpl_->GetLogicalIdAndTokenIdBySessionId(logicalSessionId, tokenId, sessionId); + EXPECT_EQ(ret, ERR_DM_AUTH_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplTest, InitNewProtocolAuthMgr_001, testing::ext::TestSize.Level1) +{ + bool isSrcSide = true; + uint64_t tokenId = 1000023; + uint64_t logicalSessionId = 456789; + const std::string pkgName = "InitNewProtocolAuthMgr"; + int32_t ret = deviceManagerServiceImpl_->InitNewProtocolAuthMgr(isSrcSide, tokenId, logicalSessionId, pkgName); + EXPECT_EQ(ret, DM_OK); + + isSrcSide = false; + ret = deviceManagerServiceImpl_->InitNewProtocolAuthMgr(isSrcSide, tokenId, logicalSessionId, pkgName); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplTest, InitOldProtocolAuthMgr_001, testing::ext::TestSize.Level1) +{ + uint64_t tokenId = 100002311; + const std::string pkgName = "InitOldProtocolAuthMgr"; + int32_t ret = deviceManagerServiceImpl_->InitOldProtocolAuthMgr(tokenId, pkgName); + EXPECT_EQ(ret, DM_OK); + + deviceManagerServiceImpl_->authMgr_ = nullptr; + ret = deviceManagerServiceImpl_->InitOldProtocolAuthMgr(tokenId, pkgName); + EXPECT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS -- Gitee From 06c2931900df4b4b2686f8ec6749a107307eb675 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 5 Jun 2025 17:08:19 +0800 Subject: [PATCH 4/4] dp idl depence. Signed-off-by: BrainL Change-Id: I8c1be9bc6469ac4b81330c0cead108a17e8e862e --- test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn | 1 + test/servicesfuzztest/authmanager_fuzzer/BUILD.gn | 1 + 2 files changed, 2 insertions(+) diff --git a/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn b/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn index 810c280fa..19da34e7a 100644 --- a/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("AuthConfirmFuzzTest") { "ipc:ipc_single", "kv_store:distributeddata_inner", "samgr:samgr_proxy", + "c_utils:utils", ] defines = [ diff --git a/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn b/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn index c2add4c2d..ed32166a3 100644 --- a/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("AuthManagerFuzzTest") { "ipc:ipc_single", "kv_store:distributeddata_inner", "samgr:samgr_proxy", + "c_utils:utils", ] defines = [ -- Gitee