From 0ea98f687b27a385cefced08b298edcdc209efa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 19 Aug 2025 15:31:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E6=89=8B=E8=A1=A8?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- common/include/dm_error_type.h | 1 + .../authentication_v2/dm_auth_context.h | 2 +- .../authentication_v2/dm_auth_manager_base.h | 2 +- .../src/authentication_v2/auth_manager.cpp | 20 +++++++++++-------- .../auth_stages/auth_acl.cpp | 5 ++++- .../dm_auth_manager_base.cpp | 2 +- .../src/authentication_v2/dm_auth_state.cpp | 3 ++- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index 753c754f2..0bca1de1b 100644 --- a/common/include/dm_error_type.h +++ b/common/include/dm_error_type.h @@ -144,6 +144,7 @@ enum { ERR_DM_DEVICE_FROZEN = 969298355, ERR_DM_SOCKET_IN_USED = 969298356, ERR_DM_ANTI_DISTURB_MODE = 969298357, + ERR_DM_SKIP_AUTHENTICATE = 969298358, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/authentication_v2/dm_auth_context.h b/services/implementation/include/authentication_v2/dm_auth_context.h index e60adda5c..4bb875565 100644 --- a/services/implementation/include/authentication_v2/dm_auth_context.h +++ b/services/implementation/include/authentication_v2/dm_auth_context.h @@ -278,7 +278,7 @@ struct DmAuthContext { bool IsProxyBind{false}; bool IsCallingProxyAsSubject{true}; bool IsNeedSetProxy{false}; - bool isNeedAuthorize{false}; + bool isNeedAuthenticate{true}; // apply for skip authenticate std::vector subjectProxyOnes; std::string reUseCreId; std::string title; diff --git a/services/implementation/include/authentication_v2/dm_auth_manager_base.h b/services/implementation/include/authentication_v2/dm_auth_manager_base.h index c680323a4..0713e8d2e 100644 --- a/services/implementation/include/authentication_v2/dm_auth_manager_base.h +++ b/services/implementation/include/authentication_v2/dm_auth_manager_base.h @@ -57,7 +57,7 @@ extern const char* TAG_HOST_PKGLABEL; extern const char* TAG_REMOTE_DEVICE_NAME; extern const char* TAG_HOST; extern const char* TAG_PROXY_CONTEXT_ID; - +extern const char* TAG_IS_NEED_AUTHENTICATE; extern const char* APP_OPERATION_KEY; extern const char* TARGET_PKG_NAME_KEY; extern const char* CUSTOM_DESCRIPTION_KEY; diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index ad9835e7c..a82000410 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -448,7 +448,6 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) std::string delaySecondsStr = jsonObject[PARAM_CLOSE_SESSION_DELAY_SECONDS].Get(); context_->connDelayCloseTime = GetCloseSessionDelaySeconds(delaySecondsStr); } - context_->accessee.bundleName = context_->accesser.bundleName; if (jsonObject[TAG_PEER_BUNDLE_NAME].IsString() && !jsonObject[TAG_PEER_BUNDLE_NAME].Get().empty()) { context_->accessee.bundleName = jsonObject[TAG_PEER_BUNDLE_NAME].Get(); @@ -456,14 +455,11 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) } else { context_->accessee.oldBundleName = context_->pkgName; } - context_->accesser.pkgName = context_->pkgName; context_->accessee.pkgName = context_->accesser.pkgName; - if (jsonObject[TAG_PEER_PKG_NAME].IsString()) { context_->accessee.pkgName = jsonObject[TAG_PEER_PKG_NAME].Get(); } - if (jsonObject[TAG_PEER_DISPLAY_ID].IsNumberInteger()) { context_->accessee.displayId = jsonObject[TAG_PEER_DISPLAY_ID].Get(); } @@ -472,11 +468,13 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) } else { context_->accesser.userId = MultipleUserConnector::GetFirstForegroundUserId(); } - + if (jsonObject[TAG_IS_NEED_AUTHENTICATE].IsString()) { + context_->isNeedAuthenticate = std::atoi(jsonObject[TAG_IS_NEED_AUTHENTICATE].Get()); + LOGI("isNeedAuthenticate: %{public}d.", context_->isNeedAuthenticate); + } if (context_->authType == AUTH_TYPE_PIN_ULTRASONIC) { ParseUltrasonicSide(jsonObject); } - ParseHmlInfoInJsonObject(jsonObject); ParseProxyJsonObject(jsonObject); return; @@ -972,8 +970,14 @@ void AuthSrcManager::AuthDeviceFinish(int64_t requestId) DmAuthStateType curState = context_->authStateMachine->GetCurState(); switch (curState) { case DmAuthStateType::AUTH_SRC_PIN_AUTH_DONE_STATE: - // ON_FINISH event occurs, start credential exchange - context_->authStateMachine->TransitionTo(std::make_shared()); + if (!context_->isNeedAuthenticate) { + LOGI("skip authenticate."); + context_->reason = ERR_DM_SKIP_AUTHENTICATE; + context_->authStateMachine->TransitionTo(std::make_shared()); + } else { + // ON_FINISH event occurs, start credential exchange + context_->authStateMachine->TransitionTo(std::make_shared()); + } break; default: break; diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index d6d13bfc9..bc7b5dc48 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -231,7 +231,10 @@ DmAuthStateType AuthSinkFinishState::GetStateType() int32_t AuthSrcFinishState::Action(std::shared_ptr context) { LOGI("AuthSrcFinishState::Action start"); - if (context->reason != DM_OK && context->reason != DM_BIND_TRUST_TARGET) { + if (context->reason == ERR_DM_SKIP_AUTHENTICATE && !context_->isNeedAuthenticate) { + context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_AUTH_REQ_FINISH, context); + context->state = static_cast(GetStateType()); + } else if (context->reason != DM_OK && context->reason != DM_BIND_TRUST_TARGET) { context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_AUTH_REQ_FINISH, context); } else { context->state = static_cast(GetStateType()); diff --git a/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp b/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp index 3c9fb29de..26e7781d5 100644 --- a/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp @@ -58,7 +58,7 @@ const char* TAG_HOST_PKGLABEL = "hostPkgLabel"; const char* TAG_REMOTE_DEVICE_NAME = "REMOTE_DEVICE_NAME"; const char* TAG_HOST = "HOST"; const char* TAG_PROXY_CONTEXT_ID = "proxyContextId"; - +const char* TAG_IS_NEED_AUTHENTICATE = "isNeedAuthenticate"; const char* APP_OPERATION_KEY = "appOperation"; const char* TARGET_PKG_NAME_KEY = "targetPkgName"; const char* CUSTOM_DESCRIPTION_KEY = "customDescription"; diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index a8da66832..200483586 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -76,7 +76,8 @@ const std::map NEW_AND_OLD_STATE_MAPPING = { const std::map NEW_AND_OLD_REPLAY_MAPPING = { { DM_ALREADY_AUTHED, SOFTBUS_OK }, { SOFTBUS_OK, SOFTBUS_OK }, - { DM_BIND_TRUST_TARGET, DM_OK } + { DM_BIND_TRUST_TARGET, DM_OK }, + { ERR_DM_SKIP_AUTHENTICATE, DM_OK }, }; int32_t DmAuthState::GetTaskTimeout(std::shared_ptr context, const char* taskName, int32_t taskTimeOut) -- Gitee From 817b8ef1fd58eb3c10f8a0efcff60d6b1cfaeabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 19 Aug 2025 16:06:29 +0800 Subject: [PATCH 2/3] code check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../src/authentication_v2/auth_stages/auth_acl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index bc7b5dc48..10f7cacfd 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -231,7 +231,7 @@ DmAuthStateType AuthSinkFinishState::GetStateType() int32_t AuthSrcFinishState::Action(std::shared_ptr context) { LOGI("AuthSrcFinishState::Action start"); - if (context->reason == ERR_DM_SKIP_AUTHENTICATE && !context_->isNeedAuthenticate) { + if (context->reason == ERR_DM_SKIP_AUTHENTICATE && !context->isNeedAuthenticate) { context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_AUTH_REQ_FINISH, context); context->state = static_cast(GetStateType()); } else if (context->reason != DM_OK && context->reason != DM_BIND_TRUST_TARGET) { -- Gitee From 90a576c01e84f71c625eb6884774fdb772026601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Tue, 19 Aug 2025 16:20:55 +0800 Subject: [PATCH 3/3] code check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../implementation/src/authentication_v2/auth_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index a82000410..57cf57f50 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -971,9 +971,9 @@ void AuthSrcManager::AuthDeviceFinish(int64_t requestId) switch (curState) { case DmAuthStateType::AUTH_SRC_PIN_AUTH_DONE_STATE: if (!context_->isNeedAuthenticate) { - LOGI("skip authenticate."); - context_->reason = ERR_DM_SKIP_AUTHENTICATE; - context_->authStateMachine->TransitionTo(std::make_shared()); + LOGI("skip authenticate."); + context_->reason = ERR_DM_SKIP_AUTHENTICATE; + context_->authStateMachine->TransitionTo(std::make_shared()); } else { // ON_FINISH event occurs, start credential exchange context_->authStateMachine->TransitionTo(std::make_shared()); -- Gitee