From d5fc4f1ece334b3f5172c6f0d91c982cb02fb473 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Fri, 23 May 2025 15:18:40 +0800 Subject: [PATCH 1/4] dm Signed-off-by: l30054665 --- .../include/authentication/dm_auth_manager.h | 1 + .../include/authentication_v2/dm_auth_state.h | 2 +- .../src/authentication/dm_auth_manager.cpp | 34 ++++++++++++-- .../auth_stages/auth_confirm.cpp | 5 +++ .../auth_stages/auth_pin_auth.cpp | 4 ++ .../src/authentication_v2/dm_auth_state.cpp | 44 +++++++++++-------- 6 files changed, 66 insertions(+), 24 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 0e07eb948..509cb730b 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -544,6 +544,7 @@ public: bool AuthDeviceTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); void AuthDeviceFinish(int64_t requestId); void AuthDeviceError(int64_t requestId, int32_t errorCode); + int32_t GetOutputState(int32_t state); void GetRemoteDeviceId(std::string &deviceId); void AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); char *AuthDeviceRequest(int64_t requestId, int operationCode, const char *reqParams); diff --git a/services/implementation/include/authentication_v2/dm_auth_state.h b/services/implementation/include/authentication_v2/dm_auth_state.h index 6cefe931d..e729ae5dd 100644 --- a/services/implementation/include/authentication_v2/dm_auth_state.h +++ b/services/implementation/include/authentication_v2/dm_auth_state.h @@ -156,7 +156,7 @@ public: void FilterProfilesByContext(std::vector &profiles, std::shared_ptr context); int32_t GetAclBindType(std::shared_ptr context, std::string credId); - int32_t GetOutputState(const std::string &processName, int32_t state); + int32_t GetOutputState(int32_t state); int32_t GetOutputReplay(const std::string &processName, int32_t replay); static uint64_t GetSysTimeMs(); static void DeleteAcl(std::shared_ptr context, diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 085c919cc..7a60dbf62 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -75,6 +75,21 @@ const std::map TASK_TIME_OUT_MAP = { { std::string(WAIT_REQUEST_TIMEOUT_TASK), CLONE_WAIT_REQUEST_TIMEOUT }, { std::string(SESSION_HEARTBEAT_TIMEOUT_TASK), CLONE_SESSION_HEARTBEAT_TIMEOUT } }; +const std::map OLD_STATE_MAPPING = { + { AuthState::AUTH_REQUEST_INIT, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_NEGOTIATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_NEGOTIATE_DONE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_REPLY, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_JOIN, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_NETWORK, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_FINISH, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_CREDENTIAL, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_CREDENTIAL_DONE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_AUTH_FINISH, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_RECHECK_MSG, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_REQUEST_RECHECK_MSG_DONE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { AuthState::AUTH_RESPONSE_FINISH, DmAuthStatus::STATUS_DM_SINK_AUTH_FINISH } +}; constexpr int32_t PROCESS_NAME_WHITE_LIST_NUM = 1; constexpr const static char* PROCESS_NAME_WHITE_LIST[PROCESS_NAME_WHITE_LIST_NUM] = { "com.example.myapplication" @@ -1405,6 +1420,16 @@ void DmAuthManager::SinkAuthenticateFinish() authTimes_ = 0; } +int32_t DmAuthManager::GetOutputState(int32_t state) +{ + LOGI("state %{public}d.", state); + auto it = OLD_STATE_MAPPING.find(static_cast(state)); + if (it != OLD_STATE_MAPPING.end()) { + return static_cast(it->second); + } + return STATUS_DM_AUTH_DEFAULT; +} + void DmAuthManager::SrcAuthenticateFinish() { LOGI("DmAuthManager::SrcAuthenticateFinish, isFinishOfLocal: %{public}d", isFinishOfLocal_); @@ -1437,10 +1462,11 @@ void DmAuthManager::SrcAuthenticateFinish() DmAuthManager::CloseAuthSession(sessionId); } }); - listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, - authResponseContext_->state, authRequestContext_->reason); - listener_->OnBindResult(processInfo_, peerTargetId_, authRequestContext_->reason, - authResponseContext_->state, GenerateBindResultContent()); + int32_t status = GetOutputState(authResponseContext_->state); + listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, status, + authRequestContext_->reason); + listener_->OnBindResult(processInfo_, peerTargetId_, authRequestContext_->reason, status, + GenerateBindResultContent()); authRequestContext_ = nullptr; authRequestState_ = nullptr; diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp index 5d3e7c1f7..57e8e3c17 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp @@ -460,6 +460,11 @@ int32_t AuthSrcConfirmState::Action(std::shared_ptr context) context->accesser.aclTypeList = aclNegoResult.Dump(); context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_REQ_USER_CONFIRM, context); + + context->listener->OnAuthResult(context->processInfo, context->peerTargetId.deviceId, context->accessee.tokenIdHash, + STATUS_DM_SHOW_AUTHORIZE_UI, DM_OK); + context->listener->OnBindResult(context->processInfo, context->peerTargetId, + DM_OK, STATUS_DM_SHOW_AUTHORIZE_UI, ""); context->timer->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), DmAuthState::GetTaskTimeout(context, CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT), [context] (std::string name) { diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp index f221d519d..a2164a77f 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp @@ -493,6 +493,10 @@ int32_t AuthSrcPinInputState::ShowStartAuthDialog(std::shared_ptr return STOP_BIND; } + context->listener->OnAuthResult(context->processInfo, context->peerTargetId.deviceId, context->accessee.tokenIdHash, + STATUS_DM_SHOW_PIN_INPUT_UI, DM_OK); + context->listener->OnBindResult(context->processInfo, context->peerTargetId, + DM_OK, STATUS_DM_SHOW_PIN_INPUT_UI, ""); DmDialogManager::GetInstance().ShowInputDialog(context->accessee.deviceName); LOGI("AuthSrcPinInputState::ShowStartAuthDialog end."); return DM_OK; diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 16c19ae22..dac775c69 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -53,7 +53,23 @@ constexpr const static char* ONBINDRESULT_MAPPING_LIST[ONBINDRESULT_MAPPING_NUM] const std::map NEW_AND_OLD_STATE_MAPPING = { { DmAuthStateType::AUTH_SRC_FINISH_STATE, DmAuthStatus::STATUS_DM_AUTH_FINISH }, - { DmAuthStateType::AUTH_SINK_FINISH_STATE, DmAuthStatus::STATUS_DM_SINK_AUTH_FINISH } + { DmAuthStateType::AUTH_SINK_FINISH_STATE, DmAuthStatus::STATUS_DM_SINK_AUTH_FINISH }, + { DmAuthStateType::AUTH_IDLE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_START_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_NEGOTIATE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_CONFIRM_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_PIN_NEGOTIATE_START_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_PIN_INPUT_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_REVERSE_ULTRASONIC_START_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_REVERSE_ULTRASONIC_DONE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_PIN_AUTH_START_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_PIN_AUTH_MSG_NEGOTIATE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_PIN_AUTH_DONE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_CREDENTIAL_EXCHANGE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_CREDENTIAL_AUTH_START_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_CREDENTIAL_AUTH_NEGOTIATE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_CREDENTIAL_AUTH_DONE_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT }, + { DmAuthStateType::AUTH_SRC_DATA_SYNC_STATE, DmAuthStatus::STATUS_DM_AUTH_DEFAULT } }; const std::map NEW_AND_OLD_REPLAY_MAPPING = { @@ -96,10 +112,10 @@ void DmAuthState::SourceFinish(std::shared_ptr context) { LOGI("SourceFinish reason:%{public}d", context->reason); context->listener->OnAuthResult(context->processInfo, context->peerTargetId.deviceId, context->accessee.tokenIdHash, - GetOutputState(context->accesser.bundleName, context->state), context->reason); + GetOutputState(context->state), context->reason); context->listener->OnBindResult(context->processInfo, context->peerTargetId, GetOutputReplay(context->accesser.bundleName, context->reason), - GetOutputState(context->accesser.bundleName, context->state), GenerateBindResultContent(context)); + GetOutputState(context->state), GenerateBindResultContent(context)); context->successFinished = true; if (context->reason != DM_OK && context->reason != DM_ALREADY_AUTHED) { @@ -134,7 +150,7 @@ void DmAuthState::SinkFinish(std::shared_ptr context) context->processInfo.pkgName = context->accessee.pkgName; context->listener->OnSinkBindResult(context->processInfo, context->peerTargetId, GetOutputReplay(context->accessee.bundleName, context->reason), - GetOutputState(context->accessee.bundleName, context->state), GenerateBindResultContent(context)); + GetOutputState(context->state), GenerateBindResultContent(context)); context->successFinished = true; if (context->reason != DM_OK) { // 根据凭据id 删除sink端多余的凭据 @@ -331,24 +347,14 @@ bool DmAuthState::HaveSameTokenId(std::shared_ptr context, const (srcTokenIdHash == context->accessee.tokenIdHash)); } -int32_t DmAuthState::GetOutputState(const std::string &processName, int32_t state) +int32_t DmAuthState::GetOutputState(int32_t state) { LOGI("state %{public}d.", state); - bool needMapFlag = false; - for (uint16_t index = 0; index < ONBINDRESULT_MAPPING_NUM; ++index) { - if (std::string(ONBINDRESULT_MAPPING_LIST[index]) == processName) { - LOGI("processName %{public}s new protocol param convert to old protocol param.", processName.c_str()); - needMapFlag = true; - break; - } - } - if (needMapFlag) { - auto it = NEW_AND_OLD_STATE_MAPPING.find(static_cast(state)); - if (it != NEW_AND_OLD_STATE_MAPPING.end()) { - return static_cast(it->second); - } + auto it = NEW_AND_OLD_STATE_MAPPING.find(static_cast(state)); + if (it != NEW_AND_OLD_STATE_MAPPING.end()) { + return static_cast(it->second); } - return state; + return STATUS_DM_AUTH_DEFAULT; } int32_t DmAuthState::GetOutputReplay(const std::string &processName, int32_t replay) -- Gitee From 52dd7d29fcfc21bf537d143858d2651fe0991f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=9A?= Date: Fri, 23 May 2025 07:21:41 +0000 Subject: [PATCH 2/4] update services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李尚 --- .../src/authentication_v2/auth_stages/auth_confirm.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp index 57e8e3c17..b9ec804bb 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp @@ -460,7 +460,6 @@ int32_t AuthSrcConfirmState::Action(std::shared_ptr context) context->accesser.aclTypeList = aclNegoResult.Dump(); context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_REQ_USER_CONFIRM, context); - context->listener->OnAuthResult(context->processInfo, context->peerTargetId.deviceId, context->accessee.tokenIdHash, STATUS_DM_SHOW_AUTHORIZE_UI, DM_OK); context->listener->OnBindResult(context->processInfo, context->peerTargetId, -- Gitee From ebd31aec3803b1a69689454f272c32af84a77aa4 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Fri, 23 May 2025 18:30:50 +0800 Subject: [PATCH 3/4] a Signed-off-by: l30054665 --- .../implementation/src/authentication/dm_auth_manager.cpp | 2 +- .../src/authentication_v2/auth_stages/auth_confirm.cpp | 4 ++-- .../src/authentication_v2/auth_stages/auth_pin_auth.cpp | 4 ++-- 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 7a60dbf62..5e3b692e1 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1427,7 +1427,7 @@ int32_t DmAuthManager::GetOutputState(int32_t state) if (it != OLD_STATE_MAPPING.end()) { return static_cast(it->second); } - return STATUS_DM_AUTH_DEFAULT; + return static_cast(STATUS_DM_AUTH_DEFAULT); } void DmAuthManager::SrcAuthenticateFinish() diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp index b9ec804bb..f861ff95e 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp @@ -461,9 +461,9 @@ int32_t AuthSrcConfirmState::Action(std::shared_ptr context) context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_REQ_USER_CONFIRM, context); context->listener->OnAuthResult(context->processInfo, context->peerTargetId.deviceId, context->accessee.tokenIdHash, - STATUS_DM_SHOW_AUTHORIZE_UI, DM_OK); + static_cast(STATUS_DM_SHOW_AUTHORIZE_UI), DM_OK); context->listener->OnBindResult(context->processInfo, context->peerTargetId, - DM_OK, STATUS_DM_SHOW_AUTHORIZE_UI, ""); + DM_OK, static_cast(STATUS_DM_SHOW_AUTHORIZE_UI), ""); context->timer->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), DmAuthState::GetTaskTimeout(context, CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT), [context] (std::string name) { diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp index a2164a77f..532809c3e 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_pin_auth.cpp @@ -494,9 +494,9 @@ int32_t AuthSrcPinInputState::ShowStartAuthDialog(std::shared_ptr } context->listener->OnAuthResult(context->processInfo, context->peerTargetId.deviceId, context->accessee.tokenIdHash, - STATUS_DM_SHOW_PIN_INPUT_UI, DM_OK); + static_cast(STATUS_DM_SHOW_PIN_INPUT_UI), DM_OK); context->listener->OnBindResult(context->processInfo, context->peerTargetId, - DM_OK, STATUS_DM_SHOW_PIN_INPUT_UI, ""); + DM_OK, static_cast(STATUS_DM_SHOW_PIN_INPUT_UI), ""); DmDialogManager::GetInstance().ShowInputDialog(context->accessee.deviceName); LOGI("AuthSrcPinInputState::ShowStartAuthDialog end."); return DM_OK; -- Gitee From 7a4cd4cbd287c4e96ceecaed5284530a25019457 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Fri, 23 May 2025 18:33:31 +0800 Subject: [PATCH 4/4] a Signed-off-by: l30054665 --- services/implementation/src/authentication_v2/dm_auth_state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index dac775c69..782ed8db1 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -354,7 +354,7 @@ int32_t DmAuthState::GetOutputState(int32_t state) if (it != NEW_AND_OLD_STATE_MAPPING.end()) { return static_cast(it->second); } - return STATUS_DM_AUTH_DEFAULT; + return static_cast(STATUS_DM_AUTH_DEFAULT); } int32_t DmAuthState::GetOutputReplay(const std::string &processName, int32_t replay) -- Gitee