From 77167cda4efa25bad1a5a722a63f11b04dbafbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Fri, 20 Dec 2024 16:40:12 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E5=A2=9E=E5=8A=A0bindLevel=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../include/authentication/dm_auth_manager.h | 3 +- .../src/authentication/dm_auth_manager.cpp | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 70c6dd645..dbc352147 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -463,6 +463,7 @@ private: int32_t CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); int32_t CheckAuthParamVaildExtra(const std::string &extra); + bool CheckPkgNameInWhiteList(const std::string &pkgName); void ProcessSourceMsg(); void ProcessSinkMsg(); std::string GetAccountGroupIdHash(); @@ -530,7 +531,7 @@ private: void GetPeerUdidHash(int32_t sessionId, std::string &peerUdidHash); void DeleteOffLineTimer(int32_t sessionId); bool IsAllowDeviceBind(); - int32_t GetBindLevel(int32_t bindLevel); + int32_t GetBindLevel(int32_t bindLevel, const std::string &pkgName); std::string GetBundleName(nlohmann::json &jsonObject); int32_t GetBinderInfo(); void SetProcessInfo(); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 18610d61c..b53977189 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -78,6 +78,11 @@ const int32_t AUTH_DEVICE_TIMEOUT = 10; const int32_t SESSION_HEARTBEAT_TIMEOUT = 50; const int32_t ALREADY_BIND = 1; const int32_t STRTOLL_BASE_10 = 10; +constexpr int32_t PKGNAME_WHITE_LIST_NUM = 1; +constexpr int32_t PKG_NAME_SIZE_MAX = 256; +constexpr const static char g_pkgNameWhiteList[PKGNAME_WHITE_LIST_NUM][PKG_NAME_SIZE_MAX] = { + +}; // clone task timeout map const std::map TASK_TIME_OUT_MAP = { @@ -190,6 +195,25 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) return DM_OK; } +bool DmAuthManager::CheckPkgNameInWhiteList(const std::string &pkgName) +{ + LOGI("DmAuthManager::CheckPkgNameInWhiteList start"); + if (pkgName.empty()) { + LOGE("pkgName is empty"); + return false; + } + uint16_t index = 0; + for (; index < PKGNAME_WHITE_LIST_NUM; ++index) { + std::string whitePkgName(g_pkgNameWhiteList[index]); + if (pkgName == whitePkgName) { + LOGI("pkgName = %{public}s in whiteList.", pkgName.c_str()); + return true; + } + } + LOGI("CheckPkgNameInWhiteList: %{public}s invalid.", pkgName.c_str()); + return false; +} + void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { @@ -2582,7 +2606,7 @@ bool DmAuthManager::IsAllowDeviceBind() return false; } -int32_t DmAuthManager::GetBindLevel(int32_t bindLevel) +int32_t DmAuthManager::GetBindLevel(int32_t bindLevel, const std::string &pkgName) { if (IsAllowDeviceBind()) { if (static_cast(bindLevel) == INVALIED_TYPE || static_cast(bindLevel) > APP || @@ -2591,6 +2615,9 @@ int32_t DmAuthManager::GetBindLevel(int32_t bindLevel) } return bindLevel; } + if (CheckPkgNameInWhiteList(pkgName)) { + return DEVICE; + } if (static_cast(bindLevel) == INVALIED_TYPE || (static_cast(bindLevel) != APP && static_cast(bindLevel) != SERVICE)) { return APP; -- Gitee From 98ba86abcde034451d930770104fcea984262719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Fri, 20 Dec 2024 19:27:07 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=99=BD=E5=90=8D?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- services/implementation/src/authentication/dm_auth_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index b53977189..2a4ba63aa 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -81,7 +81,7 @@ const int32_t STRTOLL_BASE_10 = 10; constexpr int32_t PKGNAME_WHITE_LIST_NUM = 1; constexpr int32_t PKG_NAME_SIZE_MAX = 256; constexpr const static char g_pkgNameWhiteList[PKGNAME_WHITE_LIST_NUM][PKG_NAME_SIZE_MAX] = { - + "ohos.samples.etsdevicemanager", }; // clone task timeout map -- Gitee From fedc95bb6fe9b21a06bba6165dafa5d8f76886c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Sat, 21 Dec 2024 18:08:30 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E6=A0=B9=E6=8D=AEprocessName=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- common/include/dm_constants.h | 1 + .../src/authentication/dm_auth_manager.cpp | 30 +++++++++++-------- .../service/src/device_manager_service.cpp | 6 ++++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 50b550689..c0d7eb3c0 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -245,6 +245,7 @@ constexpr const char* DM_BIND_RESULT_NETWORK_ID = "DM_BIND_RESULT_NETWORK_ID"; constexpr const char* PARAM_KEY_POLICY_STRATEGY_FOR_BLE = "DM_POLICY_STRATEGY_FOR_BLE"; constexpr const char* PARAM_KEY_POLICY_TIME_OUT = "DM_POLICY_TIMEOUT"; constexpr const char* DEVICE_SCREEN_STATUS = "DEVICE_SCREEN_STATUS"; +constexpr const char* PROCESS_NAME = "PROCESS_NAME"; // screen state constexpr int32_t DM_SCREEN_UNKNOWN = -1; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 2a4ba63aa..f89e91f27 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -78,9 +78,9 @@ const int32_t AUTH_DEVICE_TIMEOUT = 10; const int32_t SESSION_HEARTBEAT_TIMEOUT = 50; const int32_t ALREADY_BIND = 1; const int32_t STRTOLL_BASE_10 = 10; -constexpr int32_t PKGNAME_WHITE_LIST_NUM = 1; -constexpr int32_t PKG_NAME_SIZE_MAX = 256; -constexpr const static char g_pkgNameWhiteList[PKGNAME_WHITE_LIST_NUM][PKG_NAME_SIZE_MAX] = { +constexpr int32_t PROCESS_NAME_WHITE_LIST_NUM = 1; +constexpr int32_t PROCESS_NAME_SIZE_MAX = 256; +constexpr const static char g_pkgNameWhiteList[PROCESS_NAME_WHITE_LIST_NUM][PROCESS_NAME_SIZE_MAX] = { "ohos.samples.etsdevicemanager", }; @@ -195,22 +195,22 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) return DM_OK; } -bool DmAuthManager::CheckPkgNameInWhiteList(const std::string &pkgName) +bool DmAuthManager::CheckProcessNameInWhiteList(const std::string &processName) { - LOGI("DmAuthManager::CheckPkgNameInWhiteList start"); - if (pkgName.empty()) { - LOGE("pkgName is empty"); + LOGI("DmAuthManager::CheckProcessNameInWhiteList start"); + if (processName.empty()) { + LOGE("processName is empty"); return false; } uint16_t index = 0; - for (; index < PKGNAME_WHITE_LIST_NUM; ++index) { + for (; index < PROCESS_NAME_WHITE_LIST_NUM; ++index) { std::string whitePkgName(g_pkgNameWhiteList[index]); if (pkgName == whitePkgName) { - LOGI("pkgName = %{public}s in whiteList.", pkgName.c_str()); + LOGI("processName = %{public}s in whiteList.", processName.c_str()); return true; } } - LOGI("CheckPkgNameInWhiteList: %{public}s invalid.", pkgName.c_str()); + LOGI("CheckProcessNameInWhiteList: %{public}s invalid.", processName.c_str()); return false; } @@ -255,7 +255,11 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { authRequestContext_->bindLevel = jsonObject[TAG_BIND_LEVEL].get(); } - authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel); + string processName = ""; + if (IsString(jsonObject, PROCESS_NAME)) { + processName = jsonObject[PROCESS_NAME].get(); + } + authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel, processName); } authRequestContext_->bundleName = GetBundleName(jsonObject); authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); @@ -2606,7 +2610,7 @@ bool DmAuthManager::IsAllowDeviceBind() return false; } -int32_t DmAuthManager::GetBindLevel(int32_t bindLevel, const std::string &pkgName) +int32_t DmAuthManager::GetBindLevel(int32_t bindLevel, const std::string &processName) { if (IsAllowDeviceBind()) { if (static_cast(bindLevel) == INVALIED_TYPE || static_cast(bindLevel) > APP || @@ -2615,7 +2619,7 @@ int32_t DmAuthManager::GetBindLevel(int32_t bindLevel, const std::string &pkgNam } return bindLevel; } - if (CheckPkgNameInWhiteList(pkgName)) { + if (CheckProcessNameInWhiteList(processName)) { return DEVICE; } if (static_cast(bindLevel) == INVALIED_TYPE || (static_cast(bindLevel) != APP && diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 0868ce035..ad957483c 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -507,10 +507,16 @@ int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int LOGE("AuthenticateDevice failed, cannot get target info from cached discovered device map."); return ERR_DM_BIND_INPUT_PARA_INVALID; } + std::string processName = ""; + if (PermissionManager::GetInstance().GetCallerProcessName(processName) != DM_OK) { + LOGE("Get caller process name failed, pkgname: %{public}s.", pkgName.c_str()); + return ERR_DM_FAILED; + } std::map bindParam; bindParam.insert(std::pair(PARAM_KEY_AUTH_TYPE, std::to_string(authType))); bindParam.insert(std::pair(PARAM_KEY_BIND_EXTRA_DATA, extra)); bindParam.insert(std::pair(PARAM_KEY_CONN_ADDR_TYPE, std::to_string(addrType))); + bindParam.insert(std::pair(PROCESS_NAME, processName)); return dmServiceImpl_->BindTarget(pkgName, targetId, bindParam); } -- Gitee From 7990161652ad797e1727bd6c54c199a566c409dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Sat, 21 Dec 2024 19:07:09 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../include/authentication/dm_auth_manager.h | 2 +- .../implementation/src/authentication/dm_auth_manager.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index dbc352147..d49a17aca 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -463,7 +463,7 @@ private: int32_t CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); int32_t CheckAuthParamVaildExtra(const std::string &extra); - bool CheckPkgNameInWhiteList(const std::string &pkgName); + bool CheckProcessNameInWhiteList(const std::string &processName); void ProcessSourceMsg(); void ProcessSinkMsg(); std::string GetAccountGroupIdHash(); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index f89e91f27..dc4d5225d 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -80,7 +80,7 @@ const int32_t ALREADY_BIND = 1; const int32_t STRTOLL_BASE_10 = 10; constexpr int32_t PROCESS_NAME_WHITE_LIST_NUM = 1; constexpr int32_t PROCESS_NAME_SIZE_MAX = 256; -constexpr const static char g_pkgNameWhiteList[PROCESS_NAME_WHITE_LIST_NUM][PROCESS_NAME_SIZE_MAX] = { +constexpr const static char PROCESS_NAME_WHITE_LIST[PROCESS_NAME_WHITE_LIST_NUM][PROCESS_NAME_SIZE_MAX] = { "ohos.samples.etsdevicemanager", }; @@ -204,8 +204,8 @@ bool DmAuthManager::CheckProcessNameInWhiteList(const std::string &processName) } uint16_t index = 0; for (; index < PROCESS_NAME_WHITE_LIST_NUM; ++index) { - std::string whitePkgName(g_pkgNameWhiteList[index]); - if (pkgName == whitePkgName) { + std::string whitePkgName(PROCESS_NAME_WHITE_LIST[index]); + if (processName == whitePkgName) { LOGI("processName = %{public}s in whiteList.", processName.c_str()); return true; } @@ -255,7 +255,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { authRequestContext_->bindLevel = jsonObject[TAG_BIND_LEVEL].get(); } - string processName = ""; + std::string processName = ""; if (IsString(jsonObject, PROCESS_NAME)) { processName = jsonObject[PROCESS_NAME].get(); } -- Gitee From 308ef42050b87267522efc42e5c21050bfd1c8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Mon, 23 Dec 2024 17:01:34 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E6=A0=B9=E6=8D=AEprocessName=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- services/service/src/device_manager_service.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index ad957483c..81ae44c69 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2384,6 +2384,12 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, s LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } + std::string processName = ""; + if (PermissionManager::GetInstance().GetCallerProcessName(processName) != DM_OK) { + LOGE("Get caller process name failed, pkgname: %{public}s.", pkgName.c_str()); + return ERR_DM_FAILED; + } + LOGI("processName = %{public}s.", processName.c_str()); std::vector onlineDeviceList; CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); int32_t ret = softbusListener_->GetTrustedDeviceList(onlineDeviceList); -- Gitee From 172e55ecfc37d8989ebce0930eea03ebbd628601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Mon, 23 Dec 2024 21:58:32 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E6=9B=B4=E6=8D=A2processName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../implementation/src/authentication/dm_auth_manager.cpp | 2 +- services/service/src/device_manager_service.cpp | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 35f67cde3..b02336537 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -81,7 +81,7 @@ const int32_t STRTOLL_BASE_10 = 10; constexpr int32_t PROCESS_NAME_WHITE_LIST_NUM = 1; constexpr int32_t PROCESS_NAME_SIZE_MAX = 256; constexpr const static char PROCESS_NAME_WHITE_LIST[PROCESS_NAME_WHITE_LIST_NUM][PROCESS_NAME_SIZE_MAX] = { - "ohos.samples.etsdevicemanager", + "com.example.myapplication", }; // clone task timeout map diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 81ae44c69..dced0247e 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2384,11 +2384,6 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, s LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - std::string processName = ""; - if (PermissionManager::GetInstance().GetCallerProcessName(processName) != DM_OK) { - LOGE("Get caller process name failed, pkgname: %{public}s.", pkgName.c_str()); - return ERR_DM_FAILED; - } LOGI("processName = %{public}s.", processName.c_str()); std::vector onlineDeviceList; CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); -- Gitee From c9a524328ed9b718b0d6ed88cc7050e39464b378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Mon, 23 Dec 2024 22:39:24 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A3=80=E8=A7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- services/service/src/device_manager_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index dced0247e..ad957483c 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2384,7 +2384,6 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, s LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("processName = %{public}s.", processName.c_str()); std::vector onlineDeviceList; CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); int32_t ret = softbusListener_->GetTrustedDeviceList(onlineDeviceList); -- Gitee From 3d79ee10930a0c59c252b2ce29844d616216693d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 24 Dec 2024 09:50:13 +0800 Subject: [PATCH 08/15] =?UTF-8?q?UT=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../src/authentication/dm_auth_manager.cpp | 9 +++++++-- test/commonunittest/UTTest_dm_auth_manager_first.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index b02336537..b4e0a79f4 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -238,6 +238,13 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->isOnline = false; authRequestContext_->authed = !authRequestContext_->bindType.empty(); authRequestContext_->bindLevel = INVALIED_TYPE; + authRequestContext_->bundleName = GetBundleName(jsonObject); + authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); + parseBindParam(extra); +} + +void parseBindParam(const std::string &extra) +{ nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); if (!jsonObject.is_discarded()) { if (IsString(jsonObject, TARGET_PKG_NAME_KEY)) { @@ -266,8 +273,6 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, } authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel, processName); } - authRequestContext_->bundleName = GetBundleName(jsonObject); - authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); } int32_t DmAuthManager::GetCloseSessionDelaySeconds(std::string &delaySecondsStr) diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 2306830dc..d4cd54d16 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -1444,11 +1444,11 @@ HWTEST_F(DmAuthManagerTest, GetBindLevel_001, testing::ext::TestSize.Level0) authManager_->ProcIncompatible(sessionId); EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(true)); - int32_t ret = authManager_->GetBindLevel(bindLevel); + int32_t ret = authManager_->GetBindLevel(bindLevel, ""); ASSERT_EQ(ret, DEVICE); EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false)); - ret = authManager_->GetBindLevel(bindLevel); + ret = authManager_->GetBindLevel(bindLevel, ""); ASSERT_EQ(ret, APP); authManager_->authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE; @@ -1470,11 +1470,11 @@ HWTEST_F(DmAuthManagerTest, GetBindLevel_001, testing::ext::TestSize.Level0) bindLevel = SERVICE; EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false)); - ret = authManager_->GetBindLevel(bindLevel); + ret = authManager_->GetBindLevel(bindLevel, ""); ASSERT_EQ(ret, SERVICE); EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(true)); - ret = authManager_->GetBindLevel(bindLevel); + ret = authManager_->GetBindLevel(bindLevel, ""); ASSERT_EQ(ret, SERVICE); } -- Gitee From faf6a012e897e9f8c4d506d9768d45074443c8d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 24 Dec 2024 11:29:04 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../implementation/include/authentication/dm_auth_manager.h | 1 + services/implementation/src/authentication/dm_auth_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 99ccdfe10..9880f629a 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -510,6 +510,7 @@ private: int32_t ImportCredential(std::string &deviceId, std::string &publicKey); void GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); + void parseBindParam(const std::string &extra); int32_t DeleteAcl(const std::string &pkgName, const std::string &localUdid, const std::string &remoteUdid, int32_t bindLevel); void ProcessAuthRequestExt(const int32_t &sessionId); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index b4e0a79f4..7eec4fa3c 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -243,7 +243,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, parseBindParam(extra); } -void parseBindParam(const std::string &extra) +void DmAuthManager::parseBindParam(const std::string &extra) { nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); if (!jsonObject.is_discarded()) { -- Gitee From c9fad3034bd5154fc1eb3e17a1636b9a977a1f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 24 Dec 2024 14:47:38 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- services/implementation/src/authentication/dm_auth_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 7eec4fa3c..e12531315 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -238,7 +238,6 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->isOnline = false; authRequestContext_->authed = !authRequestContext_->bindType.empty(); authRequestContext_->bindLevel = INVALIED_TYPE; - authRequestContext_->bundleName = GetBundleName(jsonObject); authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); parseBindParam(extra); } @@ -273,6 +272,7 @@ void DmAuthManager::parseBindParam(const std::string &extra) } authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel, processName); } + authRequestContext_->bundleName = GetBundleName(jsonObject); } int32_t DmAuthManager::GetCloseSessionDelaySeconds(std::string &delaySecondsStr) -- Gitee From 3433c0dd73d91b99558f8461131dc1b7525b7e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 24 Dec 2024 21:11:57 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../include/authentication/dm_auth_manager.h | 2 +- .../src/authentication/dm_auth_manager.cpp | 13 ++++++------- .../src/device_manager_service_impl.cpp | 1 + services/service/src/device_manager_service.cpp | 6 ------ 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 9880f629a..3c16bb602 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -533,7 +533,7 @@ private: void GetPeerUdidHash(int32_t sessionId, std::string &peerUdidHash); void DeleteOffLineTimer(int32_t sessionId); bool IsAllowDeviceBind(); - int32_t GetBindLevel(int32_t bindLevel, const std::string &pkgName); + int32_t GetBindLevel(int32_t bindLevel); std::string GetBundleName(nlohmann::json &jsonObject); int32_t GetBinderInfo(); void SetProcessInfo(); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index e12531315..e6b88b55f 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -244,6 +244,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, void DmAuthManager::parseBindParam(const std::string &extra) { + LOGI("DmAuthManager::parseBindParam start extra %{public}s.", extra.c_str()); nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); if (!jsonObject.is_discarded()) { if (IsString(jsonObject, TARGET_PKG_NAME_KEY)) { @@ -266,11 +267,7 @@ void DmAuthManager::parseBindParam(const std::string &extra) std::string delaySecondsStr = jsonObject[PARAM_CLOSE_SESSION_DELAY_SECONDS].get(); authRequestContext_->closeSessionDelaySeconds = GetCloseSessionDelaySeconds(delaySecondsStr); } - std::string processName = ""; - if (IsString(jsonObject, PROCESS_NAME)) { - processName = jsonObject[PROCESS_NAME].get(); - } - authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel, processName); + authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel); } authRequestContext_->bundleName = GetBundleName(jsonObject); } @@ -2645,7 +2642,7 @@ bool DmAuthManager::IsAllowDeviceBind() return false; } -int32_t DmAuthManager::GetBindLevel(int32_t bindLevel, const std::string &processName) +int32_t DmAuthManager::GetBindLevel(int32_t bindLevel) { if (IsAllowDeviceBind()) { if (static_cast(bindLevel) == INVALIED_TYPE || static_cast(bindLevel) > APP || @@ -2654,7 +2651,9 @@ int32_t DmAuthManager::GetBindLevel(int32_t bindLevel, const std::string &proces } return bindLevel; } - if (CheckProcessNameInWhiteList(processName)) { + string processName = ""; + int32_t ret = PermissionManager::GetInstance().GetCallerProcessName(processName); + if (ret == DM_OK && CheckProcessNameInWhiteList(processName)) { return DEVICE; } if (static_cast(bindLevel) == INVALIED_TYPE || (static_cast(bindLevel) != APP && diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 46fc34742..f8d069e0d 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -29,6 +29,7 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "dm_common_event_manager.h" #include "parameter.h" +#include "permission_manager.h" #include "common_event_support.h" using namespace OHOS::EventFwk; #endif diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index ad957483c..0868ce035 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -507,16 +507,10 @@ int32_t DeviceManagerService::AuthenticateDevice(const std::string &pkgName, int LOGE("AuthenticateDevice failed, cannot get target info from cached discovered device map."); return ERR_DM_BIND_INPUT_PARA_INVALID; } - std::string processName = ""; - if (PermissionManager::GetInstance().GetCallerProcessName(processName) != DM_OK) { - LOGE("Get caller process name failed, pkgname: %{public}s.", pkgName.c_str()); - return ERR_DM_FAILED; - } std::map bindParam; bindParam.insert(std::pair(PARAM_KEY_AUTH_TYPE, std::to_string(authType))); bindParam.insert(std::pair(PARAM_KEY_BIND_EXTRA_DATA, extra)); bindParam.insert(std::pair(PARAM_KEY_CONN_ADDR_TYPE, std::to_string(addrType))); - bindParam.insert(std::pair(PROCESS_NAME, processName)); return dmServiceImpl_->BindTarget(pkgName, targetId, bindParam); } -- Gitee From d7e4687c40de5d2262c7f6170c489b9d17c47fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 24 Dec 2024 21:17:06 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E4=BF=AE=E6=94=B9UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../implementation/src/authentication/dm_auth_manager.cpp | 1 + .../implementation/src/device_manager_service_impl.cpp | 1 - test/commonunittest/UTTest_dm_auth_manager_first.cpp | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index e6b88b55f..b66c32a53 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -42,6 +42,7 @@ #include "multiple_user_connector.h" #include "nlohmann/json.hpp" #include "parameter.h" +#include "permission_manager.h" #include "show_confirm.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "multiple_user_connector.h" diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index f8d069e0d..46fc34742 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -29,7 +29,6 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "dm_common_event_manager.h" #include "parameter.h" -#include "permission_manager.h" #include "common_event_support.h" using namespace OHOS::EventFwk; #endif diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index d4cd54d16..2306830dc 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -1444,11 +1444,11 @@ HWTEST_F(DmAuthManagerTest, GetBindLevel_001, testing::ext::TestSize.Level0) authManager_->ProcIncompatible(sessionId); EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(true)); - int32_t ret = authManager_->GetBindLevel(bindLevel, ""); + int32_t ret = authManager_->GetBindLevel(bindLevel); ASSERT_EQ(ret, DEVICE); EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false)); - ret = authManager_->GetBindLevel(bindLevel, ""); + ret = authManager_->GetBindLevel(bindLevel); ASSERT_EQ(ret, APP); authManager_->authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE; @@ -1470,11 +1470,11 @@ HWTEST_F(DmAuthManagerTest, GetBindLevel_001, testing::ext::TestSize.Level0) bindLevel = SERVICE; EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false)); - ret = authManager_->GetBindLevel(bindLevel, ""); + ret = authManager_->GetBindLevel(bindLevel); ASSERT_EQ(ret, SERVICE); EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(true)); - ret = authManager_->GetBindLevel(bindLevel, ""); + ret = authManager_->GetBindLevel(bindLevel); ASSERT_EQ(ret, SERVICE); } -- Gitee From c5a5884ee8303c3b4817b5d20d98229a3a4597a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Wed, 25 Dec 2024 10:01:27 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E9=87=8D=E5=86=99=E8=8E=B7=E5=8F=96proce?= =?UTF-8?q?ssName=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../src/authentication/dm_auth_manager.cpp | 2 +- utils/BUILD.gn | 1 + utils/include/appInfo/standard/app_manager.h | 1 + utils/src/appInfo/standard/app_manager.cpp | 39 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index b66c32a53..608eccf8a 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2653,7 +2653,7 @@ int32_t DmAuthManager::GetBindLevel(int32_t bindLevel) return bindLevel; } string processName = ""; - int32_t ret = PermissionManager::GetInstance().GetCallerProcessName(processName); + int32_t ret = AppManager::GetInstance().GetCallerProcessName(processName); if (ret == DM_OK && CheckProcessNameInWhiteList(processName)) { return DEVICE; } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index b3b56d221..1cce2fed3 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -119,6 +119,7 @@ if (defined(ohos_lite)) { external_deps = [ "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "cJSON:cjson", diff --git a/utils/include/appInfo/standard/app_manager.h b/utils/include/appInfo/standard/app_manager.h index 8f19166a6..0a56a4d6c 100644 --- a/utils/include/appInfo/standard/app_manager.h +++ b/utils/include/appInfo/standard/app_manager.h @@ -39,6 +39,7 @@ public: int32_t GetCallerName(bool isSystemSA, std::string &callerName); int32_t GetNativeTokenIdByName(std::string &processName, int64_t &tokenId); int32_t GetHapTokenIdByName(int32_t userId, std::string &bundleName, int32_t instIndex, int64_t &tokenId); + int32_t GetCallerProcessName(std::string &processName); private: bool GetBundleManagerProxy(sptr &bundleManager); std::mutex appIdMapLock_; diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index 11d857f3a..766189281 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -16,11 +16,13 @@ #include "app_manager.h" #include "accesstoken_kit.h" +#include "access_token.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "iservice_registry.h" #include "os_account_manager.h" #include "system_ability_definition.h" +#include "tokenid_kit.h" #include "dm_anonymous.h" #include "dm_constants.h" @@ -204,5 +206,42 @@ int32_t AppManager::GetHapTokenIdByName(int32_t userId, std::string &bundleName, tokenId = static_cast(hapTokenId); return DM_OK; } + +int32_t AppManager::GetCallerProcessName(std::string &processName) +{ + AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + if (tokenCaller == 0) { + LOGE("GetCallerProcessName GetCallingTokenID error."); + return ERR_DM_FAILED; + } + LOGI("GetCallerProcessName::tokenCaller ID == %{public}s", GetAnonyInt32(tokenCaller).c_str()); + ATokenTypeEnum tokenTypeFlag = AccessTokenKit::GetTokenTypeFlag(tokenCaller); + if (tokenTypeFlag == ATokenTypeEnum::TOKEN_HAP) { + HapTokenInfo tokenInfo; + if (AccessTokenKit::GetHapTokenInfo(tokenCaller, tokenInfo) != EOK) { + LOGE("GetHapTokenInfo failed."); + return ERR_DM_FAILED; + } + processName = std::move(tokenInfo.bundleName); + uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); + if (!OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { + LOGE("GetCallerProcessName %{public}s not system hap.", processName.c_str()); + return ERR_DM_FAILED; + } + } else if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE) { + NativeTokenInfo tokenInfo; + if (AccessTokenKit::GetNativeTokenInfo(tokenCaller, tokenInfo) != EOK) { + LOGE("GetNativeTokenInfo failed."); + return ERR_DM_FAILED; + } + processName = std::move(tokenInfo.processName); + } else { + LOGE("GetCallerProcessName failed, unsupported process."); + return ERR_DM_FAILED; + } + + LOGI("Get process name: %{public}s success.", processName.c_str()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From ec50dd68b49ec886825d236bdd47943d4b3b58d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Wed, 25 Dec 2024 10:33:22 +0800 Subject: [PATCH 14/15] check code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- services/implementation/src/authentication/dm_auth_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 608eccf8a..95df856f3 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -42,7 +42,6 @@ #include "multiple_user_connector.h" #include "nlohmann/json.hpp" #include "parameter.h" -#include "permission_manager.h" #include "show_confirm.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "multiple_user_connector.h" @@ -2652,7 +2651,7 @@ int32_t DmAuthManager::GetBindLevel(int32_t bindLevel) } return bindLevel; } - string processName = ""; + std::string processName = ""; int32_t ret = AppManager::GetInstance().GetCallerProcessName(processName); if (ret == DM_OK && CheckProcessNameInWhiteList(processName)) { return DEVICE; -- Gitee From e6eb22263397aa115914e135653ab69426dbd329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Sat, 28 Dec 2024 09:30:20 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=86=B2=E7=AA=81=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../include/authentication/dm_auth_manager.h | 3 +-- .../src/authentication/dm_auth_manager.cpp | 22 +++++++------------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 8133add4a..85ae3b328 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -521,8 +521,7 @@ private: int32_t ImportCredential(std::string &deviceId, std::string &publicKey); void GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); - void parseBindParam(const std::string &extra); - void parseJsonObject(nlohmann::json jsonObject); + void ParseJsonObject(nlohmann::json jsonObject); int32_t DeleteAcl(const std::string &pkgName, const std::string &localUdid, const std::string &remoteUdid, int32_t bindLevel, const std::string &extra); void ProcessAuthRequestExt(const int32_t &sessionId); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 259198e4e..f4a0fb760 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -239,19 +239,12 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->isOnline = false; authRequestContext_->authed = !authRequestContext_->bindType.empty(); authRequestContext_->bindLevel = INVALIED_TYPE; - authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); - parseBindParam(extra); -} - -void DmAuthManager::parseBindParam(const std::string &extra) -{ - LOGI("DmAuthManager::parseBindParam start extra %{public}s.", extra.c_str()); nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); - parseJsonObject(jsonObject); + ParseJsonObject(jsonObject); authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); } -void DmAuthManager::parseJsonObject(nlohmann::json jsonObject) +void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) { if (!jsonObject.is_discarded()) { if (IsString(jsonObject, TARGET_PKG_NAME_KEY)) { @@ -280,7 +273,7 @@ void DmAuthManager::parseJsonObject(nlohmann::json jsonObject) if (authRequestContext_->peerBundleName == "") { authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; } - LOGI("parseJsonObject peerBundleName = %{public}s", authRequestContext_->peerBundleName.c_str()); + LOGI("ParseJsonObject peerBundleName = %{public}s", authRequestContext_->peerBundleName.c_str()); } else { authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; } @@ -2685,15 +2678,16 @@ int32_t DmAuthManager::GetBindLevel(int32_t bindLevel) } return bindLevel; } + if (static_cast(bindLevel) == INVALIED_TYPE || (static_cast(bindLevel) != APP && + static_cast(bindLevel) != SERVICE)) { + return APP; + } std::string processName = ""; int32_t ret = AppManager::GetInstance().GetCallerProcessName(processName); + LOGI("GetBindLevel processName = %{public}s", GetAnonyString(processName).c_str()); if (ret == DM_OK && CheckProcessNameInWhiteList(processName)) { return DEVICE; } - if (static_cast(bindLevel) == INVALIED_TYPE || (static_cast(bindLevel) != APP && - static_cast(bindLevel) != SERVICE)) { - return APP; - } return bindLevel; } -- Gitee