From 23e0433d4520d6dc0ccc43494bb5cf586497f16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Thu, 12 Jun 2025 19:25:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AF=81=E4=B9=A6=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=85=BC=E5=AE=B9=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- common/include/dm_constants.h | 2 +- common/src/dm_constants.cpp | 2 +- .../src/deviceprofile_connector.cpp | 30 +++-------- .../src/authentication_v2/auth_manager.cpp | 30 +---------- .../auth_stages/auth_negotiate.cpp | 50 +------------------ .../dm_auth_message_processor.cpp | 3 -- .../src/device_manager_service_impl.cpp | 2 +- 7 files changed, 14 insertions(+), 105 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 0a2645f57..98484ad06 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -182,7 +182,7 @@ extern const char* DM_VERSION_5_0_3; extern const char* DM_VERSION_5_0_4; extern const char* DM_VERSION_5_0_5; extern const char* DM_VERSION_5_1_0; -extern const char* DM_VERSION_5_1_1; +extern const char* DM_CURRENT_VERSION; extern const char* DM_ACL_AGING_VERSION; extern const char* DM_VERSION_5_0_OLD_MAX; // Estimated highest version number of the old version } // namespace DistributedHardware diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 9be2b9fb7..f70b2272f 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -170,7 +170,7 @@ const char* DM_VERSION_5_0_3 = "5.0.3"; const char* DM_VERSION_5_0_4 = "5.0.4"; const char* DM_VERSION_5_0_5 = "5.0.5"; const char* DM_VERSION_5_1_0 = "5.1.0"; -const char* DM_VERSION_5_1_1 = "5.1.1"; +const char* DM_CURRENT_VERSION = DM_VERSION_5_1_0; const char* DM_ACL_AGING_VERSION = DM_VERSION_5_1_0; const char* DM_VERSION_5_0_OLD_MAX = "5.0.99"; // Estimated highest version number of the old version } // namespace DistributedHardware diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index aebb45459..98d56a8a4 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2195,37 +2195,23 @@ DmOfflineParam DeviceProfileConnector::HandleServiceUnBindEvent(int32_t remoteUs return offlineParam; } + + DM_EXPORT std::vector DeviceProfileConnector::GetAllAccessControlProfile() { std::vector profiles; - int32_t ret; - uint32_t retryTimes = 0; - do { - ret = DistributedDeviceProfileClient::GetInstance().GetAllAccessControlProfile(profiles); - if (ret != DM_OK) { - ++retryTimes; - LOGE("DP failed."); - usleep(USLEEP_TIME_US_120000); - } - } while (ret != DM_OK && retryTimes < RETRY_TIMES); - + if (DistributedDeviceProfileClient::GetInstance().GetAllAccessControlProfile(profiles) != DM_OK) { + LOGE("DP failed."); + } return profiles; } DM_EXPORT std::vector DeviceProfileConnector::GetAllAclIncludeLnnAcl() { std::vector profiles; - int32_t ret; - uint32_t retryTimes = 0; - do { - ret = DistributedDeviceProfileClient::GetInstance().GetAllAclIncludeLnnAcl(profiles); - if (ret != DM_OK) { - ++retryTimes; - LOGE("DP failed."); - usleep(USLEEP_TIME_US_120000); - } - } while (ret != DM_OK && retryTimes < RETRY_TIMES); - + if (DistributedDeviceProfileClient::GetInstance().GetAllAclIncludeLnnAcl(profiles) != DM_OK) { + LOGE("DP failed."); + } return profiles; } diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 61c40a1b6..88668d9dd 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -24,8 +24,6 @@ #include "multiple_user_connector.h" #include "auth_manager.h" -#include "dm_auth_cert.h" -#include "dm_auth_attest_common.h" #include "dm_constants.h" #include "dm_crypto.h" #include "dm_random.h" @@ -133,8 +131,8 @@ AuthManager::AuthManager(std::shared_ptr softbusConnector, context_->authenticationMap[AUTH_TYPE_PIN_ULTRASONIC] = nullptr; context_->authenticationMap[AUTH_TYPE_NFC] = nullptr; context_->authenticationMap[AUTH_TYPE_CRE] = nullptr; - context_->accesser.dmVersion = DM_VERSION_5_1_1; - context_->accessee.dmVersion = DM_VERSION_5_1_1; + context_->accesser.dmVersion = DM_CURRENT_VERSION; + context_->accessee.dmVersion = DM_CURRENT_VERSION; context_->timer = std::make_shared(); context_->authMessageProcessor = std::make_shared(); } @@ -622,29 +620,6 @@ int32_t AuthManager::AuthenticateDevice(const std::string &pkgName, int32_t auth return DM_OK; } -std::string GenerateCertificate(std::shared_ptr context_) -{ -#ifdef DEVICE_MANAGER_COMMON_FLAG - if (context_ == nullptr) { - LOGE("context_ is nullptr!"); - return ""; - } - context_->accesser.isCommonFlag = true; - LOGI("Blue device do not generate cert!"); - return ""; -#else - DmCertChain dmCertChain; - int32_t certRet = AuthCert::GetInstance().GenerateCertificate(dmCertChain); - if (certRet != DM_OK) { - LOGE("generate cert fail, certRet = %{public}d", certRet); - return ""; - } - std::string cert = AuthAttestCommon::GetInstance().SerializeDmCertChain(&dmCertChain); - AuthAttestCommon::GetInstance().FreeDmCertChain(dmCertChain); - return cert; -#endif -} - int32_t AuthManager::BindTarget(const std::string &pkgName, const PeerTargetId &targetId, const std::map &bindParam, int sessionId, uint64_t logicalSessionId) { @@ -688,7 +663,6 @@ int32_t AuthManager::BindTarget(const std::string &pkgName, const PeerTargetId & return ERR_DM_INPUT_PARA_INVALID; } - context_->accesser.cert = GenerateCertificate(context_); context_->sessionId = sessionId; context_->logicalSessionId = logicalSessionId; context_->requestId = static_cast(logicalSessionId); diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp index 0639821f5..34f9d2967 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp @@ -182,47 +182,6 @@ int32_t AuthSinkNegotiateStateMachine::ProcRespNegotiate5_1_0(std::shared_ptr context) -{ -#ifdef DEVICE_MANAGER_COMMON_FLAG - (void)context; - LOGI("Blue device do not verify cert!"); - return DM_OK; -#else - // Compatible with 5.1.0 and earlier - if (!CompareVersion(context->accesser.dmVersion, DM_VERSION_5_1_0)) { - LOGI("cert verify is not supported"); - return DM_OK; - } - // Compatible common device - if (CompareVersion(context->accesser.dmVersion, DM_VERSION_5_1_0) - && context->accesser.isCommonFlag == true) { - LOGI("src is common device."); - if (DeviceProfileConnector::GetInstance() - .CheckIsSameAccountByUdidHash(context->accesser.deviceIdHash) == DM_OK) { - LOGE("src is common device, but the udidHash is identical in acl!"); - return ERR_DM_VERIFY_CERT_FAILED; - } - return DM_OK; - } - DmCertChain dmCertChain{nullptr, 0}; - if (!AuthAttestCommon::GetInstance() - .DeserializeDmCertChain(context->accesser.cert, &dmCertChain)) { - LOGE("cert deserialize fail!"); - return ERR_DM_DESERIAL_CERT_FAILED; - } - int32_t certRet = AuthCert::GetInstance() - .VerifyCertificate(dmCertChain, context->accesser.deviceIdHash.c_str()); - // free dmCertChain memory - AuthAttestCommon::GetInstance().FreeDmCertChain(dmCertChain); - if (certRet != DM_OK) { - LOGE("validate cert fail, certRet = %{public}d", certRet); - return ERR_DM_VERIFY_CERT_FAILED; - } - return DM_OK; -#endif -} - int32_t AuthSinkNegotiateStateMachine::Action(std::shared_ptr context) { LOGI("AuthSinkNegotiateStateMachine::Action sessionid %{public}d", context->sessionId); @@ -247,14 +206,7 @@ int32_t AuthSinkNegotiateStateMachine::Action(std::shared_ptr con context->reason = ERR_DM_VERSION_INCOMPATIBLE; return ERR_DM_VERSION_INCOMPATIBLE; } - // verify cert - int32_t ret = VerifyCertificate(context); - if (ret != DM_OK) { - LOGE("AuthSinkNegotiateStateMachine::Action cert verify fail!"); - context->reason = ret; - return ret; - } - ret = ProcRespNegotiate5_1_0(context); + int32_t ret = ProcRespNegotiate5_1_0(context); if (ret != DM_OK) { LOGE("AuthSinkNegotiateStateMachine::Action proc response negotiate failed"); context->reason = ret; diff --git a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 043302bf8..2dbaeb495 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -646,8 +646,6 @@ int32_t DmAuthMessageProcessor::CreateNegotiateMessage(std::shared_ptraccesser.tokenIdHash; jsonObject[TAG_BUNDLE_NAME_V2] = context->accesser.bundleName; jsonObject[TAG_EXTRA_INFO] = context->accesser.extraInfo; - jsonObject[TAG_IS_COMMON_FLAG] = context->accesser.isCommonFlag; - jsonObject[TAG_DM_CERT_CHAIN] = context->accesser.cert; jsonObject[TAG_PEER_BUNDLE_NAME_V2] = context->accessee.bundleName; jsonObject[TAG_ULTRASONIC_SIDE] = static_cast(context->ultrasonicInfo); @@ -1016,7 +1014,6 @@ int32_t DmAuthMessageProcessor::ParseNegotiateMessage( context->pkgLabel = jsonObject[TAG_HOST_PKGLABEL].Get(); } ParseUltrasonicSide(jsonObject, context); - ParseCert(jsonObject, context); context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 3ffe3af1e..0d3886893 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -1147,7 +1147,7 @@ void DeviceManagerServiceImpl::OnBytesReceived(int sessionId, const void *data, return; } if (msgType == MSG_TYPE_REQ_ACL_NEGOTIATE || msgType == MSG_TYPE_RESP_ACL_NEGOTIATE) { - curSession->version_ = DM_VERSION_5_1_1; + curSession->version_ = DM_CURRENT_VERSION; } } else { /** -- Gitee From 44146815ae9170c41aedd9ead5880117dd3f6d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Thu, 12 Jun 2025 19:31:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- commondependency/src/deviceprofile_connector.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 98d56a8a4..96b28476a 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2195,8 +2195,6 @@ DmOfflineParam DeviceProfileConnector::HandleServiceUnBindEvent(int32_t remoteUs return offlineParam; } - - DM_EXPORT std::vector DeviceProfileConnector::GetAllAccessControlProfile() { std::vector profiles; -- Gitee From e8b5d1f308bbf48d27abe835d0bda328a932cad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Thu, 12 Jun 2025 19:50:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- commondependency/src/deviceprofile_connector.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 96b28476a..4b3a3b1dd 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -37,8 +37,6 @@ const uint32_t IDENTICAL_ACCOUNT_TYPE = 6; const uint32_t SERVICE_PEER_TO_PEER_TYPE = 7; const uint32_t SERVICE_ACROSS_ACCOUNT_TYPE = 8; -const int32_t USLEEP_TIME_US_120000 = 120000; // 120ms -constexpr uint32_t RETRY_TIMES = 3; const uint32_t DM_INVALIED_TYPE = 2048; const uint32_t SERVICE = 2; -- Gitee