diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h index b93d073e433fb89e043b45a94d39dd81b9cbc3ab..cb4bb85bc260c8e3638704898fe98dfe3c505d4a 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h @@ -106,6 +106,7 @@ public: virtual void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) = 0; virtual void OnSessionClosed(const int32_t sessionId) = 0; virtual void OnBytesReceived(const int32_t sessionId, const std::string message) = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; using CreateDMServiceImplExtFuncPtr = IDMServiceImplExt *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h index 0b957825216fc0e4fea898150b6d52d067605322..3211cd8c21acaed7229ee2b3ba55294d850b3c64 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h @@ -111,6 +111,7 @@ public: virtual int32_t RestoreLocalDeviceName() = 0; virtual void ClearCacheWhenLogout(int32_t userId, const std::string &oldAccountId) = 0; virtual void HandleScreenLockEvent(bool isLock) = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; using CreateDMServiceExtResidentFuncPtr = IDMServiceImplExtResident *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h index cc7a97ace4b57eab431d620b932ad2e60bc430e5..336c5b631bd1e523058e86a725f72225b2997688 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h @@ -176,6 +176,7 @@ public: virtual void SetExistPkgName(const std::set &pkgNameSet) = 0; virtual std::string GetLocalDisplayDeviceName() = 0; + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 633b02b6b4baa9ea0b3dbf807bff94168efc9b96..2eb015b6cdba0c84f6eab4d9e98b36cf28105ac7 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -207,7 +207,7 @@ napi_value CreateBusinessError(napi_env env, int32_t errCode, bool isAsync = tru return error; } -void DeleteUvWork(uv_work_t *work) +void DeleteUvWork(uv_work_t *&work) { if (work == nullptr) { return; @@ -217,7 +217,7 @@ void DeleteUvWork(uv_work_t *work) LOGI("delete work!"); } -void DeleteDmNapiStateJsCallbackPtr(DmNapiStateJsCallback *pJsCallbackPtr) +void DeleteDmNapiStateJsCallbackPtr(DmNapiStateJsCallback *&pJsCallbackPtr) { if (pJsCallbackPtr == nullptr) { return; @@ -227,7 +227,7 @@ void DeleteDmNapiStateJsCallbackPtr(DmNapiStateJsCallback *pJsCallbackPtr) LOGI("delete DmNapiStateJsCallback callbackPtr!"); } -void DeleteAsyncCallbackInfo(DeviceInfoListAsyncCallbackInfo *pAsynCallbackInfo) +void DeleteAsyncCallbackInfo(DeviceInfoListAsyncCallbackInfo *&pAsynCallbackInfo) { if (pAsynCallbackInfo == nullptr) { return; diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 005d39c8af4c7f3d0108af28d51788c29f7b842b..2aa78c1ab4f9de5c2bbabfbc4e20d61cdf2e8158 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -86,7 +86,7 @@ std::mutex g_authCallbackMapMutex; std::mutex g_bindCallbackMapMutex; std::mutex g_dmUiCallbackMapMutex; -void DeleteUvWork(uv_work_t *work) +void DeleteUvWork(uv_work_t *&work) { if (work == nullptr) { return; @@ -96,7 +96,7 @@ void DeleteUvWork(uv_work_t *work) LOGI("delete work!"); } -void DeleteDmNapiStatusJsCallbackPtr(DmNapiStatusJsCallback *pJsCallbackPtr) +void DeleteDmNapiStatusJsCallbackPtr(DmNapiStatusJsCallback *&pJsCallbackPtr) { if (pJsCallbackPtr == nullptr) { return; @@ -106,7 +106,7 @@ void DeleteDmNapiStatusJsCallbackPtr(DmNapiStatusJsCallback *pJsCallbackPtr) LOGI("delete DmNapiStatusJsCallback callbackPtr!"); } -void DeleteAsyncCallbackInfo(DeviceBasicInfoListAsyncCallbackInfo *pAsynCallbackInfo) +void DeleteAsyncCallbackInfo(DeviceBasicInfoListAsyncCallbackInfo *&pAsynCallbackInfo) { if (pAsynCallbackInfo == nullptr) { return; diff --git a/services/implementation/include/dependency/softbus/softbus_session.h b/services/implementation/include/dependency/softbus/softbus_session.h index b3dfc2840c51d70cb62f9858279d96ad30b329d8..aaa548f361113f91bb2f8223f50c04a06673634d 100644 --- a/services/implementation/include/dependency/softbus/softbus_session.h +++ b/services/implementation/include/dependency/softbus/softbus_session.h @@ -59,13 +59,6 @@ public: */ int32_t OpenAuthSession(const std::string &deviceId); - /** - * @tc.name: SoftbusSession::OpenAuthSessionWithPara - * @tc.desc: Open HML AuthSession of the Softbus Session - * @tc.type: FUNC - */ - int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m); - /** * @tc.name: SoftbusSession::CloseAuthSession * @tc.desc: Close AuthSession of the Softbus Session diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ded639356c1946ed37091e086b3d162a42049f2e..60f51ac5c5fbb4c002aa89d88b9a37292d12b74d 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -868,10 +868,11 @@ int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) int32_t sessionId = 0; if (IsHmlSessionType()) { CHECK_NULL_RETURN(authRequestContext_, ERR_DM_FAILED); + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); LOGI("hmlActionId %{public}d, hmlReleaseTime %{public}d, hmlEnable160M %{public}d", authRequestContext_->hmlActionId, authRequestContext_->closeSessionDelaySeconds, authRequestContext_->hmlEnable160M); - sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, + sessionId = listener_->OpenAuthSessionWithPara(deviceId, authRequestContext_->hmlActionId, authRequestContext_->hmlEnable160M); } else { sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 056eb40442acffaca75ff0bc67d5ff22945fa10f..1563f8b861969b505a82fda35348ba07a38436ca 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -23,9 +23,6 @@ #include "json_object.h" #include "softbus_connector.h" #include "softbus_error_code.h" -#ifndef DEVICE_MANAGER_COMMON_FLAG -#include "session_ex.h" -#endif namespace OHOS { namespace DistributedHardware { @@ -75,29 +72,6 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) return sessionId; } -int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) -{ -#ifdef DEVICE_MANAGER_COMMON_FLAG - LOGE("[SOFTBUS] OpenAuthSessionWithPara no implement"); - return SOFTBUS_NOT_IMPLEMENT; -#else - DmTraceStart(std::string(DM_HITRACE_AUTH_TO_OPPEN_SESSION)); - LinkPara para; - para.type = PARA_ACTION; - para.action.actionId = static_cast(actionId); - para.enable160M = isEnable160m; - para.accountInfo = false; - int32_t sessionId = ::OpenAuthSessionWithPara(DM_SESSION_NAME, ¶); - if (sessionId < 0) { - LOGE("[SOFTBUS]open session error, sessionId: %{public}d.", sessionId); - return sessionId; - } - DmTraceEnd(); - LOGI("OpenAuthSessionWithPara success. sessionId: %{public}d.", sessionId); - return sessionId; -#endif -} - int32_t SoftbusSession::CloseAuthSession(int32_t sessionId) { LOGI("CloseAuthSession."); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 370064b1d36348465034a97f40f2f3a0748b74a6..36dccf96aa6b107eb30ad7218818dec8efd90ffd 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1529,8 +1529,8 @@ int DeviceManagerServiceImpl::OpenAuthSession(const std::string& deviceId, return ret; } LOGI("hmlActionId %{public}d, hmlEnable160M %{public}d", hmlActionId, hmlEnable160M); - return softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, - hmlActionId, hmlEnable160M); + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); + return listener_->OpenAuthSessionWithPara(deviceId, hmlActionId, hmlEnable160M); } else { return softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 4ac7e9d87f34f931df4aa5fd97f63cb3fc2e163c..70c27f371593f457c0f27d2d07570851d2e2437e 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -258,6 +258,7 @@ public: int32_t GetDeviceNetworkIdList(const std::string &pkgName, const NetworkIdQueryFilter &queryFilter, std::vector &networkIds); void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); + int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); void ProcessReceiveRspAppUninstall(const std::string &remoteUdid); void ProcessReceiveRspAppUnbind(const std::string &remoteUdid); diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index c6b9128b6d27389805d67f6422ed776f0485286b..216835016a96327f3e1961ba1e80cab2facb1e72 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -92,6 +92,7 @@ public: void SetExistPkgName(const std::set &pkgNameSet) override; std::string GetLocalDisplayDeviceName() override; + int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index f8eb37b841c3b75c633d9719d114151344a2e93b..4b66bb6555a70509c07742fb4c38caeaff94c812 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -4301,6 +4301,15 @@ void DeviceManagerService::ProcessSyncAccountLogout(const std::string &accountId dmServiceImpl_->HandleAccountLogoutEvent(userId, accountId, peerUdid); } +int32_t DeviceManagerService::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) +{ + if (!IsDMServiceAdapterResidentLoad()) { + LOGE("failed, adapter instance not init or init failed."); + return ERR_DM_UNSUPPORTED_METHOD; + } + return dmServiceImplExtResident_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); +} + int32_t DeviceManagerService::UnRegisterPinHolderCallback(const std::string &pkgName) { if (!PermissionManager::GetInstance().CheckPermission()) { diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 7bf14c146627fbc118e152d31e4f6f073774712f..bc47a6a81fc2c3d3908b7aa811a1d160a185c12a 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -45,6 +45,7 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "datetime_ex.h" #include "device_name_manager.h" +#include "device_manager_service.h" #include "kv_adapter_manager.h" #include "multiple_user_connector.h" #endif @@ -1041,5 +1042,15 @@ std::string DeviceManagerServiceListener::GetLocalDisplayDeviceName() return ""; #endif } + +int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string &deviceId, + int32_t actionId, bool isEnable160m) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + return DeviceManagerService::GetInstance().OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); +#else + return ERR_DM_UNSUPPORTED_METHOD; +#endif +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index c85383af7292f05e11704bbdbc510063dd097d6b..a971dd983848abdd1948a9a7f4b2eb46528979a0 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -16,6 +16,7 @@ #include "ipc_server_stub.h" #include +#include #include "ipc_cmd_register.h" #include "ipc_skeleton.h" @@ -44,6 +45,15 @@ namespace OHOS { namespace DistributedHardware { +namespace { +const std::unordered_set CLIENT_CODE { SERVER_DEVICE_STATE_NOTIFY, SERVER_DEVICE_FOUND, BIND_TARGET_RESULT, +SERVER_DEVICE_DISCOVERY, SERVER_PUBLISH_FINISH, SERVER_AUTH_RESULT, SERVER_DEVICE_FA_NOTIFY, SERVER_CREDENTIAL_RESULT, +SERVER_CREATE_PIN_HOLDER, SERVER_DESTROY_PIN_HOLDER, SERVER_CREATE_PIN_HOLDER_RESULT, SERVER_DESTROY_PIN_HOLDER_RESULT, +SERVER_ON_PIN_HOLDER_EVENT, UNBIND_TARGET_RESULT, REMOTE_DEVICE_TRUST_CHANGE, SERVER_DEVICE_SCREEN_STATE_NOTIFY, +SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, SINK_BIND_TARGET_RESULT, GET_DEVICE_PROFILE_INFO_LIST_RESULT, +GET_DEVICE_ICON_INFO_RESULT, SET_LOCAL_DEVICE_NAME_RESULT, SET_REMOTE_DEVICE_NAME_RESULT }; +} + DM_IMPLEMENT_SINGLE_INSTANCE(IpcServerStub); const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&IpcServerStub::GetInstance()); @@ -242,6 +252,9 @@ void IpcServerStub::OnStop() int32_t IpcServerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + if (CLIENT_CODE.find(code) != CLIENT_CODE.end()) { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } auto remoteDescriptor = data.ReadInterfaceToken(); if (GetDescriptor() != remoteDescriptor) { LOGI("ReadInterfaceToken fail!"); diff --git a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp index 0b1103234ecf676347497848a63548f495a5cae1..f0420974898654c0eea5def335499b521e1bf8af 100644 --- a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp @@ -32,6 +32,7 @@ void AuthAclFuzzTest(const uint8_t* data, size_t size) FuzzedDataProvider fdp(data, size); int32_t sessionId = fdp.ConsumeIntegral(); std::string result = fdp.ConsumeRandomLengthString(); + std::string peerDeviceId = fdp.ConsumeRandomLengthString(); std::shared_ptr authSink = std::make_shared(); std::shared_ptr authSrc = std::make_shared(); @@ -45,6 +46,9 @@ void AuthAclFuzzTest(const uint8_t* data, size_t size) context->accesser.isCommonFlag = false; authSink->VerifyCertificate(context); authSink->VerifyCertificate(nullptr); + context->IsProxyBind = true; + authSink->DerivativeSessionKey(context); + authSrc->GetPeerDeviceId(context, peerDeviceId); } } } diff --git a/test/commonfuzztest/authcredential_fuzzer/BUILD.gn b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn index 5928e20ddbc15ba59a79f7672472915d72c20ccf..95b5069e4f0c78ddbbcb2657e40271225c833b1d 100644 --- a/test/commonfuzztest/authcredential_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn @@ -46,6 +46,7 @@ ohos_fuzztest("AuthCredentialFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", + "${json_path}:devicemanagerjson", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", diff --git a/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp index df8f7027ae254006ef23ff03837de4bc80bcf4d2..9e258bf0bbd2253d90c1821d1300e387351623f1 100644 --- a/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp +++ b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp @@ -19,6 +19,7 @@ #include #include "device_manager_service_listener.h" +#include "dm_auth_message_processor.h" #include "dm_auth_state.h" #include "dm_freeze_process.h" @@ -26,6 +27,53 @@ namespace OHOS { namespace DistributedHardware { constexpr uint32_t SERVICE = 2; +void DerivativeSessionKeyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->IsProxyBind = true; + context->accesser.userId = fdp.ConsumeIntegral(); + context->accesser.transmitSessionKeyId = fdp.ConsumeIntegral(); + DmProxyAuthContext dmProxyAuthContext; + context->subjectProxyOnes.push_back(dmProxyAuthContext); + std::shared_ptr authPtr = std::make_shared(); + context->authMessageProcessor = std::make_shared(); + authPtr->DerivativeSessionKey(context); +} + +void DerivativeProxySessionKeyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->reUseCreId = fdp.ConsumeRandomLengthString(); + context->IsProxyBind = true; + context->accesser.isAuthed = true; + context->accesser.deviceIdHash = fdp.ConsumeRandomLengthString(); + context->accessee.deviceIdHash = fdp.ConsumeRandomLengthString(); + context->accesser.tokenIdHash = fdp.ConsumeRandomLengthString(); + context->accessee.tokenIdHash = fdp.ConsumeRandomLengthString(); + context->accesser.userId = fdp.ConsumeIntegral(); + context->accesser.transmitSkTimeStamp = fdp.ConsumeIntegral(); + context->accesser.transmitSessionKeyId = fdp.ConsumeIntegral(); + context->authMessageProcessor = std::make_shared(); + DmProxyAuthContext dmProxyAuthContext; + context->subjectProxyOnes.push_back(dmProxyAuthContext); + std::shared_ptr authSrcPtr = std::make_shared(); + authSrcPtr->DerivativeProxySessionKey(context); + std::shared_ptr authSinkPtr = + std::make_shared(); + authSinkPtr->DerivativeSessionKey(context); + std::shared_ptr authCrePtr = std::make_shared(); + JsonObject jsonObject; + authCrePtr->GenerateTokenIds(context, jsonObject); +} + void AuthCredentialFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -59,6 +107,9 @@ void AuthCredentialFuzzTest(const uint8_t* data, size_t size) authForth->GetStateType(); authFifth->GetStateType(); authSixth->GetStateType(); + + DerivativeSessionKeyFuzzTest(data, size); + DerivativeProxySessionKeyFuzzTest(data, size); } } } diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp index 4a4bd8d94f8640094625a7e2f41097e9eba58987..51c8eb0472a4a64e40eb2805b192a800480a0895 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -19,11 +19,52 @@ #include #include "device_manager_service_listener.h" +#include "dm_auth_state.h" #include "dm_negotiate_process.h" namespace OHOS { namespace DistributedHardware { +void RespQueryProxyAcceseeIdsFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->IsProxyBind = true; + context->accessee.userId = fdp.ConsumeIntegral(); + DmProxyAuthContext dmProxyAuthContext; + dmProxyAuthContext.proxyAccessee.bundleName = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.tokenId = fdp.ConsumeIntegral(); + context->subjectProxyOnes.push_back(dmProxyAuthContext); + std::shared_ptr authSinkPtr = std::make_shared(); + authSinkPtr->RespQueryProxyAcceseeIds(context); +} + +void GetSinkProxyCredTypeForP2PFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->IsProxyBind = true; + context->accessee.userId = fdp.ConsumeIntegral(); + DmProxyAuthContext dmProxyAuthContext; + dmProxyAuthContext.proxyAccessee.bundleName = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.tokenId = fdp.ConsumeIntegral(); + dmProxyAuthContext.proxyAccessee.credInfoJson = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.aclTypeList = fdp.ConsumeRandomLengthString(); + dmProxyAuthContext.proxyAccessee.credTypeList = fdp.ConsumeRandomLengthString(); + context->subjectProxyOnes.push_back(dmProxyAuthContext); + std::shared_ptr authSinkPtr = std::make_shared(); + std::vector deleteCredInfo; + authSinkPtr->GetSinkProxyCredTypeForP2P(context, deleteCredInfo); + DistributedDeviceProfile::AccessControlProfile profile; + authSinkPtr->GetSinkProxyAclInfoForP2P(context, profile); +} + void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -66,6 +107,9 @@ void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) p2pCredP2pAclImportAuthType.NegotiateHandle(context); P2pCredP2pAclInputAuthType p2pCredP2pAclInputAuthType; p2pCredP2pAclInputAuthType.NegotiateHandle(context); + + RespQueryProxyAcceseeIdsFuzzTest(data, size); + GetSinkProxyCredTypeForP2PFuzzTest(data, size); } } // namespace DistributedHardware } // namespace OHOS diff --git a/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp b/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp index a60faf0ed9999f644ab3acc1e801c26f6401c299..0571eab22bc6bee124427ffb26094c68ae37a4fb 100644 --- a/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp +++ b/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp @@ -165,6 +165,7 @@ void AuthConfirmFuzzTestNext(JsonObject &jsonObject, FuzzedDataProvider &fdp) authSrcConfirmState_->GetIdenticalCredentialInfo(context_, jsonObject); authSrcConfirmState_->GetShareCredentialInfo(context_, jsonObject); authSrcConfirmState_->GetP2PCredentialInfo(context_, jsonObject); + authSinkConfirmState_->CreateProxyData(context_, jsonObject); authSinkConfirmState_->NegotiateCredential(context_, jsonObject); authSinkConfirmState_->NegotiateAcl(context_, jsonObject); authSinkNegotiateStateMachine_->GetIdenticalCredentialInfo(context_, jsonObject); @@ -200,6 +201,9 @@ void AuthConfirmFuzzTestThird(FuzzedDataProvider &fdp) { std::string businessId = fdp.ConsumeRandomLengthString(); std::string businessValue = fdp.ConsumeRandomLengthString(); + std::string authorizeInfo = fdp.ConsumeRandomLengthString(); + std::vector deleteCredInfo; + DistributedDeviceProfile::AccessControlProfile acl; authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(businessId); authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(""); authSinkNegotiateStateMachine_->ParseAndCheckAntiDisturbanceMode(businessId, businessValue); @@ -216,6 +220,18 @@ void AuthConfirmFuzzTestThird(FuzzedDataProvider &fdp) authSrcPinNegotiateStartState_->ProcessCredAuth(context_); int32_t credType = fdp.ConsumeIntegral(); authSrcPinNegotiateStartState_->GetCredIdByCredType(context_, credType); + context_->IsProxyBind = true; + authSrcConfirmState_->NegotiateProxyCredential(context_); + authSrcConfirmState_->NegotiateProxyAcl(context_); + authSrcConfirmState_->ResetBindLevel(context_); + authSinkConfirmState_->GetBundleLabel(context_); + authSinkConfirmState_->NegotiateProxyAcl(context_); + authSinkConfirmState_->ProcessUserAuthorize(context_); + authSinkConfirmState_->ProcessServerAuthorize(context_); + authSinkConfirmState_->NegotiateProxyCredential(context_); + authSrcConfirmState_->GetSrcProxyCredTypeForP2P(context_, deleteCredInfo); + authSinkConfirmState_->ProcessUserOption(context_, authorizeInfo); + authSrcConfirmState_->GetSrcProxyAclInfoForP2P(context_, acl); } void AuthConfirmFuzzTest(const uint8_t* data, size_t size) diff --git a/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp index 59472857323ef04f2ad53636ba84f3e46a2e997a..7adab1c32716b30f912dff790d27904dc9dc8c4e 100644 --- a/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp +++ b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp @@ -376,6 +376,49 @@ void HandleBusinessEventsFuzzTest(FuzzedDataProvider &fdp) authManager->PrepareSoftbusSessionCallback(); } +void CheckProxyAuthParamVaildFuzzTest(FuzzedDataProvider &fdp) +{ + std::string extra = fdp.ConsumeRandomLengthString(); + authManager->CheckProxyAuthParamVaild(extra); + + JsonObject jsonObject; + jsonObject[PARAM_KEY_IS_PROXY_BIND] = "true"; + std::string bundleNameDemoA = "com.ohos.devicemanagerdemoA"; + std::string bundleNameDemoGame = "com.game.gamenearbydemo"; + JsonObject jsonA; + jsonA["pakgName"] = bundleNameDemoA; + jsonA["bundleName"] = bundleNameDemoA; + + JsonObject jsonGame; + jsonGame["pakgName"] = bundleNameDemoGame; + jsonGame["bundleName"] = bundleNameDemoGame; + + JsonObject subJsonArr(JsonCreateType::JSON_CREATE_TYPE_ARRAY); + subJsonArr.PushBack(jsonA); + subJsonArr.PushBack(jsonGame); + jsonObject[PARAM_KEY_SUBJECT_PROXYED_SUBJECTS] = subJsonArr.Dump(); + std::string extra1 = jsonObject.Dump(); + authManager->CheckProxyAuthParamVaild(extra1); + authManager->ParseProxyJsonObject(jsonObject); +} + +void ParseProxyJsonObjectFuzzTest(FuzzedDataProvider &fdp) +{ + JsonObject jsonObject; + jsonObject[PARAM_KEY_IS_PROXY_BIND] = fdp.ConsumeRandomLengthString(); + jsonObject[PARAM_KEY_IS_CALLING_PROXY_AS_SUBJECT] = fdp.ConsumeRandomLengthString(); + jsonObject[PARAM_KEY_SUBJECT_PROXYED_SUBJECTS] = fdp.ConsumeRandomLengthString(); + authManager->ParseProxyJsonObject(jsonObject); +} + +void GetBindLevelByBundleNameFuzzTest(FuzzedDataProvider &fdp) +{ + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t requestId = fdp.ConsumeIntegral(); + int32_t bindLevel = 0; + authManager->GetBindLevelByBundleName(bundleName, requestId, bindLevel); +} + void AuthManagerFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size == 0)) { @@ -422,6 +465,9 @@ void AuthManagerFuzzTest(const uint8_t* data, size_t size) AuthSinkDeviceSessionKeyFuzzTest(fdp); AuthSinkDeviceRequestFuzzTest(fdp); HandleBusinessEventsFuzzTest(fdp); + CheckProxyAuthParamVaildFuzzTest(fdp); + ParseProxyJsonObjectFuzzTest(fdp); + GetBindLevelByBundleNameFuzzTest(fdp); } } } diff --git a/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp b/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp index 84d93153e323e67274dcde0353417777b6614c80..9fa37aac635313757cacb8c0734bf4a0a613c6c8 100644 --- a/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp +++ b/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp @@ -70,6 +70,7 @@ void GenerateJsonObject(JsonObject &jsonObject, FuzzedDataProvider &fdp) jsonObject[TAG_DEVICE_VERSION] = fdp.ConsumeRandomLengthString(); jsonObject[TAG_DEVICE_NAME] = fdp.ConsumeRandomLengthString(); jsonObject[TAG_NETWORKID_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[PARAM_KEY_SUBJECT_PROXYED_SUBJECTS] = fdp.ConsumeRandomLengthString(); } void AuthContextFuzzTest(FuzzedDataProvider &fdp) @@ -131,6 +132,52 @@ void AuthMessageProcessorFuzzTestNext(JsonObject &jsonObject) FromJson(jsonObject, sync); } +void AuthMessageProcessorFuzzTestNextTwo(FuzzedDataProvider &fdp, JsonObject &jsonObject) +{ + int32_t userId = fdp.ConsumeIntegral(); + int32_t skId = fdp.ConsumeIntegral(); + std::string suffix = fdp.ConsumeRandomLengthString(); + int64_t tokenId = fdp.ConsumeIntegral(); + DistributedDeviceProfile::AccessControlProfile acl; + DistributedDeviceProfile::Accesser accesser; + DistributedDeviceProfile::Accessee accessee; + acl.SetExtraData(fdp.ConsumeRandomLengthString()); + accesser.SetAccesserExtraData(fdp.ConsumeRandomLengthString()); + accessee.SetAccesseeExtraData(fdp.ConsumeRandomLengthString()); + DmProxyAuthContext dmProxyAuthContext; + dmProxyAuthContext.customData = fdp.ConsumeRandomLengthString(); + context_->IsProxyBind = false; + context_->subjectProxyOnes.clear(); + dmAuthMessageProcessor_->ParseProxyCredExchangeToSync(context_, jsonObject); + context_->IsProxyBind = true; + context_->subjectProxyOnes.emplace_back(dmProxyAuthContext); + dmAuthMessageProcessor_->ParseProxyCredExchangeToSync(context_, jsonObject); + dmAuthMessageProcessor_->CreateProxyNegotiateMessage(context_, jsonObject); + dmAuthMessageProcessor_->CreateProxyRespNegotiateMessage(context_, jsonObject); + dmAuthMessageProcessor_->CreateProxyCredExchangeMessage(context_, jsonObject); + dmAuthMessageProcessor_->ParseProxyAccessToSync(context_, jsonObject); + dmAuthMessageProcessor_->ParseProxyNegotiateMessage(jsonObject, context_); + context_->accessee.dmVersion = DM_VERSION_5_1_0; + dmAuthMessageProcessor_->ParseMessageProxyRespAclNegotiate(jsonObject, context_); + context_->accessee.dmVersion = DM_VERSION_5_1_1; + dmAuthMessageProcessor_->ParseMessageProxyRespAclNegotiate(jsonObject, context_); + dmAuthMessageProcessor_->ParseMessageProxyReqUserConfirm(jsonObject, context_); + dmAuthMessageProcessor_->ParseMessageProxyRespUserConfirm(jsonObject, context_); + dmAuthMessageProcessor_->CreateMessageProxyReqUserConfirm(context_, jsonObject); + dmAuthMessageProcessor_->CreateProxyAccessMessage(context_, jsonObject); + dmAuthMessageProcessor_->cryptoMgr_ = std::make_shared(); + dmAuthMessageProcessor_->SaveDerivativeSessionKeyToDP(userId, suffix, skId); + dmAuthMessageProcessor_->GetSessionKey(userId, skId); + context_->accesser.extraInfo = ""; + dmAuthMessageProcessor_->SetProxyAccess(context_, dmProxyAuthContext, accesser, accessee); + dmAuthMessageProcessor_->PutProxyAccessControlList(context_, acl, accesser, accessee); + dmAuthMessageProcessor_->IsExistTheToken(jsonObject, tokenId); + dmAuthMessageProcessor_->SetAclProxyRelate(context_); + acl.accesser_.SetAccesserExtraData(""); + acl.accessee_.SetAccesseeExtraData(""); + dmAuthMessageProcessor_->SetAclProxyRelate(context_, acl); +} + void AuthMessageProcessorFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -178,6 +225,7 @@ void AuthMessageProcessorFuzzTest(const uint8_t* data, size_t size) dmAuthMessageProcessor_ -> SetTransmitAccessControlList(context_, accesser, accessee); dmAuthMessageProcessor_ -> SetLnnAccessControlList(context_, accesser, accessee); AuthMessageProcessorFuzzTestNext(jsonObject); + AuthMessageProcessorFuzzTestNextTwo(fdp, jsonObject); AuthContextFuzzTest(fdp); } } diff --git a/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp b/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp index 57c6d3e99c45218d9e475a2915c86e998c0eb081..9df6f8cdc50bfc013fe330e613e6b8d09cabff27 100644 --- a/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp +++ b/test/softbusfuzztest/softbussession_fuzzer/softbus_session_fuzzer.cpp @@ -75,8 +75,6 @@ void SoftBusSessionFuzzTest(const uint8_t* data, size_t size) softbusSession->SendHeartbeatData(sessionId, str); softbusSession->OnSessionClosed(result); softbusSession->UnRegisterSessionCallback(); - bool isEnable = fdp.ConsumeBool(); - softbusSession->OpenAuthSessionWithPara(str, sessionId, isEnable); } } } diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 1a9d05fae885db52804b24d17bf79c05c4220eab..bf2d124ea3e49f78a26cd4914f2dea39306772da 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -2598,6 +2598,15 @@ HWTEST_F(DeviceManagerServiceTest, GetEncryptedUuidByNetworkId_004, testing::ext DeviceManagerService::GetInstance().softbusListener_ = nullptr; EXPECT_EQ(ret, DM_OK); } + +HWTEST_F(DeviceManagerServiceTest, OpenAuthSessionWithPara_001, testing::ext::TestSize.Level1) +{ + const std::string deviceId = "OpenAuthSessionWithPara"; + int32_t actionId = 0; + bool isEnable160m = false; + int32_t ret = DeviceManagerService::GetInstance().OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); + EXPECT_NE(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index 84d1bc6ff9172f4668697f297214e4d284a7b684..ff761bb5399e6cb47271deaaf5f4f7e0d605c6eb 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -1093,6 +1093,16 @@ HWTEST_F(DeviceManagerServiceListenerTest, GetLocalDisplayDeviceName_001, testin displayDeviceName = listener_->GetLocalDisplayDeviceName(); EXPECT_FALSE(displayDeviceName.empty()); } + +HWTEST_F(DeviceManagerServiceListenerTest, OpenAuthSessionWithPara_001, testing::ext::TestSize.Level1) +{ + const std::string deviceId = "OpenAuthSessionWithPara"; + int32_t actionId = 0; + bool isEnable160m = false; + std::shared_ptr listener_ = std::make_shared(); + int32_t ret = listener_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); + EXPECT_NE(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 8e890141d4675d74ee208cb23fe7e42866cdc57d..1ecdd86fa305cbc697cf4487d2fe5676f5ce7a0b 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -2008,7 +2008,6 @@ HWTEST_F(DeviceManagerServiceTest, GetNotifyRemoteUnBindAppWay_002, testing::ext DeviceManagerService::GetInstance().softbusListener_ = nullptr; DeviceManagerService::GetInstance().GetNotifyRemoteUnBindAppWay(userId, tokenId, wifiDevices, isBleWay); EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); - } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 7d38ad3cee4fbfade509da3d3fe937a2277b3e39..4dfb660f8392378ea8602484e6d805220f6f3f99 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -265,6 +265,14 @@ public: { (void)pkgNameSet; } + + virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) + { + (void)deviceId; + (void)actionId; + (void)isEnable160m; + return 0; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_ipc_server_stub.cpp b/test/unittest/UTTest_ipc_server_stub.cpp index 67f91bd307d257e4801efb489f0035e909361e68..adc33ab53c1bb534285886645528d21208a98aec 100644 --- a/test/unittest/UTTest_ipc_server_stub.cpp +++ b/test/unittest/UTTest_ipc_server_stub.cpp @@ -159,8 +159,8 @@ HWTEST_F(IpcServerStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) int ret = 0; // 2. Call IpcServerStub OnRemoteRequest with param ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option); - // 3. check ret not ERR_DM_IPC_READ_FAILED - ASSERT_EQ(ret, ERR_DM_IPC_READ_FAILED); + // 3. check ret not DM_OK + ASSERT_NE(ret, DM_OK); } /** diff --git a/test/unittest/mock/softbus_session_mock.cpp b/test/unittest/mock/softbus_session_mock.cpp index c85d7045d13a77be7fea3621d4830ec6912454da..331e0e2cbf58b2a546b64340caadf437006e2967 100644 --- a/test/unittest/mock/softbus_session_mock.cpp +++ b/test/unittest/mock/softbus_session_mock.cpp @@ -30,11 +30,6 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message) return DmSoftbusSession::dmSoftbusSession->SendData(sessionId, message); } -int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) -{ - return DmSoftbusSession::dmSoftbusSession->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); -} - int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) { return DmSoftbusSession::dmSoftbusSession->OpenAuthSession(deviceId); diff --git a/test/unittest/mock/softbus_session_mock.h b/test/unittest/mock/softbus_session_mock.h index 9f386d18388b8c01da00ab872a8e5fad15852dd3..bdb1ad0f52d1db87ee431265bebe491599a1e0f6 100644 --- a/test/unittest/mock/softbus_session_mock.h +++ b/test/unittest/mock/softbus_session_mock.h @@ -28,7 +28,6 @@ public: public: virtual int32_t GetPeerDeviceId(int32_t sessionId, std::string &peerDevId) = 0; virtual int32_t SendData(int32_t sessionId, std::string &message) = 0; - virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; virtual int32_t OpenAuthSession(const std::string &deviceId) = 0; public: @@ -39,7 +38,6 @@ class SoftbusSessionMock : public DmSoftbusSession { public: MOCK_METHOD(int32_t, GetPeerDeviceId, (int32_t, std::string &)); MOCK_METHOD(int32_t, SendData, (int32_t, std::string &)); - MOCK_METHOD(int32_t, OpenAuthSessionWithPara, (const std::string &, int32_t, bool)); MOCK_METHOD(int32_t, OpenAuthSession, (const std::string &)); }; }