From 116d2ba3a7077fd3192e846bf1d30fa8d8e22316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B7=8D?= Date: Thu, 24 Oct 2024 11:26:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=E9=BB=84=E8=93=9D=E5=B7=AE?= =?UTF-8?q?=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李巍 --- .../src/authentication/dm_auth_manager.cpp | 182 ++++++++++++------ 1 file changed, 119 insertions(+), 63 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 715e23cb3..c4c2a5e23 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -486,7 +486,9 @@ void DmAuthManager::ProcessSourceMsg() break; case MSG_TYPE_REQ_SYNC_DELETE_DONE: if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_SYNCDELETE) { - timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + } isFinishOfLocal_ = false; authRequestState_->TransitionTo(std::make_shared()); } @@ -505,7 +507,9 @@ void DmAuthManager::ProcessSinkMsg() switch (authResponseContext_->msgType) { case MSG_TYPE_NEGOTIATE: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT) { - timer_->DeleteTimer(std::string(WAIT_NEGOTIATE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(WAIT_NEGOTIATE_TIMEOUT_TASK)); + } authResponseState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); @@ -513,7 +517,9 @@ void DmAuthManager::ProcessSinkMsg() break; case MSG_TYPE_REQ_AUTH: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE) { - timer_->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); + } authResponseState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); @@ -537,7 +543,9 @@ void DmAuthManager::ProcessSinkMsg() break; case MSG_TYPE_REQ_SYNC_DELETE_DONE: if (authResponseState_->GetStateType() == AuthState::AUTH_REQUEST_SYNCDELETE) { - timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + } isFinishOfLocal_ = false; authResponseState_->TransitionTo(std::make_shared()); } @@ -627,6 +635,7 @@ void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) HandleMemberJoinImportAuthCode(requestId, status); return; } + CHECK_NULL_VOID(timer_); if (status != DM_OK || authResponseContext_->requestId != requestId) { if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; @@ -744,10 +753,12 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); - timer_->StartTimer(std::string(NEGOTIATE_TIMEOUT_TASK), - GetTaskTimeout(NEGOTIATE_TIMEOUT_TASK, NEGOTIATE_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleAuthenticateTimeout(name); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(NEGOTIATE_TIMEOUT_TASK), + GetTaskTimeout(NEGOTIATE_TIMEOUT_TASK, NEGOTIATE_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + } } void DmAuthManager::AbilityNegotiate() @@ -807,21 +818,26 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) } else { ProRespNegotiate(sessionId); } - timer_->StartTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK), - GetTaskTimeout(WAIT_REQUEST_TIMEOUT_TASK, WAIT_REQUEST_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleAuthenticateTimeout(name); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK), + GetTaskTimeout(WAIT_REQUEST_TIMEOUT_TASK, WAIT_REQUEST_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + } } void DmAuthManager::SendAuthRequest(const int32_t &sessionId) { + LOGI("DmAuthManager::SendAuthRequest sessionId %{public}d.", sessionId); if (authResponseContext_ == nullptr) { LOGE("failed to SendAuthRequest because authResponseContext_ is nullptr"); return; } LOGI("DmAuthManager::SendAuthRequest session id"); remoteDeviceId_ = authResponseContext_->localDeviceId; - timer_->DeleteTimer(std::string(NEGOTIATE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(NEGOTIATE_TIMEOUT_TASK)); + } if (authResponseContext_->cryptoSupport) { isCryptoSupport_ = true; } @@ -863,10 +879,12 @@ void DmAuthManager::ProcessAuthRequest(const int32_t &sessionId) 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); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), + GetTaskTimeout(CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + } } void DmAuthManager::GetAuthRequestContext() @@ -937,10 +955,12 @@ void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) 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); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), + GetTaskTimeout(CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + } } int32_t DmAuthManager::ConfirmProcess(const int32_t &action) @@ -1023,26 +1043,30 @@ void DmAuthManager::StartRespAuthProcess() return; } LOGI("DmAuthManager::StartRespAuthProcess sessionId = %{public}d", authResponseContext_->sessionId); - timer_->DeleteTimer(std::string(CONFIRM_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(CONFIRM_TIMEOUT_TASK)); + } if (authResponseContext_->groupName[CHECK_AUTH_ALWAYS_POS] == AUTH_ALWAYS) { action_ = USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS; } else if (authResponseContext_->groupName[CHECK_AUTH_ALWAYS_POS] == AUTH_ONCE) { action_ = USER_OPERATION_TYPE_ALLOW_AUTH; } if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH) { - timer_->StartTimer(std::string(INPUT_TIMEOUT_TASK), - GetTaskTimeout(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleAuthenticateTimeout(name); - }); - timer_->StartTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK), - GetTaskTimeout(SESSION_HEARTBEAT_TIMEOUT_TASK, SESSION_HEARTBEAT_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleSessionHeartbeat(name); - }); - listener_->OnAuthResult(authRequestContext_->hostPkgName, peerTargetId_.deviceId, - authRequestContext_->token, STATUS_DM_SHOW_PIN_INPUT_UI, DM_OK); - listener_->OnBindResult(authRequestContext_->hostPkgName, peerTargetId_, DM_OK, - STATUS_DM_SHOW_PIN_INPUT_UI, ""); - authRequestState_->TransitionTo(std::make_shared()); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(INPUT_TIMEOUT_TASK), + GetTaskTimeout(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + timer_->StartTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK), + GetTaskTimeout(SESSION_HEARTBEAT_TIMEOUT_TASK, SESSION_HEARTBEAT_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleSessionHeartbeat(name); + }); + listener_->OnAuthResult(authRequestContext_->hostPkgName, peerTargetId_.deviceId, + authRequestContext_->token, STATUS_DM_SHOW_PIN_INPUT_UI, DM_OK); + listener_->OnBindResult(authRequestContext_->hostPkgName, peerTargetId_, DM_OK, + STATUS_DM_SHOW_PIN_INPUT_UI, ""); + authRequestState_->TransitionTo(std::make_shared()); + } } else { LOGE("do not accept"); authResponseContext_->state = AuthState::AUTH_REQUEST_REPLY; @@ -1071,7 +1095,9 @@ int32_t DmAuthManager::AddMember(int32_t pinCode) return ERR_DM_FAILED; } LOGI("DmAuthManager::AddMember start group id %{public}s", GetAnonyString(authResponseContext_->groupId).c_str()); - timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); + } nlohmann::json jsonObject; jsonObject[TAG_GROUP_ID] = authResponseContext_->groupId; jsonObject[TAG_GROUP_NAME] = authResponseContext_->groupName; @@ -1079,10 +1105,12 @@ int32_t DmAuthManager::AddMember(int32_t pinCode) jsonObject[TAG_REQUEST_ID] = authResponseContext_->requestId; jsonObject[TAG_DEVICE_ID] = authResponseContext_->deviceId; std::string connectInfo = jsonObject.dump(); - timer_->StartTimer(std::string(ADD_TIMEOUT_TASK), - GetTaskTimeout(ADD_TIMEOUT_TASK, ADD_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleAuthenticateTimeout(name); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(ADD_TIMEOUT_TASK), + GetTaskTimeout(ADD_TIMEOUT_TASK, ADD_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + } if (authUiStateMgr_ == nullptr) { LOGE("DmAuthManager::AddMember authUiStateMgr is null."); return ERR_DM_FAILED; @@ -1202,7 +1230,9 @@ void DmAuthManager::AuthenticateFinish() } else if (authRequestState_ != nullptr) { SrcAuthenticateFinish(); } - timer_->DeleteAll(); + if (timer_ != nullptr) { + timer_->DeleteAll(); + } isFinishOfLocal_ = true; authResponseContext_ = nullptr; authMessageProcessor_ = nullptr; @@ -1416,7 +1446,9 @@ int32_t DmAuthManager::ProcessPincode(int32_t pinCode) LOGE("failed to ProcessPincode because authResponseContext_ is nullptr"); return ERR_DM_FAILED; } - timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); + } if (authResponseContext_->dmVersion == DM_NEW_VERSION && authResponseContext_->bindLevel != INVALIED_TYPE) { return AuthDevice(pinCode); } else { @@ -1434,10 +1466,12 @@ int32_t DmAuthManager::AuthDevice(int32_t pinCode) } isAuthDevice_ = true; int32_t osAccountId = MultipleUserConnector::GetCurrentAccountUserID(); - timer_->StartTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK), AUTH_DEVICE_TIMEOUT, - [this] (std::string name) { - DmAuthManager::HandleAuthenticateTimeout(name); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK), AUTH_DEVICE_TIMEOUT, + [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + } if (hiChainAuthConnector_->AuthDevice(pinCode, osAccountId, remoteDeviceId_, authResponseContext_->requestId) != DM_OK) { LOGE("DmAuthManager::AuthDevice failed."); @@ -1813,7 +1847,9 @@ void DmAuthManager::RequestCredentialDone() if (ImportCredential(remoteDeviceId_, authResponseContext_->publicKey) != DM_OK) { LOGE("ResponseCredential import credential failed."); } - timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); + } softbusConnector_->JoinLnn(authRequestContext_->ip); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; @@ -1878,7 +1914,9 @@ void DmAuthManager::SrcSyncDeleteAclDone() DeleteAcl(authRequestContext_->hostPkgName, remoteDeviceId_); } softbusConnector_->GetSoftbusSession()->CloseUnbindSession(authRequestContext_->sessionId); - timer_->DeleteAll(); + if (timer_ != nullptr) { + timer_->DeleteAll(); + } isFinishOfLocal_ = true; authRequestContext_ = nullptr; authResponseContext_ = nullptr; @@ -1904,7 +1942,9 @@ void DmAuthManager::SinkSyncDeleteAclDone() DeleteAcl(authResponseContext_->hostPkgName, remoteDeviceId_); } } - timer_->DeleteAll(); + if (timer_ != nullptr) { + timer_->DeleteAll(); + } isFinishOfLocal_ = true; authResponseContext_ = nullptr; authResponseState_ = nullptr; @@ -1937,7 +1977,9 @@ void DmAuthManager::ResponseCredential() void DmAuthManager::ResponseSyncDeleteAcl() { LOGI("ResponseSyncDeleteAcl start."); - timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(SYNC_DELETE_TIMEOUT_TASK)); + } remoteDeviceId_ = authResponseContext_->localDeviceId; authResponseState_->TransitionTo(std::make_shared()); } @@ -1974,7 +2016,9 @@ void DmAuthManager::SrcAuthDeviceFinish() softbusConnector_->SetPkgName(authResponseContext_->hostPkgName); } softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); - timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); + } authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); @@ -1993,7 +2037,9 @@ void DmAuthManager::SrcAuthDeviceFinish() } if (!authResponseContext_->isOnline && authResponseContext_->haveCredential) { softbusConnector_->JoinLnn(authRequestContext_->ip); - timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); + } authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); @@ -2028,7 +2074,9 @@ void DmAuthManager::AuthDeviceFinish(int64_t requestId) return; } isAuthDevice_ = false; - timer_->DeleteTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK)); + } if (authRequestState_ != nullptr && authResponseState_ == nullptr) { PutAccessControlList(); SrcAuthDeviceFinish(); @@ -2053,17 +2101,21 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) return; } authTimes_++; - timer_->DeleteTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK)); + } if (errorCode != DM_OK || requestId != authResponseContext_->requestId) { if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authRequestContext_->reason = ERR_DM_INPUT_PARA_INVALID; authRequestState_->TransitionTo(std::make_shared()); } else { - timer_->StartTimer(std::string(INPUT_TIMEOUT_TASK), - GetTaskTimeout(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleAuthenticateTimeout(name); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(INPUT_TIMEOUT_TASK), + GetTaskTimeout(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + } authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_PIN_CODE_ERROR); } } @@ -2463,7 +2515,9 @@ void DmAuthManager::PutAccessControlList() void DmAuthManager::HandleSessionHeartbeat(std::string name) { - timer_->DeleteTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK)); + } LOGI("DmAuthManager::HandleSessionHeartbeat name %{public}s", name.c_str()); nlohmann::json jsonObj; jsonObj[TAG_SESSION_HEARTBEAT] = TAG_SESSION_HEARTBEAT; @@ -2471,10 +2525,12 @@ void DmAuthManager::HandleSessionHeartbeat(std::string name) softbusConnector_->GetSoftbusSession()->SendHeartbeatData(authResponseContext_->sessionId, message); if (authRequestState_ != nullptr) { - timer_->StartTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK), - GetTaskTimeout(SESSION_HEARTBEAT_TIMEOUT_TASK, SESSION_HEARTBEAT_TIMEOUT), [this] (std::string name) { - DmAuthManager::HandleSessionHeartbeat(name); - }); + if (timer_ != nullptr) { + timer_->StartTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK), + GetTaskTimeout(SESSION_HEARTBEAT_TIMEOUT_TASK, SESSION_HEARTBEAT_TIMEOUT), [this] (std::string name) { + DmAuthManager::HandleSessionHeartbeat(name); + }); + } } LOGI("DmAuthManager::HandleSessionHeartbeat complete"); } -- Gitee