diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 0e07eb948d0b721db392047de0830e5b32551b40..509cb730bc8386fb3cb33fe971c6527a78053cfa 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 6cefe931d75f1698a409fe631edeb69db4f39343..e729ae5dd9ee2b3d446670081ce474d837f82e5f 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 085c919cc8d090cc5483bb3eb2fbeb4b8cd08abe..5e3b692e1b7014526fe3fd2aeda314f6625ef1ca 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 static_cast(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 5d3e7c1f7695da6537b5121ca3c7b6a547d71364..f861ff95e9d598f9b177ed7872a385700f32f267 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,10 @@ 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, + static_cast(STATUS_DM_SHOW_AUTHORIZE_UI), DM_OK); + context->listener->OnBindResult(context->processInfo, context->peerTargetId, + 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 f221d519d13e9d55953442ebbc1fba889365b372..532809c3e2787957d7b2b30c87bfc14e487fe375 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, + static_cast(STATUS_DM_SHOW_PIN_INPUT_UI), DM_OK); + context->listener->OnBindResult(context->processInfo, context->peerTargetId, + DM_OK, static_cast(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 16c19ae22a55d3efb373686dd95b4c3fc565389a..782ed8db16ce2e5be08764f1c66c8ca4fcf6e538 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 static_cast(STATUS_DM_AUTH_DEFAULT); } int32_t DmAuthState::GetOutputReplay(const std::string &processName, int32_t replay)