diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 4241f843ff40919863732b893b1c21c3fd56f668..c7ab57b8bedab8f44582d7fc5efc1cb1e3b7b87a 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -82,6 +82,7 @@ void AuthMessageProcessor::GetJsonObj(JsonObject &jsonObj) LOGE("GetJsonObj invalid bindType size."); return; } + CHECK_NULL_VOID(authRequestContext_); jsonObj[TAG_VER] = DM_ITF_VER; jsonObj[TAG_MSG_TYPE] = MSG_TYPE_REQ_AUTH; jsonObj[TAG_INDEX] = 0; @@ -201,6 +202,7 @@ void AuthMessageProcessor::CreatePublicKeyMessageExt(JsonObject &json) std::lock_guard mutexLock(encryptFlagMutex_); encryptFlag = encryptFlag_; } + CHECK_NULL_VOID(authResponseContext_); if (!encryptFlag) { LOGI("not encrypt publickey."); json[TAG_PUBLICKEY] = authResponseContext_->publicKey; @@ -227,6 +229,7 @@ void AuthMessageProcessor::CreatePublicKeyMessageExt(JsonObject &json) void AuthMessageProcessor::CreateResponseAuthMessageExt(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); json[TAG_REPLY] = authResponseContext_->reply; json[TAG_TOKEN] = authResponseContext_->token; json[TAG_CONFIRM_OPERATION] = authResponseContext_->confirmOperation; @@ -235,6 +238,7 @@ void AuthMessageProcessor::CreateResponseAuthMessageExt(JsonObject &json) void AuthMessageProcessor::CreateNegotiateMessage(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); if (cryptoAdapter_ == nullptr) { json[TAG_CRYPTO_SUPPORT] = false; } else { @@ -267,6 +271,7 @@ void AuthMessageProcessor::CreateNegotiateMessage(JsonObject &json) void AuthMessageProcessor::CreateRespNegotiateMessage(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); if (cryptoAdapter_ == nullptr) { json[TAG_CRYPTO_SUPPORT] = false; } else { @@ -301,12 +306,14 @@ void AuthMessageProcessor::CreateRespNegotiateMessage(JsonObject &json) void AuthMessageProcessor::CreateSyncGroupMessage(JsonObject &json) { + CHECK_NULL_VOID(authRequestContext_); json[TAG_DEVICE_ID] = authRequestContext_->deviceId; json[TAG_GROUPIDS] = authRequestContext_->syncGroupList; } void AuthMessageProcessor::CreateResponseAuthMessage(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); json[TAG_REPLY] = authResponseContext_->reply; json[TAG_DEVICE_ID] = authResponseContext_->deviceId; json[TAG_TOKEN] = authResponseContext_->token; @@ -335,6 +342,7 @@ void AuthMessageProcessor::CreateResponseAuthMessage(JsonObject &json) void AuthMessageProcessor::CreateResponseFinishMessage(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); json[TAG_REPLY] = authResponseContext_->reply; json[TAG_AUTH_FINISH] = authResponseContext_->isFinish; } @@ -351,6 +359,7 @@ int32_t AuthMessageProcessor::ParseMessage(const std::string &message) return ERR_DM_FAILED; } int32_t msgType = jsonObject[TAG_MSG_TYPE].Get(); + CHECK_NULL_RETURN(authResponseContext_, ERR_DM_FAILED); authResponseContext_->msgType = msgType; LOGI("message type %{public}d", authResponseContext_->msgType); switch (msgType) { @@ -394,12 +403,14 @@ void AuthMessageProcessor::ParsePublicKeyMessageExt(JsonObject &json) encryptFlag = encryptFlag_; } if (!encryptFlag && IsString(json, TAG_PUBLICKEY)) { + CHECK_NULL_VOID(authResponseContext_); authResponseContext_->publicKey = json[TAG_PUBLICKEY].Get(); return; } if (encryptFlag && IsString(json, TAG_CRYPTIC_MSG)) { std::string encryptStr = json[TAG_CRYPTIC_MSG].Get(); std::string decryptStr = ""; + CHECK_NULL_VOID(authResponseContext_); authResponseContext_->publicKey = ""; CHECK_NULL_VOID(cryptoMgr_); if (cryptoMgr_->DecryptMessage(encryptStr, decryptStr) != DM_OK) { @@ -440,6 +451,7 @@ void AuthMessageProcessor::ParseAuthResponseMessageExt(JsonObject &json) void AuthMessageProcessor::ParseResponseFinishMessage(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); if (IsInt32(json, TAG_REPLY)) { authResponseContext_->reply = json[TAG_REPLY].Get(); } @@ -450,6 +462,7 @@ void AuthMessageProcessor::ParseResponseFinishMessage(JsonObject &json) void AuthMessageProcessor::GetAuthReqMessage(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); authResponseContext_->localDeviceId = ""; authResponseContext_->deviceId = ""; if (IsInt32(json, TAG_AUTH_TYPE)) { @@ -494,6 +507,7 @@ int32_t AuthMessageProcessor::ParseAuthRequestMessage(JsonObject &json) } idx = json[TAG_INDEX].Get(); sliceNum = json[TAG_SLICE_NUM].Get(); + CHECK_NULL_RETURN(authResponseContext_, ERR_DM_FAILED); if (idx == 0) { GetAuthReqMessage(json); authResponseContext_->appThumbnail = ""; @@ -532,6 +546,7 @@ void AuthMessageProcessor::ParseAuthResponseMessage(JsonObject &json) LOGE("AuthMessageProcessor::ParseAuthResponseMessage err json string, first time."); return; } + CHECK_NULL_VOID(authResponseContext_); authResponseContext_->reply = json[TAG_REPLY].Get(); if (IsString(json, TAG_DEVICE_ID)) { authResponseContext_->deviceId = json[TAG_DEVICE_ID].Get(); @@ -560,6 +575,7 @@ void AuthMessageProcessor::ParseAuthResponseMessage(JsonObject &json) void AuthMessageProcessor::ParsePkgNegotiateMessage(const JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); if (IsString(json, TAG_LOCAL_ACCOUNTID)) { authResponseContext_->localAccountId = json[TAG_LOCAL_ACCOUNTID].Get(); } @@ -610,6 +626,7 @@ void AuthMessageProcessor::ParsePkgNegotiateMessage(const JsonObject &json) void AuthMessageProcessor::ParseNegotiateMessage(const JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); if (IsBool(json, TAG_CRYPTO_SUPPORT)) { authResponseContext_->cryptoSupport = json[TAG_CRYPTO_SUPPORT].Get(); } @@ -658,6 +675,7 @@ void AuthMessageProcessor::ParseNegotiateMessage(const JsonObject &json) void AuthMessageProcessor::ParseRespNegotiateMessage(const JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); if (IsBool(json, TAG_IDENTICAL_ACCOUNT)) { authResponseContext_->isIdenticalAccount = json[TAG_IDENTICAL_ACCOUNT].Get(); } @@ -721,6 +739,7 @@ std::string AuthMessageProcessor::CreateDeviceAuthMessage(int32_t msgType, const void AuthMessageProcessor::CreateReqReCheckMessage(JsonObject &jsonObj) { + CHECK_NULL_VOID(authResponseContext_); JsonObject jsonTemp; jsonTemp[TAG_EDITION] = authResponseContext_->edition; jsonTemp[TAG_LOCAL_DEVICE_ID] = authResponseContext_->localDeviceId; @@ -741,6 +760,7 @@ void AuthMessageProcessor::CreateReqReCheckMessage(JsonObject &jsonObj) void AuthMessageProcessor::ParseReqReCheckMessage(JsonObject &json) { + CHECK_NULL_VOID(authResponseContext_); std::string encryptStr = ""; if (IsString(json, TAG_CRYPTIC_MSG)) { encryptStr = json[TAG_CRYPTIC_MSG].Get(); diff --git a/services/implementation/src/authentication/auth_request_state.cpp b/services/implementation/src/authentication/auth_request_state.cpp index ff8c4120e541ced6d6234e35ffd5bc8a5a6d2fe8..5794db23a145ea006e4848232e1e94160023b621 100644 --- a/services/implementation/src/authentication/auth_request_state.cpp +++ b/services/implementation/src/authentication/auth_request_state.cpp @@ -52,6 +52,7 @@ int32_t AuthRequestState::TransitionTo(std::shared_ptr state) return ERR_DM_FAILED; } std::shared_ptr contextTemp = GetAuthContext(); + CHECK_NULL_RETURN(state, ERR_DM_FAILED); state->SetAuthManager(stateAuthManager); stateAuthManager->SetAuthRequestState(state); state->SetAuthContext(contextTemp); @@ -72,6 +73,7 @@ int32_t AuthRequestInitState::Enter() LOGE("AuthRequestState::authManager_ null"); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context_, ERR_DM_FAILED); stateAuthManager->EstablishAuthChannel(context_->deviceId); return DM_OK; } @@ -88,6 +90,7 @@ int32_t AuthRequestNegotiateState::Enter() LOGE("AuthRequestState::authManager_ null"); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context_, ERR_DM_FAILED); stateAuthManager->StartNegotiate(context_->sessionId); return DM_OK; } @@ -104,6 +107,7 @@ int32_t AuthRequestNegotiateDoneState::Enter() LOGE("AuthRequestState::authManager_ null"); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context_, ERR_DM_FAILED); stateAuthManager->SendAuthRequest(context_->sessionId); return DM_OK; } diff --git a/services/implementation/src/authentication/auth_response_state.cpp b/services/implementation/src/authentication/auth_response_state.cpp index 38dae0cccfa8727a0caafbc580485e097e26345c..2d5517ea19fa04f27a98d1665a387ed94790a8c8 100644 --- a/services/implementation/src/authentication/auth_response_state.cpp +++ b/services/implementation/src/authentication/auth_response_state.cpp @@ -52,6 +52,7 @@ int32_t AuthResponseState::TransitionTo(std::shared_ptr state return ERR_DM_FAILED; } std::shared_ptr contextTemp = GetAuthContext(); + CHECK_NULL_RETURN(state, ERR_DM_FAILED); state->SetAuthManager(stateAuthManager); stateAuthManager->SetAuthResponseState(state); state->SetAuthContext(contextTemp); @@ -84,6 +85,7 @@ int32_t AuthResponseNegotiateState::Enter() LOGE("AuthResponseNegotiateState authManager_ is null"); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context_, ERR_DM_FAILED); stateAuthManager->RespNegotiate(context_->sessionId); return DM_OK; } diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index cba2d2c4f2073ba62d94d1c775c19be49fc987e6..cec1a6b34d2aed08c49083e6f653dced38a255f2 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -172,11 +172,13 @@ int32_t DmAuthManager::CheckAuthParamVaild(const std::string &pkgName, int32_t a int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra, const std::string &deviceId) { + CHECK_NULL_RETURN(softbusConnector_, ERR_DM_INPUT_PARA_INVALID); JsonObject jsonObject(extra); if ((jsonObject.IsDiscarded() || !IsString(jsonObject, PARAM_KEY_CONN_SESSIONTYPE) || jsonObject[PARAM_KEY_CONN_SESSIONTYPE].Get() != CONN_SESSION_TYPE_HML) && !softbusConnector_->HaveDeviceInMap(deviceId)) { LOGE("CheckAuthParamVaild failed, the discoveryDeviceInfoMap_ not have this device."); + CHECK_NULL_RETURN(listener_, ERR_DM_INPUT_PARA_INVALID); listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, "", STATUS_DM_AUTH_DEFAULT, ERR_DM_INPUT_PARA_INVALID); listener_->OnBindResult(processInfo_, peerTargetId_, ERR_DM_INPUT_PARA_INVALID, STATUS_DM_AUTH_DEFAULT, ""); @@ -226,6 +228,8 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = static_cast(localDeviceId); + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(softbusConnector_); authRequestContext_->hostPkgName = pkgName; authRequestContext_->authType = authType; authRequestContext_->localDeviceName = softbusConnector_->GetLocalDeviceName(); @@ -251,6 +255,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, void DmAuthManager::ParseJsonObject(JsonObject &jsonObject) { + CHECK_NULL_VOID(authRequestContext_); if (!jsonObject.IsDiscarded()) { if (IsString(jsonObject, TARGET_PKG_NAME_KEY)) { authRequestContext_->targetPkgName = jsonObject[TARGET_PKG_NAME_KEY].Get(); @@ -450,6 +455,7 @@ int32_t DmAuthManager::DeleteAcl(const std::string &pkgName, const std::string & ProcessInfo processInfo; processInfo.pkgName = pkgName; processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId(); + CHECK_NULL_RETURN(softbusConnector_, ERR_DM_FAILED); if (offlineParam.leftAclNumber != 0) { LOGI("The pkgName unbind app-level type leftAclNumber not zero."); softbusConnector_->SetProcessInfoVec(offlineParam.processVec); @@ -459,6 +465,7 @@ int32_t DmAuthManager::DeleteAcl(const std::string &pkgName, const std::string & if (offlineParam.leftAclNumber == 0) { LOGI("The pkgName unbind app-level type leftAclNumber is zero."); softbusConnector_->SetProcessInfoVec(offlineParam.processVec); + CHECK_NULL_RETURN(hiChainAuthConnector_, ERR_DM_FAILED); hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID(), offlineParam.peerUserId); return DM_OK; @@ -470,6 +477,7 @@ int32_t DmAuthManager::DeleteAcl(const std::string &pkgName, const std::string & } if (static_cast(bindLevel) == USER && offlineParam.leftAclNumber == 0) { LOGI("Unbind deivce-level, retain null."); + CHECK_NULL_RETURN(hiChainAuthConnector_, ERR_DM_FAILED); hiChainAuthConnector_->DeleteCredential(remoteUdid, MultipleUserConnector::GetCurrentAccountUserID(), offlineParam.peerUserId); return DM_OK; @@ -494,6 +502,7 @@ int32_t DmAuthManager::UnBindDevice(const std::string &pkgName, const std::strin void DmAuthManager::GetPeerUdidHash(int32_t sessionId, std::string &peerUdidHash) { + CHECK_NULL_VOID(softbusConnector_); std::string peerUdid = ""; int32_t ret = softbusConnector_->GetSoftbusSession()->GetPeerDeviceId(sessionId, peerUdid); if (ret != DM_OK) { @@ -558,6 +567,7 @@ void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int3 } else { if (authResponseState_ == nullptr && authRequestState_ != nullptr && authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INIT) { + CHECK_NULL_VOID(authRequestContext_); authRequestContext_->sessionId = sessionId; authResponseContext_->sessionId = sessionId; authMessageProcessor_->SetRequestContext(authRequestContext_); @@ -609,6 +619,9 @@ void DmAuthManager::PrepareSoftbusSessionCallback() void DmAuthManager::ProcessSourceMsg() { + CHECK_NULL_VOID(authMessageProcessor_); + CHECK_NULL_VOID(authRequestState_); + CHECK_NULL_VOID(authResponseContext_); authRequestContext_ = authMessageProcessor_->GetRequestContext(); authRequestState_->SetAuthContext(authRequestContext_); LOGI("OnDataReceived for source device, authResponseContext msgType = %{public}d, authRequestState stateType =" @@ -650,6 +663,8 @@ void DmAuthManager::ProcessSourceMsg() void DmAuthManager::ProcessSinkMsg() { + CHECK_NULL_VOID(authResponseState_); + CHECK_NULL_VOID(authResponseContext_); authResponseState_->SetAuthContext(authResponseContext_); LOGI("OnDataReceived for sink device, authResponseContext msgType = %{public}d, authResponseState stateType =" "%{public}d", authResponseContext_->msgType, authResponseState_->GetStateType()); @@ -755,6 +770,8 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId return; } LOGI("DmAuthManager::OnGroupCreated start group id %{public}s", GetAnonyString(groupId).c_str()); + CHECK_NULL_VOID(authMessageProcessor_); + CHECK_NULL_VOID(softbusConnector_); if (groupId == "{}") { authResponseContext_->reply = ERR_DM_CREATE_GROUP_FAILED; authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -838,6 +855,7 @@ void DmAuthManager::MemberJoinAuthRequest(int64_t requestId, int32_t status) if (timer_ != nullptr) { timer_->DeleteTimer(std::string(ADD_TIMEOUT_TASK)); } + CHECK_NULL_VOID(authResponseContext_); if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE) { HandleMemberJoinImportAuthCode(requestId, status); return; @@ -846,6 +864,7 @@ void DmAuthManager::MemberJoinAuthRequest(int64_t requestId, int32_t status) if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authResponseContext_->reply = ERR_DM_BIND_PIN_CODE_ERROR; + CHECK_NULL_VOID(authRequestContext_); authRequestContext_->reason = ERR_DM_BIND_PIN_CODE_ERROR; authRequestState_->TransitionTo(std::make_shared()); return; @@ -856,8 +875,10 @@ void DmAuthManager::MemberJoinAuthRequest(int64_t requestId, int32_t status) DmAuthManager::HandleAuthenticateTimeout(name); }); } + CHECK_NULL_VOID(authUiStateMgr_); authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_PIN_CODE_ERROR); } else { + CHECK_NULL_VOID(authRequestState_); authRequestState_->TransitionTo(std::make_shared()); if (timer_ != nullptr) { timer_->DeleteTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK)); @@ -867,9 +888,12 @@ void DmAuthManager::MemberJoinAuthRequest(int64_t requestId, int32_t status) void DmAuthManager::HandleMemberJoinImportAuthCode(const int64_t requestId, const int32_t status) { + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authRequestState_); if (status != DM_OK || authResponseContext_->requestId != requestId) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authResponseContext_->reply = ERR_DM_AUTH_CODE_INCORRECT; + CHECK_NULL_VOID(authRequestContext_); authRequestContext_->reason = ERR_DM_AUTH_CODE_INCORRECT; authRequestState_->TransitionTo(std::make_shared()); } else { @@ -885,12 +909,14 @@ void DmAuthManager::HandleAuthenticateTimeout(std::string name) authResponseContext_ = std::make_shared(); } authResponseContext_->state = authRequestState_->GetStateType(); + CHECK_NULL_VOID(authRequestContext_); authRequestContext_->reason = ERR_DM_TIME_OUT; authResponseContext_->reply = ERR_DM_TIME_OUT; authRequestState_->TransitionTo(std::make_shared()); } if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { + CHECK_NULL_VOID(authResponseContext_); authResponseContext_->state = authResponseState_->GetStateType(); authResponseContext_->reply = ERR_DM_TIME_OUT; authResponseState_->TransitionTo(std::make_shared()); @@ -957,6 +983,8 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) return; } LOGI("DmAuthManager::StartNegotiate sessionId %{public}d.", sessionId); + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(authMessageProcessor_); authResponseContext_->localDeviceId = authRequestContext_->localDeviceId; authResponseContext_->reply = ERR_DM_AUTH_REJECT; authResponseContext_->authType = authRequestContext_->authType; @@ -980,6 +1008,7 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); if (!NeedInsensibleSwitching()) { + CHECK_NULL_VOID(softbusConnector_); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); } if (timer_ != nullptr) { @@ -992,6 +1021,8 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) void DmAuthManager::AbilityNegotiate() { + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(hiChainConnector_); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); authResponseContext_->remoteAccountId = authResponseContext_->localAccountId; @@ -1031,6 +1062,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) return; } LOGI("DmAuthManager::RespNegotiate sessionid %{public}d", sessionId); + CHECK_NULL_VOID(softbusConnector_); remoteDeviceId_ = authResponseContext_->localDeviceId; authResponseContext_->networkId = softbusConnector_->GetLocalDeviceNetworkId(); authResponseContext_->targetDeviceName = softbusConnector_->GetLocalDeviceName(); @@ -1040,6 +1072,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) (static_cast(authResponseContext_->bindLevel) >= USER && static_cast(authResponseContext_->bindLevel) <= APP)) { ProcRespNegotiateExt(sessionId); + CHECK_NULL_VOID(timer_); timer_->StartTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK), GetTaskTimeout(WAIT_REQUEST_TIMEOUT_TASK, WAIT_REQUEST_TIMEOUT), [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); @@ -1047,6 +1080,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) } else if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_4_1_5_1)) || static_cast(authResponseContext_->bindLevel) == INVALIED_TYPE) { ProcRespNegotiate(sessionId); + CHECK_NULL_VOID(timer_); timer_->StartTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK), GetTaskTimeout(WAIT_REQUEST_TIMEOUT_TASK, WAIT_REQUEST_TIMEOUT), [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); @@ -1058,6 +1092,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) void DmAuthManager::NegotiateRespMsg(const std::string &version) { + CHECK_NULL_VOID(authResponseContext_); if (version == DM_VERSION_5_0_1) { authResponseContext_->dmVersion = DM_VERSION_5_0_1; } else if (version < DM_VERSION_5_0_1) { @@ -1075,9 +1110,11 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) LOGE("failed to SendAuthRequest because authResponseContext_ is nullptr"); return; } + CHECK_NULL_VOID(authRequestContext_); if (authResponseContext_->reply == ERR_DM_VERSION_INCOMPATIBLE) { LOGE("The peer device version is not supported"); authRequestContext_->reason = authResponseContext_->reply; + CHECK_NULL_VOID(authRequestState_); authRequestState_->TransitionTo(std::make_shared()); return; } @@ -1107,6 +1144,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) void DmAuthManager::ProcessAuthRequest(const int32_t &sessionId) { LOGI("ProcessAuthRequest start."); + CHECK_NULL_VOID(authResponseContext_); if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !authResponseContext_->importAuthCode.empty() && !importAuthCode_.empty()) { if (authResponseContext_->importAuthCode != Crypto::Sha256(importAuthCode_)) { @@ -1114,7 +1152,7 @@ void DmAuthManager::ProcessAuthRequest(const int32_t &sessionId) return; } } - + CHECK_NULL_VOID(softbusConnector_); if (authResponseContext_->isOnline && softbusConnector_->CheckIsOnline(remoteDeviceId_)) { authResponseContext_->isOnline = true; } else { @@ -1124,15 +1162,17 @@ void DmAuthManager::ProcessAuthRequest(const int32_t &sessionId) LOGI("CheckTrustState end."); return; } - + CHECK_NULL_VOID(authMessageProcessor_); std::vector messageList = authMessageProcessor_->CreateAuthRequestMessage(); for (auto msg : messageList) { softbusConnector_->GetSoftbusSession()->SendData(sessionId, msg); } - + CHECK_NULL_VOID(listener_); + CHECK_NULL_VOID(authRequestContext_); listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, STATUS_DM_SHOW_AUTHORIZE_UI, DM_OK); listener_->OnBindResult(processInfo_, peerTargetId_, DM_OK, STATUS_DM_SHOW_AUTHORIZE_UI, ""); + CHECK_NULL_VOID(timer_); timer_->StartTimer(std::string(CONFIRM_TIMEOUT_TASK), GetTaskTimeout(CONFIRM_TIMEOUT_TASK, CONFIRM_TIMEOUT), [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); @@ -1141,6 +1181,9 @@ void DmAuthManager::ProcessAuthRequest(const int32_t &sessionId) void DmAuthManager::GetAuthRequestContext() { + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(softbusConnector_); char deviceIdHash[DM_MAX_DEVICE_ID_LEN] = {0}; Crypto::GetUdidHash(authResponseContext_->localDeviceId, reinterpret_cast(deviceIdHash)); authRequestContext_->deviceId = static_cast(deviceIdHash); @@ -1161,6 +1204,7 @@ void DmAuthManager::GetAuthRequestContext() void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) { LOGI("ProcessAuthRequestExt start."); + CHECK_NULL_VOID(authResponseContext_); if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_3)) && authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && !authResponseContext_->importAuthCode.empty() && !importAuthCode_.empty()) { @@ -1202,7 +1246,11 @@ void DmAuthManager::ProcessAuthRequestExt(const int32_t &sessionId) bool DmAuthManager::IsAuthFinish() { + CHECK_NULL_RETURN(authResponseContext_, false); if (authResponseContext_->reply == ERR_DM_UNSUPPORTED_AUTH_TYPE) { + CHECK_NULL_RETURN(listener_, false); + CHECK_NULL_RETURN(authRequestContext_, false); + CHECK_NULL_RETURN(authRequestState_, false); listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, AuthState::AUTH_REQUEST_NEGOTIATE_DONE, ERR_DM_UNSUPPORTED_AUTH_TYPE); authRequestState_->TransitionTo(std::make_shared()); @@ -1211,10 +1259,12 @@ bool DmAuthManager::IsAuthFinish() if ((authResponseContext_->isIdenticalAccount && !authResponseContext_->authed) || (authResponseContext_->authed && !authResponseContext_->isOnline)) { + CHECK_NULL_RETURN(authRequestContext_, false); JoinLnn(authRequestContext_->addr); authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authResponseContext_->reply = DM_OK; + CHECK_NULL_RETURN(authRequestState_, false); authRequestState_->TransitionTo(std::make_shared()); return true; } @@ -1222,6 +1272,7 @@ bool DmAuthManager::IsAuthFinish() if (authResponseContext_->reply == ERR_DM_UNSUPPORTED_AUTH_TYPE || (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE && authResponseContext_->isAuthCodeReady == false)) { + CHECK_NULL_RETURN(authRequestState_, false); authRequestState_->TransitionTo(std::make_shared()); return true; } @@ -1232,6 +1283,7 @@ int32_t DmAuthManager::ConfirmProcess(const int32_t &action) { LOGI("ConfirmProcess start."); CHECK_NULL_RETURN(authResponseContext_, ERR_DM_POINT_NULL); + CHECK_NULL_RETURN(authResponseState_, ERR_DM_POINT_NULL); authResponseContext_->confirmOperation = action; if (action_ == USER_OPERATION_TYPE_ALLOW_AUTH || action_ == USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS) { authResponseContext_->reply = USER_OPERATION_TYPE_ALLOW_AUTH; @@ -1243,8 +1295,10 @@ int32_t DmAuthManager::ConfirmProcess(const int32_t &action) authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_CONFIRM) { authResponseState_->TransitionTo(std::make_shared()); } else { + CHECK_NULL_RETURN(authMessageProcessor_, ERR_DM_POINT_NULL); authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH); + CHECK_NULL_RETURN(softbusConnector_, ERR_DM_POINT_NULL); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } return DM_OK; @@ -1253,13 +1307,16 @@ int32_t DmAuthManager::ConfirmProcess(const int32_t &action) int32_t DmAuthManager::ConfirmProcessExt(const int32_t &action) { LOGI("ConfirmProcessExt start."); + CHECK_NULL_RETURN(authResponseContext_, ERR_DM_POINT_NULL); authResponseContext_->confirmOperation = action; if (action_ == USER_OPERATION_TYPE_ALLOW_AUTH || action_ == USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS) { authResponseContext_->reply = USER_OPERATION_TYPE_ALLOW_AUTH; } else { authResponseContext_->reply = USER_OPERATION_TYPE_CANCEL_AUTH; } + CHECK_NULL_RETURN(authMessageProcessor_, ERR_DM_POINT_NULL); authMessageProcessor_->SetResponseContext(authResponseContext_); + CHECK_NULL_RETURN(authResponseState_, ERR_DM_POINT_NULL); if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH && authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_CONFIRM) { if (CanUsePincodeFromDp()) { @@ -1275,6 +1332,7 @@ int32_t DmAuthManager::ConfirmProcessExt(const int32_t &action) } authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH_EXT); + CHECK_NULL_RETURN(softbusConnector_, ERR_DM_POINT_NULL); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); return DM_OK; } @@ -1326,6 +1384,8 @@ void DmAuthManager::StartRespAuthProcess() } else if (authResponseContext_->groupName[CHECK_AUTH_ALWAYS_POS] == AUTH_ONCE) { action_ = USER_OPERATION_TYPE_ALLOW_AUTH; } + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(authRequestState_); 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) { @@ -1335,6 +1395,7 @@ void DmAuthManager::StartRespAuthProcess() GetTaskTimeout(SESSION_HEARTBEAT_TIMEOUT_TASK, SESSION_HEARTBEAT_TIMEOUT), [this] (std::string name) { DmAuthManager::HandleSessionHeartbeat(name); }); + CHECK_NULL_VOID(listener_); listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, STATUS_DM_SHOW_PIN_INPUT_UI, DM_OK); listener_->OnBindResult(processInfo_, peerTargetId_, DM_OK, STATUS_DM_SHOW_PIN_INPUT_UI, ""); @@ -1355,6 +1416,7 @@ int32_t DmAuthManager::CreateGroup() return ERR_DM_FAILED; } LOGI("DmAuthManager::CreateGroup start"); + CHECK_NULL_RETURN(hiChainConnector_, ERR_DM_FAILED); authResponseContext_->groupName = GenerateGroupName(); authResponseContext_->requestId = GenRandLongLong(MIN_REQUEST_ID, MAX_REQUEST_ID); hiChainConnector_->CreateGroup(authResponseContext_->requestId, authResponseContext_->groupName); @@ -1384,8 +1446,8 @@ int32_t DmAuthManager::AddMember(const std::string &pinCode) DmAuthManager::HandleAuthenticateTimeout(name); }); } - if (authUiStateMgr_ == nullptr) { - LOGE("DmAuthManager::AddMember authUiStateMgr is null."); + if (authUiStateMgr_ == nullptr || hiChainConnector_ == nullptr || authRequestContext_ == nullptr) { + LOGE("DmAuthManager::AddMember authUiStateMgr_ or hiChainConnector_ or authRequestContext_ is null."); return ERR_DM_FAILED; } if (isAddingMember_) { @@ -1415,6 +1477,7 @@ int32_t DmAuthManager::AddMember(const std::string &pinCode) std::string DmAuthManager::GetConnectAddr(std::string deviceId) { + CHECK_NULL_RETURN(softbusConnector_, ""); std::string connectAddr; if (softbusConnector_->GetConnectAddr(deviceId, connectAddr) == nullptr) { LOGE("DmAuthManager::GetConnectAddr error"); @@ -1432,6 +1495,8 @@ int32_t DmAuthManager::JoinNetwork() if (timer_ != nullptr) { timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); } + CHECK_NULL_RETURN(authRequestContext_, ERR_DM_FAILED); + CHECK_NULL_RETURN(authRequestState_, ERR_DM_FAILED); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authResponseContext_->isFinish = true; authRequestContext_->reason = DM_OK; @@ -1473,21 +1538,27 @@ int32_t DmAuthManager::GetOutputState(int32_t state) void DmAuthManager::SrcAuthenticateFinish() { LOGI("DmAuthManager::SrcAuthenticateFinish, isFinishOfLocal: %{public}d", isFinishOfLocal_); + CHECK_NULL_VOID(authResponseContext_); if (isFinishOfLocal_) { + CHECK_NULL_VOID(authMessageProcessor_); authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE); + CHECK_NULL_VOID(softbusConnector_); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } else { + CHECK_NULL_VOID(authRequestContext_); authRequestContext_->reason = authResponseContext_->reply; } if ((authResponseContext_->state == AuthState::AUTH_REQUEST_JOIN || authResponseContext_->state == AuthState::AUTH_REQUEST_FINISH) && (authResponseContext_->authType == AUTH_TYPE_NFC || authPtr_ != nullptr)) { + CHECK_NULL_VOID(authUiStateMgr_); authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); } if (timer_ == nullptr) { timer_ = std::make_shared(); } + CHECK_NULL_VOID(authRequestContext_); int32_t closeSessionDelaySeconds = authRequestContext_->closeSessionDelaySeconds; if (IsHmlSessionType() && closeSessionDelaySeconds == 0 && isWaitingJoinLnnCallback_) { closeSessionDelaySeconds = SESSION_CLOSE_TIMEOUT; @@ -1503,6 +1574,7 @@ void DmAuthManager::SrcAuthenticateFinish() } }); int32_t status = GetOutputState(authResponseContext_->state); + CHECK_NULL_VOID(listener_); listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, status, authRequestContext_->reason); listener_->OnBindResult(processInfo_, peerTargetId_, authRequestContext_->reason, status, @@ -1536,6 +1608,7 @@ void DmAuthManager::AuthenticateFinish() isAuthenticateDevice_ = false; isAuthDevice_ = false; isNeedJoinLnn_ = true; + CHECK_NULL_VOID(softbusConnector_); if (DeviceProfileConnector::GetInstance().GetTrustNumber(remoteDeviceId_) >= 1 && CompareVersion(remoteVersion_, std::string(DM_VERSION_4_1_5_1)) && softbusConnector_->CheckIsOnline(remoteDeviceId_) && authResponseContext_->isFinish) { @@ -1912,6 +1985,7 @@ int32_t DmAuthManager::AuthDevice(const std::string &pinCode) LOGI("DmAuthManager::AuthDevice start."); if (isAuthDevice_) { LOGE("DmAuthManager::AuthDevice doing auth device."); + CHECK_NULL_RETURN(authUiStateMgr_, ERR_DM_FAILED); authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_DOING_AUTH); return ERR_DM_FAILED; } @@ -1924,6 +1998,8 @@ int32_t DmAuthManager::AuthDevice(const std::string &pinCode) DmAuthManager::HandleAuthenticateTimeout(name); }); } + CHECK_NULL_RETURN(hiChainAuthConnector_, ERR_DM_FAILED); + CHECK_NULL_RETURN(authResponseContext_, ERR_DM_FAILED); if (hiChainAuthConnector_->AuthDevice(pinCode, osAccountId, remoteDeviceId_, authResponseContext_->requestId) != DM_OK) { LOGE("DmAuthManager::AuthDevice failed."); @@ -2006,6 +2082,7 @@ int32_t DmAuthManager::SetReasonAndFinish(int32_t reason, int32_t state) authResponseContext_->state = state; authResponseContext_->reply = reason; if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { + CHECK_NULL_RETURN(authRequestContext_, ERR_DM_AUTH_NOT_START); authRequestContext_->reason = reason; authRequestState_->TransitionTo(std::make_shared()); } else if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { @@ -2025,6 +2102,7 @@ bool DmAuthManager::IsIdenticalAccount() LOGE("get current process account user id failed"); return false; } + CHECK_NULL_RETURN(hiChainConnector_, false); std::vector groupList; if (!hiChainConnector_->GetGroupInfo(osAccountUserId, queryParams, groupList)) { return false; @@ -2066,6 +2144,7 @@ std::string DmAuthManager::GetAccountGroupIdHash() LOGE("get current process account user id failed"); return ""; } + CHECK_NULL_RETURN(hiChainConnector_, ""); std::vector groupList; if (!hiChainConnector_->GetGroupInfo(osAccountUserId, queryParams, groupList)) { return ""; @@ -2177,6 +2256,7 @@ int32_t DmAuthManager::ParseConnectAddr(const PeerTargetId &targetId, std::strin } deviceInfo->addrNum = static_cast(index); + CHECK_NULL_RETURN(softbusConnector_, ERR_DM_INPUT_PARA_INVALID); if (softbusConnector_->AddMemberToDiscoverMap(deviceId, deviceInfo) != DM_OK) { LOGE("DmAuthManager::ParseConnectAddr failed, AddMemberToDiscoverMap failed."); return ERR_DM_INPUT_PARA_INVALID; @@ -2231,6 +2311,7 @@ int32_t DmAuthManager::GetAuthCode(const std::string &pkgName, std::string &pinC bool DmAuthManager::IsImportedAuthCodeValid() { std::string pinCode = ""; + CHECK_NULL_RETURN(authRequestContext_, false); if (GetAuthCode(authRequestContext_->hostPkgName, pinCode) == DM_OK) { return true; } @@ -2257,6 +2338,7 @@ bool DmAuthManager::IsAuthTypeSupported(const int32_t &authType) std::string DmAuthManager::GenerateBindResultContent() { + CHECK_NULL_RETURN(authResponseContext_, ""); JsonObject jsonObj; jsonObj[DM_BIND_RESULT_NETWORK_ID] = authResponseContext_->networkId; if (remoteDeviceId_.empty()) { @@ -2276,6 +2358,9 @@ void DmAuthManager::RequestCredential() LOGI("DmAuthManager::RequestCredential start."); std::string publicKey = ""; GenerateCredential(publicKey); + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authMessageProcessor_); + CHECK_NULL_VOID(softbusConnector_); authResponseContext_->publicKey = publicKey; std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_PUBLICKEY); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); @@ -2288,6 +2373,7 @@ void DmAuthManager::GenerateCredential(std::string &publicKey) GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = localDeviceId; int32_t osAccountId = MultipleUserConnector::GetCurrentAccountUserID(); + CHECK_NULL_VOID(hiChainAuthConnector_); hiChainAuthConnector_->GetCredential(localUdid, osAccountId, publicKey); if (publicKey == "") { hiChainAuthConnector_->GenerateCredential(localUdid, osAccountId, publicKey); @@ -2305,6 +2391,9 @@ void DmAuthManager::RequestCredentialDone() if (timer_ != nullptr) { timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); } + CHECK_NULL_VOID(softbusConnector_); + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(authRequestState_); if (softbusConnector_->CheckIsOnline(remoteDeviceId_) && !authResponseContext_->isOnline) { JoinLnn(authRequestContext_->addr, true); } else { @@ -2348,7 +2437,9 @@ void DmAuthManager::ResponseCredential() LOGE("authResponseContext_->publicKey is empty."); authResponseContext_->isFinish = false; isFinishOfLocal_ = false; + CHECK_NULL_VOID(authMessageProcessor_); authMessageProcessor_->SetEncryptFlag(false); + CHECK_NULL_VOID(authResponseState_); authResponseContext_->state = authResponseState_->GetStateType(); authResponseState_->TransitionTo(std::make_shared()); return; @@ -2357,11 +2448,14 @@ void DmAuthManager::ResponseCredential() GenerateCredential(publicKey); if (ImportCredential(remoteDeviceId_, authResponseContext_->publicKey) != DM_OK) { LOGE("ResponseCredential import credential failed."); + CHECK_NULL_VOID(authResponseState_); authResponseContext_->state = authResponseState_->GetStateType(); authResponseState_->TransitionTo(std::make_shared()); return; } authResponseContext_->publicKey = publicKey; + CHECK_NULL_VOID(authMessageProcessor_); + CHECK_NULL_VOID(softbusConnector_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_PUBLICKEY); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } @@ -2382,6 +2476,7 @@ bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, u LOGI("SoftbusSession send msgType %{public}d.", MSG_TYPE_RESP_AUTH_DEVICE_NEGOTIATE); message = authMessageProcessor_->CreateDeviceAuthMessage(MSG_TYPE_RESP_AUTH_DEVICE_NEGOTIATE, data, dataLen); } + CHECK_NULL_RETURN(softbusConnector_, false); if (softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message) != DM_OK) { LOGE("SoftbusSession send data failed."); return false; @@ -2425,6 +2520,7 @@ void DmAuthManager::SrcAuthDeviceFinish() } if (!authResponseContext_->isOnline && authResponseContext_->haveCredential) { JoinLnn(authRequestContext_->addr); + CHECK_NULL_VOID(timer_); timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); ConverToFinish(); return; @@ -2445,7 +2541,9 @@ void DmAuthManager::SinkAuthDeviceFinish() LOGI("isNeedProcCachedSrcReqMsg %{public}d.", isNeedProcCachedSrcReqMsg_); CHECK_NULL_VOID(authResponseState_); authResponseState_->TransitionTo(std::make_shared()); + CHECK_NULL_VOID(authResponseContext_); if (!authResponseContext_->haveCredential) { + CHECK_NULL_VOID(authUiStateMgr_); authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_SHOW); } if (authResponseContext_->isOnline) { @@ -2466,11 +2564,13 @@ void DmAuthManager::SinkAuthDeviceFinish() LOGI("please wait client request."); return; } + CHECK_NULL_VOID(authMessageProcessor_); authMessageProcessor_->SetResponseContext(authResponseContext_); if (authMessageProcessor_->ParseMessage(srcReqMsg) != DM_OK) { LOGE("ParseMessage failed."); return; } + CHECK_NULL_VOID(authResponseState_); if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { authResponseState_->TransitionTo(std::make_shared()); } else { @@ -2481,6 +2581,7 @@ void DmAuthManager::SinkAuthDeviceFinish() void DmAuthManager::AuthDeviceFinish(int64_t requestId) { LOGI("DmAuthManager::AuthDeviceFinish start."); + CHECK_NULL_VOID(authResponseContext_); if (requestId != authResponseContext_->requestId) { LOGE("DmAuthManager::onTransmit requestId %{public}" PRId64 "is error.", requestId); return; @@ -2557,6 +2658,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) void DmAuthManager::AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) { LOGI("DmAuthManager::AuthDeviceSessionKey start. keyLen: %{public}u", sessionKeyLen); + CHECK_NULL_VOID(authResponseContext_); if (requestId != authResponseContext_->requestId) { LOGE("DmAuthManager::onTransmit requestId %{public}" PRId64 "is error.", requestId); return; @@ -2675,7 +2777,8 @@ void DmAuthManager::CompatiblePutAcl() DmAccesser accesser; DmAccessee accessee; - if (authRequestState_ != nullptr && authResponseState_ == nullptr) { + if (authRequestState_ != nullptr && authResponseState_ == nullptr && authResponseContext_ != nullptr && + authRequestContext_ != nullptr) { accesser.requestBundleName = authResponseContext_->hostPkgName; accesser.requestDeviceId = localUdid; accesser.requestUserId = MultipleUserConnector::GetCurrentAccountUserID(); @@ -2685,7 +2788,7 @@ void DmAuthManager::CompatiblePutAcl() accessee.trustDeviceId = remoteDeviceId_; accessee.trustUserId = -1; } - if (authRequestState_ == nullptr && authResponseState_ != nullptr) { + if (authRequestState_ == nullptr && authResponseState_ != nullptr && authResponseContext_ != nullptr) { accesser.requestBundleName = authResponseContext_->hostPkgName; accesser.requestDeviceId = remoteDeviceId_; accesser.requestUserId = authResponseContext_->remoteUserId; @@ -2703,6 +2806,7 @@ void DmAuthManager::CompatiblePutAcl() void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) { LOGI("DmAuthManager::ProcRespNegotiateExt start."); + CHECK_NULL_VOID(authResponseContext_); remoteDeviceId_ = authResponseContext_->localDeviceId; authResponseContext_->remoteAccountId = authResponseContext_->localAccountId; authResponseContext_->remoteUserId = authResponseContext_->localUserId; @@ -2722,7 +2826,9 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) authResponseContext_->isIdenticalAccount = true; } + CHECK_NULL_VOID(softbusConnector_); authResponseContext_->isOnline = softbusConnector_->CheckIsOnline(remoteDeviceId_); + CHECK_NULL_VOID(hiChainAuthConnector_); authResponseContext_->haveCredential = hiChainAuthConnector_->QueryCredential(authResponseContext_->deviceId, MultipleUserConnector::GetFirstForegroundUserId(), authResponseContext_->remoteUserId); @@ -2737,6 +2843,7 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) } else { authResponseContext_->isAuthCodeReady = false; } + CHECK_NULL_VOID(authMessageProcessor_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); @@ -2749,6 +2856,8 @@ void DmAuthManager::ProcRespNegotiate(const int32_t &sessionId) { LOGI("DmAuthManager::ProcRespNegotiate session id"); AbilityNegotiate(); + CHECK_NULL_VOID(softbusConnector_); + CHECK_NULL_VOID(authMessageProcessor_); authResponseContext_->isOnline = softbusConnector_->CheckIsOnline(remoteDeviceId_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); JsonObject jsonObject(message); @@ -2762,6 +2871,7 @@ void DmAuthManager::ProcRespNegotiate(const int32_t &sessionId) return; } jsonObject[TAG_ACCOUNT_GROUPID] = GetAccountGroupIdHash(); + CHECK_NULL_VOID(authResponseState_); authResponseContext_ = authResponseState_->GetAuthContext(); if (jsonObject[TAG_CRYPTO_SUPPORT].Get() == true && authResponseContext_->cryptoSupport) { if (IsString(jsonObject, TAG_CRYPTO_NAME) && IsString(jsonObject, TAG_CRYPTO_VERSION)) { @@ -2786,6 +2896,7 @@ void DmAuthManager::ProcIncompatible(const int32_t &sessionId) respNegotiateMsg[TAG_VER] = DM_ITF_VER; respNegotiateMsg[TAG_MSG_TYPE] = MSG_TYPE_RESP_NEGOTIATE; std::string message = respNegotiateMsg.Dump(); + CHECK_NULL_VOID(softbusConnector_); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); } @@ -2838,6 +2949,7 @@ int32_t DmAuthManager::DeleteGroup(const std::string &pkgName, int32_t userId, c return ERR_DM_FAILED; } std::vector groupList; + CHECK_NULL_RETURN(hiChainConnector_, ERR_DM_FAILED); hiChainConnector_->GetRelatedGroups(userId, deviceId, groupList); if (groupList.size() > 0) { std::string groupId = ""; @@ -2863,6 +2975,7 @@ void DmAuthManager::PutAccessControlList() std::string localUdidHash = static_cast(mUdidHash); DmAclInfo aclInfo; aclInfo.bindType = DM_ACROSS_ACCOUNT; + CHECK_NULL_VOID(authResponseContext_); if (authResponseContext_->localAccountId == "ohosAnonymousUid" || authResponseContext_->remoteAccountId == "ohosAnonymousUid") { aclInfo.bindType = DM_POINT_TO_POINT; @@ -2890,11 +3003,13 @@ void DmAuthManager::PutAccessControlList() void DmAuthManager::PutSrcAccessControlList(DmAccesser &accesser, DmAccessee &accessee, const std::string &localUdid) { + CHECK_NULL_VOID(authRequestContext_); accesser.requestTokenId = static_cast(authRequestContext_->tokenId); accesser.requestUserId = authRequestContext_->localUserId; accesser.requestAccountId = authRequestContext_->localAccountId; accesser.requestDeviceId = authRequestContext_->localDeviceId; accesser.requestDeviceName = authRequestContext_->localDeviceName; + CHECK_NULL_VOID(authResponseContext_); if (authResponseContext_->remoteTokenId == authRequestContext_->tokenId) { accessee.trustTokenId = 0; } else { @@ -2909,6 +3024,7 @@ void DmAuthManager::PutSrcAccessControlList(DmAccesser &accesser, DmAccessee &ac void DmAuthManager::PutSinkAccessControlList(DmAccesser &accesser, DmAccessee &accessee, const std::string &localUdid) { + CHECK_NULL_VOID(authResponseContext_); accesser.requestTokenId = static_cast(authResponseContext_->remoteTokenId); accesser.requestUserId = authResponseContext_->remoteUserId; accesser.requestAccountId = authResponseContext_->remoteAccountId; @@ -2934,8 +3050,11 @@ void DmAuthManager::HandleSessionHeartbeat(std::string name) JsonObject jsonObj; jsonObj[TAG_SESSION_HEARTBEAT] = TAG_SESSION_HEARTBEAT; std::string message = jsonObj.Dump(); + CHECK_NULL_VOID(softbusConnector_); + CHECK_NULL_VOID(authResponseContext_); softbusConnector_->GetSoftbusSession()->SendHeartbeatData(authResponseContext_->sessionId, message); + CHECK_NULL_VOID(authRequestState_); if (authRequestState_ != nullptr) { if (timer_ != nullptr) { timer_->StartTimer(std::string(SESSION_HEARTBEAT_TIMEOUT_TASK), @@ -2950,6 +3069,9 @@ void DmAuthManager::HandleSessionHeartbeat(std::string name) int32_t DmAuthManager::CheckTrustState() { bool isSameGroup = false; + CHECK_NULL_RETURN(authResponseContext_, ERR_DM_FAILED); + CHECK_NULL_RETURN(hiChainConnector_, ERR_DM_FAILED); + CHECK_NULL_RETURN(authRequestContext_, ERR_DM_FAILED); if (authResponseContext_->reply == ERR_DM_AUTH_PEER_REJECT && hiChainConnector_->IsDevicesInP2PGroup(authResponseContext_->localDeviceId, authRequestContext_->localDeviceId)) { @@ -2966,6 +3088,7 @@ int32_t DmAuthManager::CheckTrustState() authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; authResponseContext_->reply = DM_OK; + CHECK_NULL_RETURN(authRequestState_, ERR_DM_FAILED); authRequestState_->TransitionTo(std::make_shared()); return ALREADY_BIND; } @@ -2977,6 +3100,7 @@ int32_t DmAuthManager::CheckTrustState() } JoinLnn(authResponseContext_->deviceId); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; + CHECK_NULL_RETURN(authRequestState_, ERR_DM_FAILED); authRequestState_->TransitionTo(std::make_shared()); return ALREADY_BIND; } @@ -2985,6 +3109,7 @@ int32_t DmAuthManager::CheckTrustState() authResponseContext_->isAuthCodeReady == false)) { authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = ERR_DM_BIND_PEER_UNSUPPORTED; + CHECK_NULL_RETURN(authRequestState_, ERR_DM_FAILED); authRequestState_->TransitionTo(std::make_shared()); return ERR_DM_BIND_PEER_UNSUPPORTED; } @@ -3111,7 +3236,7 @@ void DmAuthManager::SetProcessInfo() CHECK_NULL_VOID(authResponseContext_); ProcessInfo processInfo; if (static_cast(authResponseContext_->bindLevel) == APP) { - if ((authRequestState_ != nullptr) && (authResponseState_ == nullptr)) { + if ((authRequestState_ != nullptr) && (authResponseState_ == nullptr) && authRequestContext_ != nullptr) { processInfo.pkgName = authResponseContext_->hostPkgName; processInfo.userId = authRequestContext_->localUserId; } else if ((authRequestState_ == nullptr) && (authResponseState_ != nullptr)) { @@ -3128,11 +3253,15 @@ void DmAuthManager::SetProcessInfo() LOGE("bindlevel error %{public}d.", authResponseContext_->bindLevel); return; } + CHECK_NULL_VOID(softbusConnector_); softbusConnector_->SetProcessInfo(processInfo); } void DmAuthManager::ConverToFinish() { + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authRequestState_); authRequestContext_->reason = DM_OK; authResponseContext_->reply = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; @@ -3148,6 +3277,9 @@ void DmAuthManager::RequestReCheckMsg() int32_t localUserId = 0; MultipleUserConnector::GetTokenIdAndForegroundUserId(tokenId, localUserId); std::string localAccountId = MultipleUserConnector::GetOhosAccountIdByUserId(localUserId); + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(authMessageProcessor_); authResponseContext_->edition = DM_VERSION_5_0_5; authResponseContext_->localDeviceId = static_cast(localDeviceId); authResponseContext_->localUserId = localUserId; @@ -3157,11 +3289,14 @@ void DmAuthManager::RequestReCheckMsg() authResponseContext_->tokenId = authRequestContext_->tokenId; authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_RECHECK_MSG); + CHECK_NULL_VOID(softbusConnector_); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } void DmAuthManager::ResponseReCheckMsg() { + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authMessageProcessor_); LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", remoteVersion_.c_str(), authResponseContext_->edition.c_str()); if (!IsSinkMsgValid()) { @@ -3170,6 +3305,7 @@ void DmAuthManager::ResponseReCheckMsg() isFinishOfLocal_ = false; authMessageProcessor_->SetEncryptFlag(false); int32_t sessionId = authResponseContext_->sessionId; + CHECK_NULL_VOID(authResponseState_); authResponseContext_->state = authResponseState_->GetStateType(); authResponseState_->TransitionTo(std::make_shared()); return; @@ -3192,18 +3328,22 @@ void DmAuthManager::ResponseReCheckMsg() authResponseContext_->bundleName = authResponseContext_->peerBundleName; authMessageProcessor_->SetEncryptFlag(true); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_RECHECK_MSG); + CHECK_NULL_VOID(softbusConnector_); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); PutAccessControlList(); } void DmAuthManager::RequestReCheckMsgDone() { + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authRequestState_); LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", remoteVersion_.c_str(), authResponseContext_->edition.c_str()); if (!IsSourceMsgValid()) { LOGE("peer deviceId not trust."); authResponseContext_->isFinish = false; isFinishOfLocal_ = false; + CHECK_NULL_VOID(authMessageProcessor_); authMessageProcessor_->SetEncryptFlag(false); authRequestState_->TransitionTo(std::make_shared()); return; @@ -3234,6 +3374,8 @@ bool DmAuthManager::IsSinkMsgValid() bool DmAuthManager::IsSourceMsgValid() { + CHECK_NULL_RETURN(authResponseContext_, false); + CHECK_NULL_RETURN(authRequestContext_, false); if (authResponseContext_->edition != remoteVersion_ || authResponseContext_->localDeviceId != remoteDeviceId_ || authResponseContext_->localUserId != authRequestContext_->remoteUserId || @@ -3253,6 +3395,7 @@ int32_t DmAuthManager::RegisterAuthenticationType(int32_t authenticationType) void DmAuthManager::ProcessReqPublicKey() { + CHECK_NULL_VOID(authResponseState_); if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { authResponseState_->TransitionTo(std::make_shared()); @@ -3266,6 +3409,7 @@ void DmAuthManager::ProcessReqPublicKey() void DmAuthManager::GetLocalServiceInfoInDp() { + CHECK_NULL_VOID(authResponseContext_); DistributedDeviceProfile::LocalServiceInfo localServiceInfo; int32_t result = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( authResponseContext_->hostPkgName, (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP, localServiceInfo); @@ -3345,7 +3489,6 @@ void DmAuthManager::CloseAuthSession(const int32_t sessionId) std::to_string(sessionId)); } CHECK_NULL_VOID(softbusConnector_); - CHECK_NULL_VOID(softbusConnector_->GetSoftbusSession()); softbusConnector_->GetSoftbusSession()->CloseAuthSession(sessionId); } 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 10f7cacfdc9f28d6f35763b035d602ec1648b557..e8e00e4b498d7746f3e16cda7b7e1da77e182035 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -97,12 +97,14 @@ int32_t AuthSinkDataSyncState::Action(std::shared_ptr context) return ret; } // Query the ACL of the sink end. Compare the ACLs at both ends. + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_POINT_NULL); context->softbusConnector->SyncLocalAclListProcess({context->accessee.deviceId, context->accessee.userId}, {context->accesser.deviceId, context->accesser.userId}, context->accesser.aclStrList); if (GetSessionKey(context)) { DerivativeSessionKey(context); } // Synchronize the local SP information, the format is uncertain, not done for now + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_RESP_DATA_SYNC, context); context->accessee.deviceName = context->softbusConnector->GetLocalDeviceName(); LOGI("AuthSinkDataSyncState::Action ok"); @@ -125,6 +127,7 @@ int32_t AuthSinkDataSyncState::DerivativeSessionKey(std::shared_ptraccesser.deviceIdHash + context->accessee.deviceIdHash + context->accesser.tokenIdHash + context->accessee.tokenIdHash; + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); int32_t ret = context->authMessageProcessor->SaveDerivativeSessionKeyToDP(context->accessee.userId, suffix, skId); if (ret != DM_OK) { @@ -141,6 +144,7 @@ int32_t AuthSinkDataSyncState::DerivativeSessionKey(std::shared_ptraccesser.deviceIdHash + context->accessee.deviceIdHash + app.proxyAccesser.tokenIdHash + app.proxyAccessee.tokenIdHash; + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); int32_t ret = context->authMessageProcessor->SaveDerivativeSessionKeyToDP(context->accessee.userId, suffix, skId); if (ret != DM_OK) { @@ -162,6 +166,9 @@ int32_t AuthSinkDataSyncState::DerivativeSessionKey(std::shared_ptr context) { LOGI("AuthSrcDataSyncState::Action start"); + CHECK_NULL_RETURN(context, ERR_DM_FAILED); + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_FAILED); + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_FAILED); if (NeedAgreeAcl(context)) { // Query the ACL of the sink end. Compare the ACLs at both ends. context->softbusConnector->SyncLocalAclListProcess({context->accesser.deviceId, context->accesser.userId}, @@ -199,6 +206,7 @@ int32_t AuthSinkFinishState::Action(std::shared_ptr context) { LOGI("AuthSinkFinishState::Action start"); int32_t ret = DM_OK; + CHECK_NULL_RETURN(context, ERR_DM_POINT_NULL); LOGI("reason: %{public}d", context->reason); if (context->reason == DM_OK) { context->state = static_cast(GetStateType()); @@ -231,7 +239,9 @@ DmAuthStateType AuthSinkFinishState::GetStateType() int32_t AuthSrcFinishState::Action(std::shared_ptr context) { LOGI("AuthSrcFinishState::Action start"); + CHECK_NULL_RETURN(context, ERR_DM_POINT_NULL); if (context->reason == ERR_DM_SKIP_AUTHENTICATE && !context->isNeedAuthenticate) { + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); 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) { @@ -247,6 +257,7 @@ int32_t AuthSrcFinishState::Action(std::shared_ptr context) context->confirmOperation = UiAction::USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS; } SourceFinish(context); + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_POINT_NULL); bool isNeedJoinLnn = context->softbusConnector->CheckIsNeedJoinLnn(peerDeviceId, context->accessee.addr); // Trigger networking if (context->reason == DM_BIND_TRUST_TARGET && (!context->accesser.isOnline || isNeedJoinLnn)) { 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 88bf18015ee535e83407dff1c79165598defce9a..2f5ed451264cb0b2f24c84c3037d128604b6783a 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp @@ -499,6 +499,7 @@ bool AuthSrcConfirmState::IdenticalAccountAclCompare(std::shared_ptraccesser.deviceId && accesser.GetAccesserUserId() == context->accesser.userId && Crypto::GetUdidHash(accessee.GetAccesseeDeviceId()) == context->accessee.deviceIdHash; @@ -508,6 +509,7 @@ bool AuthSrcConfirmState::ShareAclCompare(std::shared_ptr context const DistributedDeviceProfile::Accesser &accesser, const DistributedDeviceProfile::Accessee &accessee) { LOGI("start."); + CHECK_NULL_RETURN(context, false); return accesser.GetAccesserDeviceId() == context->accesser.deviceId && accesser.GetAccesserUserId() == context->accesser.userId && Crypto::GetUdidHash(accessee.GetAccesseeDeviceId()) == context->accessee.deviceIdHash; @@ -517,6 +519,7 @@ bool AuthSrcConfirmState::Point2PointAclCompare(std::shared_ptr c const DistributedDeviceProfile::Accesser &accesser, const DistributedDeviceProfile::Accessee &accessee) { LOGI("start."); + CHECK_NULL_RETURN(context, false); return (accesser.GetAccesserDeviceId() == context->accesser.deviceId && accesser.GetAccesserUserId() == context->accesser.userId && accesser.GetAccesserTokenId() == context->accesser.tokenId && @@ -533,6 +536,7 @@ bool AuthSrcConfirmState::LnnAclCompare(std::shared_ptr context, const DistributedDeviceProfile::Accesser &accesser, const DistributedDeviceProfile::Accessee &accessee) { LOGI("start."); + CHECK_NULL_RETURN(context, false); return ((accesser.GetAccesserDeviceId() == context->accesser.deviceId && accesser.GetAccesserUserId() == context->accesser.userId) || (accessee.GetAccesseeDeviceId() == context->accesser.deviceId && @@ -771,6 +775,7 @@ int32_t AuthSinkConfirmState::ShowConfigDialog(std::shared_ptr co { LOGI("AuthSinkConfirmState::ShowConfigDialog start"); + CHECK_NULL_RETURN(context, STOP_BIND); if (context->authType == AUTH_TYPE_PIN_ULTRASONIC && context->ultrasonicInfo == DmUltrasonicInfo::DM_Ultrasonic_Invalid) { LOGE("AuthSinkConfirmState::ShowConfigDialog ultrasonicInfo invalid."); @@ -793,6 +798,7 @@ int32_t AuthSinkConfirmState::ShowConfigDialog(std::shared_ptr co } else if (IsScreenLocked()) { LOGE("AuthSinkConfirmState::ShowStartAuthDialog screen is locked."); context->reason = ERR_DM_BIND_USER_CANCEL; + CHECK_NULL_RETURN(context->authStateMachine, STOP_BIND); context->authStateMachine->NotifyEventFinish(DmEventType::ON_FAIL); return STOP_BIND; } @@ -1003,6 +1009,7 @@ void AuthSinkConfirmState::NegotiateProxyAcl(std::shared_ptr cont void AuthSinkConfirmState::MatchFallBackCandidateList( std::shared_ptr context, DmAuthType authType) { + CHECK_NULL_VOID(context); for (size_t i = 0; i < MAX_FALLBACK_LOOPKUP_TIMES; i++) { auto it = g_pinAuthTypeFallBackMap.find({context->accessee.bundleName, authType}); if (it != g_pinAuthTypeFallBackMap.end()) { @@ -1016,6 +1023,7 @@ void AuthSinkConfirmState::MatchFallBackCandidateList( void AuthSinkConfirmState::ReadServiceInfo(std::shared_ptr context) { + CHECK_NULL_VOID(context); // query ServiceInfo by accessee.pkgName and authType from client OHOS::DistributedDeviceProfile::LocalServiceInfo srvInfo; auto ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( @@ -1111,7 +1119,9 @@ int32_t AuthSinkConfirmState::ProcessBindAuthorize(std::shared_ptrauthType == DmAuthType::AUTH_TYPE_PIN_ULTRASONIC) && (context->serviceInfoFound || AuthSinkStatePinAuthComm::IsAuthCodeReady(context)) && context->authBoxType == DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_POINT_NULL); context->authStateMachine->TransitionTo(std::make_shared()); + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_RESP_USER_CONFIRM, context); return DM_OK; } @@ -1127,12 +1137,14 @@ int32_t AuthSinkConfirmState::ProcessBindAuthorize(std::shared_ptr context) { CHECK_NULL_RETURN(context, ERR_DM_POINT_NULL); + CHECK_NULL_RETURN(context->timer, ERR_DM_POINT_NULL); context->timer->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); if (ShowConfigDialog(context) != DM_OK) { LOGE("ShowConfigDialog failed"); context->reason = ERR_DM_SHOW_CONFIRM_FAILED; return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_POINT_NULL); if (DmEventType::ON_USER_OPERATION != context->authStateMachine->WaitExpectEvent(DmEventType::ON_USER_OPERATION)) { LOGE("AuthSinkConfirmState::Action ON_USER_OPERATION err"); @@ -1148,7 +1160,9 @@ int32_t AuthSinkConfirmState::ProcessUserAuthorize(std::shared_ptrreason = ERR_DM_AUTH_PEER_REJECT; return ERR_DM_FAILED; } + context->authStateMachine->TransitionTo(std::make_shared()); + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_RESP_USER_CONFIRM, context); return DM_OK; } @@ -1278,7 +1292,10 @@ int32_t AuthSinkConfirmState::ProcessNoBindAuthorize(std::shared_ptrreason = ERR_DM_CAPABILITY_NEGOTIATE_FAILED; return ERR_DM_FAILED; } + + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_POINT_NULL); context->authStateMachine->TransitionTo(std::make_shared()); + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_RESP_USER_CONFIRM, context); return DM_OK; } diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp index 6f294d97f1659181e23e55dbc12558550a47dae3..b5d182855c1b463da2bf50c034d04f99dd9945cd 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_credential.cpp @@ -44,17 +44,20 @@ const int32_t GENERATE_CERT_TIMEOUT = 100; // 100ms // decrypt process int32_t g_authCredentialTransmitDecryptProcess(std::shared_ptr context, DmEventType event) { + CHECK_NULL_RETURN(context, ERR_DM_FAILED); if (context->transmitData.empty()) { LOGE("DmAuthMessageProcessor::CreateMessageReqCredAuthStart failed, get onTransmitData failed."); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context->hiChainAuthConnector, ERR_DM_FAILED); int32_t ret = context->hiChainAuthConnector->ProcessCredData(context->requestId, context->transmitData); if (ret != DM_OK) { LOGE("AuthCredentialTransmitDecryptProcess: ProcessCredData transmit data failed"); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_FAILED); if (context->authStateMachine->WaitExpectEvent(event) != event) { LOGE("AuthCredentialTransmitDecryptProcess: Hichain auth transmit data failed"); return ERR_DM_FAILED; @@ -64,11 +67,13 @@ int32_t g_authCredentialTransmitDecryptProcess(std::shared_ptr co int32_t AuthCredentialTransmitSend(std::shared_ptr context, DmMessageType msgType) { + CHECK_NULL_RETURN(context, ERR_DM_FAILED); if (context->transmitData.empty()) { LOGE("AuthCredentialTransmitSend: Get onTransmitData failed."); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_FAILED); std::string message = context->authMessageProcessor->CreateMessage(msgType, context); if (message.empty()) { @@ -76,6 +81,7 @@ int32_t AuthCredentialTransmitSend(std::shared_ptr context, DmMes return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_FAILED); return context->softbusConnector->GetSoftbusSession()->SendData(context->sessionId, message); } @@ -129,6 +135,7 @@ int32_t AuthSrcCredentialAuthDoneState::Action(std::shared_ptr co return ret; } // Authentication completion triggers the Onfinish callback event. + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_POINT_NULL); if (context->authStateMachine->WaitExpectEvent(ON_FINISH) != ON_FINISH) { LOGE("AuthSrcCredentialAuthDoneState::Action Hichain auth SINK transmit data failed"); return ERR_DM_FAILED; @@ -148,6 +155,7 @@ int32_t AuthSrcCredentialAuthDoneState::HandleSrcCredentialAuthDone(std::shared_ context->isAppCredentialVerified = true; DerivativeSessionKey(context); msgType = MSG_TYPE_REQ_CREDENTIAL_AUTH_START; + CHECK_NULL_RETURN(context->hiChainAuthConnector, ERR_DM_POINT_NULL); ret = context->hiChainAuthConnector->AuthCredential(context->accesser.userId, context->requestId, context->accesser.lnnCredentialId, std::string("")); if (ret != DM_OK) { @@ -155,6 +163,7 @@ int32_t AuthSrcCredentialAuthDoneState::HandleSrcCredentialAuthDone(std::shared_ return ret; } // wait for onTransmit event + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_POINT_NULL); if (context->authStateMachine->WaitExpectEvent(ON_TRANSMIT) != ON_TRANSMIT) { LOGE("AuthSrcCredentialAuthDoneState::Action failed, ON_TRANSMIT event not arrived."); return ERR_DM_FAILED; @@ -193,6 +202,7 @@ int32_t AuthSrcCredentialAuthDoneState::SendCredentialAuthMessage(std::shared_pt LOGE("AuthSrcCredentialAuthDoneState::Action CreateMessage failed"); return ERR_DM_FAILED; } + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_POINT_NULL); return context->softbusConnector->GetSoftbusSession()->SendData(context->sessionId, message); } @@ -201,6 +211,7 @@ int32_t AuthSrcCredentialAuthDoneState::DerivativeSessionKey(std::shared_ptrIsProxyBind || context->subjectProxyOnes.empty()) { int32_t skId = 0; + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); int32_t ret = context->authMessageProcessor->SaveSessionKeyToDP(context->accesser.userId, skId); if (ret != DM_OK) { LOGE("AuthSrcCredentialAuthDoneState::Action DP save user session key failed"); @@ -221,6 +232,7 @@ int32_t AuthSrcCredentialAuthDoneState::DerivativeProxySessionKey(std::shared_pt if (context->IsCallingProxyAsSubject && !context->accesser.isAuthed) { int32_t skId = 0; int32_t ret = 0; + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); if (!context->reUseCreId.empty()) { std::string suffix = context->accesser.deviceIdHash + context->accessee.deviceIdHash + context->accesser.tokenIdHash + context->accessee.tokenIdHash; @@ -242,6 +254,7 @@ int32_t AuthSrcCredentialAuthDoneState::DerivativeProxySessionKey(std::shared_pt int32_t skId = 0; std::string suffix = context->accesser.deviceIdHash + context->accessee.deviceIdHash + app.proxyAccesser.tokenIdHash + app.proxyAccessee.tokenIdHash; + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); int32_t ret = context->authMessageProcessor->SaveDerivativeSessionKeyToDP(context->accesser.userId, suffix, skId); if (ret != DM_OK) { @@ -266,6 +279,8 @@ DmAuthStateType AuthSinkCredentialAuthStartState::GetStateType() int32_t AuthSinkCredentialAuthStartState::Action(std::shared_ptr context) { + CHECK_NULL_RETURN(context, ERR_DM_POINT_NULL); + CHECK_NULL_RETURN(context->timer, ERR_DM_POINT_NULL); context->timer->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); int32_t ret = g_authCredentialTransmitDecryptProcess(context, ON_TRANSMIT); @@ -309,6 +324,7 @@ int32_t AuthSinkCredentialAuthNegotiateState::Action(std::shared_ptraccessee.isGenerateLnnCredential == true && context->accessee.bindLevel != static_cast(USER) && context->isAppCredentialVerified == true) { + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_FAILED); ret = context->authMessageProcessor->SaveSessionKeyToDP(context->accessee.userId, skId); if (ret != DM_OK) { LOGE("AuthSinkCredentialAuthNegotiateState::Action DP save user session key failed"); @@ -320,6 +336,7 @@ int32_t AuthSinkCredentialAuthNegotiateState::Action(std::shared_ptrisAppCredentialVerified = true; if (!context->IsProxyBind || context->subjectProxyOnes.empty() || (context->IsCallingProxyAsSubject && !context->accessee.isAuthed)) { + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_FAILED); ret = context->authMessageProcessor->SaveSessionKeyToDP(context->accessee.userId, skId); if (ret != DM_OK) { LOGE("DP save user session key failed %{public}d", ret); @@ -346,6 +363,7 @@ int32_t AuthSinkCredentialAuthNegotiateState::DerivativeSessionKey(std::shared_p int32_t skId = 0; std::string suffix = context->accesser.deviceIdHash + context->accessee.deviceIdHash + app.proxyAccesser.tokenIdHash + app.proxyAccessee.tokenIdHash; + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_POINT_NULL); int32_t ret = context->authMessageProcessor->SaveDerivativeSessionKeyToDP(context->accessee.userId, suffix, skId); if (ret != DM_OK) { @@ -380,6 +398,7 @@ std::string AuthCredentialAgreeState::CreateAuthParamsString(DmAuthScope authori jsonObj[TAG_METHOD] = method; } + CHECK_NULL_RETURN(authContext, ""); jsonObj[TAG_LOWER_DEVICE_ID] = (method == DM_AUTH_CREDENTIAL_ADD_METHOD_GENERATE) ? authContext->GetDeviceId(DM_AUTH_LOCAL_SIDE) : authContext->GetDeviceId(DM_AUTH_REMOTE_SIDE); if (method == DM_AUTH_CREDENTIAL_ADD_METHOD_IMPORT) { @@ -502,6 +521,9 @@ int32_t AuthCredentialAgreeState::AgreeCredential(DmAuthScope authorizedScope, std::string credId; LOGI("AuthCredentialAgreeState::AgreeCredential agree with accountId %{public}d and param %{public}s.", osAccountId, GetAnonyJsonString(authParamsString).c_str()); + if (authContext->hiChainAuthConnector == nullptr) { + return ERR_DM_FAILED; + } int32_t ret = authContext->hiChainAuthConnector->AgreeCredential(osAccountId, selfCredId, authParamsString, credId); if (ret != DM_OK) { @@ -522,18 +544,22 @@ DmAuthStateType AuthSrcCredentialExchangeState::GetStateType() int32_t AuthSrcCredentialExchangeState::Action(std::shared_ptr context) { LOGI("AuthSrcCredentialExchangeState::Action() start."); + CHECK_NULL_RETURN(context, ERR_DM_FAILED); int32_t ret = ERR_DM_FAILED; context->isAppCredentialVerified = false; if (!NeedAgreeAcl(context)) { + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_FAILED); context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } if (GetSessionKey(context)) { + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_FAILED); context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } if (!IsNeedAgreeCredential(context)) { + CHECK_NULL_RETURN(context->authStateMachine, ERR_DM_FAILED); context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } @@ -561,8 +587,10 @@ int32_t AuthSrcCredentialExchangeState::Action(std::shared_ptr co return ret; } + CHECK_NULL_RETURN(context->authMessageProcessor, ERR_DM_FAILED); std::string message = context->authMessageProcessor->CreateMessage(MSG_TYPE_REQ_CREDENTIAL_EXCHANGE, context); LOGI("AuthSrcCredentialExchangeState::Action() leave."); + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_FAILED); return context->softbusConnector->GetSoftbusSession()->SendData(context->sessionId, message); } @@ -576,12 +604,12 @@ int32_t AuthSinkCredentialExchangeState::Action(std::shared_ptr c LOGI("AuthSinkCredentialExchangeState::Action start."); int32_t ret = ERR_DM_FAILED; std::string tmpCredId; - int32_t osAccountId = context->accessee.userId; - context->isAppCredentialVerified = false; - if (context == nullptr || context->hiChainAuthConnector == nullptr || - context->authMessageProcessor == nullptr || context->softbusConnector == nullptr) { + if (context == nullptr || context->hiChainAuthConnector == nullptr || context->authMessageProcessor == nullptr || + context->softbusConnector == nullptr || context->softbusConnector->GetSoftbusSession() == nullptr) { return ret; } + int32_t osAccountId = context->accessee.userId; + context->isAppCredentialVerified = false; // First authentication lnn cred if (context->accessee.isGenerateLnnCredential && context->accessee.bindLevel != static_cast(USER)) { @@ -686,11 +714,12 @@ int32_t AuthSrcCredentialAuthStartState::Action(std::shared_ptr c { LOGI("AuthSrcCredentialAuthStartState::Action start."); int32_t ret = ERR_DM_FAILED; - int32_t osAccountId = context->accesser.userId; - if (context == nullptr || context->hiChainAuthConnector == nullptr || - context->authMessageProcessor == nullptr || context->softbusConnector == nullptr) { + if (context == nullptr || context->hiChainAuthConnector == nullptr || context->authMessageProcessor == nullptr || + context->softbusConnector == nullptr || context->softbusConnector->GetSoftbusSession() == nullptr || + context->authStateMachine == nullptr) { return ret; } + int32_t osAccountId = context->accesser.userId; if (IsNeedAgreeCredential(context)) { ret = AgreeAndDeleteCredential(context); if (ret != DM_OK) { @@ -752,6 +781,7 @@ int32_t AuthSrcSKDeriveState::Action(std::shared_ptr context) // send 180 std::string message = context->authMessageProcessor->CreateMessage(MSG_TYPE_REQ_DATA_SYNC, context); LOGI("AuthSrcSKDeriveState::Action() leave."); + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_POINT_NULL); return context->softbusConnector->GetSoftbusSession()->SendData(context->sessionId, message); } @@ -871,6 +901,7 @@ int32_t AuthSinkSKDeriveState::Action(std::shared_ptr context) // send 151 std::string message = context->authMessageProcessor->CreateMessage(MSG_TYPE_RESP_SK_DERIVE, context); LOGI("AuthSinkSKDeriveState::Action() leave."); + CHECK_NULL_RETURN(context->softbusConnector, ERR_DM_POINT_NULL); return context->softbusConnector->GetSoftbusSession()->SendData(context->sessionId, message); } diff --git a/test/commonunittest/UTTest_dm_auth_manager_second.cpp b/test/commonunittest/UTTest_dm_auth_manager_second.cpp index 46e18cbc86d9926abaa6b498e136ebc619988f38..a57779ccf488a267e311142fa29cfedf1640b3ba 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_second.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_second.cpp @@ -516,7 +516,7 @@ HWTEST_F(DmAuthManagerTest, ConfirmProcessExt_003, testing::ext::TestSize.Level1 ASSERT_EQ(ret, DM_OK); } -HWTEST_F(DmAuthManagerTest, ConfirmProcessExt_004, testing::ext::TestSize.Level0) +HWTEST_F(DmAuthManagerTest, ConfirmProcessExt_004, testing::ext::TestSize.Level1) { DistributedDeviceProfile::LocalServiceInfo info; info.SetAuthBoxType((int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM);