From 4ef1536a34ba54eb201aedb4d5233688943ecf7c Mon Sep 17 00:00:00 2001 From: q30043944 Date: Fri, 1 Nov 2024 15:55:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=A4=E7=BB=84=E5=88=87=E6=8D=A2acl?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: q30043944 --- .../include/authentication/dm_auth_manager.h | 1 + .../src/authentication/dm_auth_manager.cpp | 58 ++++++++++++++----- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index bbea5de22..85982bc12 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -512,6 +512,7 @@ private: int32_t DeleteAcl(const std::string &pkgName, const std::string &localUdid, const std::string &remoteUdid, int32_t bindLevel); void ProcessAuthRequestExt(const int32_t &sessionId); + bool IsAuthFinish(); void ProcessAuthRequest(const int32_t &sessionId); int32_t ConfirmProcess(const int32_t &action); int32_t ConfirmProcessExt(const int32_t &action); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 3e4f8aa35..0848b84f0 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -932,24 +932,57 @@ void DmAuthManager::GetAuthRequestContext() void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) { LOGI("ProcessAuthRequestExt start."); + if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && + !authResponseContext_->importAuthCode.empty() && !importAuthCode_.empty()) { + if (authResponseContext_->importAuthCode != Crypto::Sha256(importAuthCode_)) { + SetReasonAndFinish(ERR_DM_AUTH_CODE_INCORRECT, AuthState::AUTH_REQUEST_FINISH); + return; + } + } + GetAuthRequestContext(); std::vector bindType = DeviceProfileConnector::GetInstance().SyncAclByBindType(authResponseContext_->hostPkgName, authResponseContext_->bindType, authResponseContext_->localDeviceId, authResponseContext_->deviceId); authResponseContext_->authed = !bindType.empty(); + if (authResponseContext_->isOnline && authResponseContext_->authed && + authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && + (authResponseContext_->importAuthCode.empty() || importAuthCode_.empty())) { + SetReasonAndFinish(ERR_DM_AUTH_CODE_INCORRECT, AuthState::AUTH_REQUEST_FINISH); + return; + } authResponseContext_->bindType = bindType; + if (IsAuthFinish()) { + return; + } + + std::vector messageList = authMessageProcessor_->CreateAuthRequestMessage(); + for (auto msg : messageList) { + softbusConnector_->GetSoftbusSession()->SendData(sessionId, msg); + } + listener_->OnAuthResult(authResponseContext_->hostPkgName, peerTargetId_.deviceId, + authRequestContext_->token, STATUS_DM_SHOW_AUTHORIZE_UI, DM_OK); + listener_->OnBindResult(authResponseContext_->hostPkgName, peerTargetId_, DM_OK, STATUS_DM_SHOW_AUTHORIZE_UI, ""); + timer_->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), + GetTaskTimeout(CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); +} + +bool DmAuthManager::IsAuthFinish() +{ if (authResponseContext_->reply == ERR_DM_UNSUPPORTED_AUTH_TYPE) { listener_->OnAuthResult(authResponseContext_->hostPkgName, peerTargetId_.deviceId, authRequestContext_->token, AuthState::AUTH_REQUEST_NEGOTIATE_DONE, ERR_DM_UNSUPPORTED_AUTH_TYPE); authRequestState_->TransitionTo(std::make_shared()); - return; + return true; } if (authResponseContext_->isOnline && authResponseContext_->authed) { authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); - return; + return true; } if ((authResponseContext_->isIdenticalAccount && !authResponseContext_->authed) || @@ -958,27 +991,16 @@ void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); - return; + return true; } if (authResponseContext_->reply == ERR_DM_UNSUPPORTED_AUTH_TYPE || (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && authResponseContext_->isAuthCodeReady == false)) { authRequestState_->TransitionTo(std::make_shared()); - return; - } - - std::vector messageList = authMessageProcessor_->CreateAuthRequestMessage(); - for (auto msg : messageList) { - softbusConnector_->GetSoftbusSession()->SendData(sessionId, msg); + return true; } - listener_->OnAuthResult(authResponseContext_->hostPkgName, peerTargetId_.deviceId, - authRequestContext_->token, STATUS_DM_SHOW_AUTHORIZE_UI, DM_OK); - listener_->OnBindResult(authResponseContext_->hostPkgName, peerTargetId_, DM_OK, STATUS_DM_SHOW_AUTHORIZE_UI, ""); - timer_->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), - GetTaskTimeout(CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleAuthenticateTimeout(name); - }); + return false; } int32_t DmAuthManager::ConfirmProcess(const int32_t &action) @@ -2106,6 +2128,10 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) DeviceProfileConnector::GetInstance().GetBindTypeByPkgName(authResponseContext_->hostPkgName, authResponseContext_->localDeviceId, authResponseContext_->deviceId); authResponseContext_->authed = !authResponseContext_->bindType.empty(); + if (authResponseContext_->authed && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && + !importAuthCode_.empty()) { + authResponseContext_->importAuthCode = Crypto::Sha256(importAuthCode_); + } authResponseContext_->isOnline = softbusConnector_->CheckIsOnline(remoteDeviceId_); authResponseContext_->haveCredential = hiChainAuthConnector_->QueryCredential(authResponseContext_->deviceId, authResponseContext_->localUserId); -- Gitee