From 8f40e48624d208c133c996fba052dd206ad88b30 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 12:45:18 +0800 Subject: [PATCH 01/16] debug Signed-off-by: zhuzhihui7 Change-Id: I559f034240fd571fab320108c836cd7d3a1bae5d --- .../include/authentication/dm_auth_manager.h | 3 + .../src/authentication/dm_auth_manager.cpp | 85 ++++++++++++++----- 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index d0ac1fc8a..7d6604fe9 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -517,6 +517,7 @@ public: int32_t DeleteGroup(const std::string &pkgName, int32_t userId, const std::string &deviceId); int32_t StopAuthenticateDevice(const std::string &pkgName); void RequestReCheckMsg(); + bool SinkHandleReCheckMsg(); void ResponseReCheckMsg(); void RequestReCheckMsgDone(); private: @@ -554,6 +555,7 @@ private: void ConverToFinish(); bool IsSinkMsgValid(); bool IsSourceMsgValid(); + bool RemoteSupportRecheck(); private: std::shared_ptr softbusConnector_; @@ -592,6 +594,7 @@ private: std::mutex srcReqMsgLock_; bool isNeedProcCachedSrcReqMsg_ = false; std::string srcReqMsg_ = ""; + bool recheckSourceSuccess_ = false; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9a9271708..7f53a7f7e 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -613,16 +613,37 @@ void DmAuthManager::ProcessSinkMsg() case MSG_TYPE_REQ_PUBLICKEY: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { - authResponseState_->TransitionTo(std::make_shared()); + if (RemoteSupportRecheck()) { + LOGI("[temp003] MSG_TYPE_REQ_PUBLICKEY, RemoteSupportRecheck"); + if (recheckSourceSuccess_) { + LOGI("[temp003] recheckSourceSuccess_"); + authResponseState_->TransitionTo(std::make_shared()); + } else { + LOGI("[temp003] !recheckSourceSuccess_"); + } + } else { + LOGI("[temp003] MSG_TYPE_REQ_PUBLICKEY, !RemoteSupportRecheck"); + authResponseState_->TransitionTo(std::make_shared()); + } } + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { std::lock_guard lock(srcReqMsgLock_); isNeedProcCachedSrcReqMsg_ = true; } break; case MSG_TYPE_REQ_RECHECK_MSG: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH) { - authResponseState_->TransitionTo(std::make_shared()); + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || + authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { + bool ret = SinkHandleReCheckMsg(); + if (!ret) { + LOGI("[temp003] SinkHandleReCheckMsg failed"); + } else { + LOGI("[temp003] SinkHandleReCheckMsg success"); + authResponseState_->TransitionTo(std::make_shared()); + LOGI("[temp003] PutAccessControlList"); + PutAccessControlList(); + } } if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { std::lock_guard lock(srcReqMsgLock_); @@ -2135,7 +2156,7 @@ void DmAuthManager::SrcAuthDeviceFinish() void DmAuthManager::SinkAuthDeviceFinish() { - LOGI("isNeedProcCachedSrcReqMsg %{public}d.", isNeedProcCachedSrcReqMsg_); + LOGI("isNeedProcCachedSrcReqMsg %{public}d. srcReqMsg_ %{public}d", isNeedProcCachedSrcReqMsg_, srcReqMsg_.empty()); CHECK_NULL_VOID(authResponseState_); authResponseState_->TransitionTo(std::make_shared()); if (!authResponseContext_->haveCredential) { @@ -2155,19 +2176,22 @@ void DmAuthManager::SinkAuthDeviceFinish() srcReqMsg_ = ""; isNeedProcCachedSrcReqMsg_ = false; } - if (!isNeedProcCachedSrcReqMsg || srcReqMsg.empty()) { - LOGI("please wait client request."); - return; - } - authMessageProcessor_->SetResponseContext(authResponseContext_); - if (authMessageProcessor_->ParseMessage(srcReqMsg) != DM_OK) { - LOGE("ParseMessage failed."); - return; - } - if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - authResponseState_->TransitionTo(std::make_shared()); + if (isNeedProcCachedSrcReqMsg && !srcReqMsg.empty()) { + authMessageProcessor_->SetResponseContext(authResponseContext_); + if (authMessageProcessor_->ParseMessage(srcReqMsg) != DM_OK) { + LOGE("ParseMessage failed."); + return; + } + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + authResponseState_->TransitionTo(std::make_shared()); + } else { + authResponseState_->TransitionTo(std::make_shared()); + } } else { - authResponseState_->TransitionTo(std::make_shared()); + if (RemoteSupportRecheck()) { + LOGE("[temp003] SinkAuthDeviceFinish AuthResponseReCheckMsg"); + authResponseState_->TransitionTo(std::make_shared()); + } } } @@ -2839,10 +2863,18 @@ void DmAuthManager::RequestReCheckMsg() softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } -void DmAuthManager::ResponseReCheckMsg() +bool DmAuthManager::RemoteSupportRecheck() { - LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", - remoteVersion_.c_str(), authResponseContext_->edition.c_str()); + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + return false; + } else { + return true; + } +} + +bool DmAuthManager::SinkHandleReCheckMsg() +{ + LOGI("[temp003] SinkHandleReCheckMsg"); if (!IsSinkMsgValid()) { LOGE("peer deviceId not trust."); authResponseContext_->isFinish = false; @@ -2850,10 +2882,19 @@ void DmAuthManager::ResponseReCheckMsg() authMessageProcessor_->SetEncryptFlag(false); int32_t sessionId = authResponseContext_->sessionId; authResponseState_->TransitionTo(std::make_shared()); - CHECK_NULL_VOID(softbusConnector_->GetSoftbusSession()); + CHECK_NULL_RETURN(softbusConnector_->GetSoftbusSession(), false); softbusConnector_->GetSoftbusSession()->CloseAuthSession(sessionId); - return; + return false; + } else { + recheckSourceSuccess_ = true; + return true; } +} + +void DmAuthManager::ResponseReCheckMsg() +{ + LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", + remoteVersion_.c_str(), authResponseContext_->edition.c_str()); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); authResponseContext_->edition = DM_VERSION_5_0_3; @@ -2869,7 +2910,7 @@ void DmAuthManager::ResponseReCheckMsg() authMessageProcessor_->SetEncryptFlag(true); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_RECHECK_MSG); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); - PutAccessControlList(); + //PutAccessControlList(); } void DmAuthManager::RequestReCheckMsgDone() -- Gitee From 993c68102ce1ace7a6fedac7a99afcd207055996 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 14:53:53 +0800 Subject: [PATCH 02/16] src change Change-Id: I736bde4942ed6990ceeda9d6c04da4fe500e0cdf --- .../include/authentication/dm_auth_manager.h | 1 + .../src/authentication/dm_auth_manager.cpp | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 7d6604fe9..777c15945 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -595,6 +595,7 @@ private: bool isNeedProcCachedSrcReqMsg_ = false; std::string srcReqMsg_ = ""; bool recheckSourceSuccess_ = false; + bool recheckSinkSuccess_ = false; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 7f53a7f7e..40eb7a46f 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -572,8 +572,11 @@ void DmAuthManager::ProcessSourceMsg() } break; case MSG_TYPE_RESP_RECHECK_MSG: - if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH || + authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { authRequestState_->TransitionTo(std::make_shared()); + } else { + LOGI("[temp003] skip MSG_TYPE_RESP_RECHECK_MSG"); } break; default: @@ -620,6 +623,7 @@ void DmAuthManager::ProcessSinkMsg() authResponseState_->TransitionTo(std::make_shared()); } else { LOGI("[temp003] !recheckSourceSuccess_"); + //close auth session? } } else { LOGI("[temp003] MSG_TYPE_REQ_PUBLICKEY, !RemoteSupportRecheck"); @@ -637,7 +641,8 @@ void DmAuthManager::ProcessSinkMsg() authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { bool ret = SinkHandleReCheckMsg(); if (!ret) { - LOGI("[temp003] SinkHandleReCheckMsg failed"); + LOGI("[temp003] SinkHandleReCheckMsg failed, authsession closed"); + return; } else { LOGI("[temp003] SinkHandleReCheckMsg success"); authResponseState_->TransitionTo(std::make_shared()); @@ -2917,7 +2922,7 @@ void DmAuthManager::RequestReCheckMsgDone() { LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", remoteVersion_.c_str(), authResponseContext_->edition.c_str()); - if (!IsSourceMsgValid()) { + if (!recheckSinkSuccess_ && !IsSourceMsgValid()) { LOGE("peer deviceId not trust."); authResponseContext_->isFinish = false; isFinishOfLocal_ = false; @@ -2925,8 +2930,14 @@ void DmAuthManager::RequestReCheckMsgDone() authRequestState_->TransitionTo(std::make_shared()); return; } - PutAccessControlList(); - authRequestState_->TransitionTo(std::make_shared()); + if (!recheckSinkSuccess_) { + LOGI("[temp003] RequestReCheckMsgDone recheckSinkSuccess_ = true"); + recheckSinkSuccess_ = true; + PutAccessControlList(); + + LOGI("[temp003] RequestReCheckMsgDone enter AuthRequestCredential"); + authRequestState_->TransitionTo(std::make_shared()); + } } bool DmAuthManager::IsSinkMsgValid() -- Gitee From c3b7f7d26fc15f51e2ca1265ba31474b2aa5472e Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 15:51:06 +0800 Subject: [PATCH 03/16] src change Change-Id: I59f0d8c02b0af023916abf5b94ec70f0fe00a9f4 --- .../include/authentication/dm_auth_manager.h | 2 +- .../src/authentication/dm_auth_manager.cpp | 77 +++++++------------ 2 files changed, 30 insertions(+), 49 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 777c15945..1ab446aeb 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -517,7 +517,7 @@ public: int32_t DeleteGroup(const std::string &pkgName, int32_t userId, const std::string &deviceId); int32_t StopAuthenticateDevice(const std::string &pkgName); void RequestReCheckMsg(); - bool SinkHandleReCheckMsg(); + void SendResponseReCheckMsg(); void ResponseReCheckMsg(); void RequestReCheckMsgDone(); private: diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 40eb7a46f..ddc755344 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -344,6 +344,8 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au LOGE("CheckAuthParamVaildExtra failed, param is invaild."); return ret; } + recheckSinkSuccess_ = false; + recheckSourceSuccess_ = false; isAuthenticateDevice_ = true; if (authType == AUTH_TYPE_CRE) { LOGI("DmAuthManager::AuthenticateDevice for credential type, joinLNN directly."); @@ -616,19 +618,7 @@ void DmAuthManager::ProcessSinkMsg() case MSG_TYPE_REQ_PUBLICKEY: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { - if (RemoteSupportRecheck()) { - LOGI("[temp003] MSG_TYPE_REQ_PUBLICKEY, RemoteSupportRecheck"); - if (recheckSourceSuccess_) { - LOGI("[temp003] recheckSourceSuccess_"); - authResponseState_->TransitionTo(std::make_shared()); - } else { - LOGI("[temp003] !recheckSourceSuccess_"); - //close auth session? - } - } else { - LOGI("[temp003] MSG_TYPE_REQ_PUBLICKEY, !RemoteSupportRecheck"); - authResponseState_->TransitionTo(std::make_shared()); - } + authResponseState_->TransitionTo(std::make_shared()); } if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { @@ -639,16 +629,7 @@ void DmAuthManager::ProcessSinkMsg() case MSG_TYPE_REQ_RECHECK_MSG: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { - bool ret = SinkHandleReCheckMsg(); - if (!ret) { - LOGI("[temp003] SinkHandleReCheckMsg failed, authsession closed"); - return; - } else { - LOGI("[temp003] SinkHandleReCheckMsg success"); - authResponseState_->TransitionTo(std::make_shared()); - LOGI("[temp003] PutAccessControlList"); - PutAccessControlList(); - } + authResponseState_->TransitionTo(std::make_shared()); } if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { std::lock_guard lock(srcReqMsgLock_); @@ -2194,8 +2175,8 @@ void DmAuthManager::SinkAuthDeviceFinish() } } else { if (RemoteSupportRecheck()) { - LOGE("[temp003] SinkAuthDeviceFinish AuthResponseReCheckMsg"); - authResponseState_->TransitionTo(std::make_shared()); + LOGE("[temp003] SinkAuthDeviceFinish SendResponseReCheckMsg"); + SendResponseReCheckMsg(); } } } @@ -2877,29 +2858,8 @@ bool DmAuthManager::RemoteSupportRecheck() } } -bool DmAuthManager::SinkHandleReCheckMsg() -{ - LOGI("[temp003] SinkHandleReCheckMsg"); - if (!IsSinkMsgValid()) { - LOGE("peer deviceId not trust."); - authResponseContext_->isFinish = false; - isFinishOfLocal_ = false; - authMessageProcessor_->SetEncryptFlag(false); - int32_t sessionId = authResponseContext_->sessionId; - authResponseState_->TransitionTo(std::make_shared()); - CHECK_NULL_RETURN(softbusConnector_->GetSoftbusSession(), false); - softbusConnector_->GetSoftbusSession()->CloseAuthSession(sessionId); - return false; - } else { - recheckSourceSuccess_ = true; - return true; - } -} - -void DmAuthManager::ResponseReCheckMsg() +void DmAuthManager::SendResponseReCheckMsg() { - LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", - remoteVersion_.c_str(), authResponseContext_->edition.c_str()); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); authResponseContext_->edition = DM_VERSION_5_0_3; @@ -2915,7 +2875,26 @@ void DmAuthManager::ResponseReCheckMsg() authMessageProcessor_->SetEncryptFlag(true); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_RECHECK_MSG); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); - //PutAccessControlList(); +} + +void DmAuthManager::ResponseReCheckMsg() +{ + LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", + remoteVersion_.c_str(), authResponseContext_->edition.c_str()); + if (!IsSinkMsgValid()) { + LOGE("peer deviceId not trust."); + authResponseContext_->isFinish = false; + isFinishOfLocal_ = false; + authMessageProcessor_->SetEncryptFlag(false); + int32_t sessionId = authResponseContext_->sessionId; + authResponseState_->TransitionTo(std::make_shared()); + CHECK_NULL_VOID(softbusConnector_->GetSoftbusSession()); + softbusConnector_->GetSoftbusSession()->CloseAuthSession(sessionId); + return; + } + SendResponseReCheckMsg(); + + PutAccessControlList(); } void DmAuthManager::RequestReCheckMsgDone() @@ -2930,6 +2909,8 @@ void DmAuthManager::RequestReCheckMsgDone() authRequestState_->TransitionTo(std::make_shared()); return; } + LOGI("[temp003] RequestReCheckMsgDone recheckSinkSuccess_ = %{public}d", recheckSinkSuccess_); + if (!recheckSinkSuccess_) { LOGI("[temp003] RequestReCheckMsgDone recheckSinkSuccess_ = true"); recheckSinkSuccess_ = true; -- Gitee From e8b2646a0c1631bf93d9c63d5a8c6ed1aaaf0ceb Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 15:56:51 +0800 Subject: [PATCH 04/16] src change Change-Id: I009f49855a15d91c1173cd8a44e9a0755660c6ba --- .../src/authentication/dm_auth_manager.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ddc755344..553dd1b87 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -620,7 +620,6 @@ void DmAuthManager::ProcessSinkMsg() authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { authResponseState_->TransitionTo(std::make_shared()); } - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { std::lock_guard lock(srcReqMsgLock_); isNeedProcCachedSrcReqMsg_ = true; @@ -2828,6 +2827,15 @@ void DmAuthManager::ConverToFinish() authRequestState_->TransitionTo(std::make_shared()); } +bool DmAuthManager::RemoteSupportRecheck() +{ + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + return false; + } else { + return true; + } +} + void DmAuthManager::RequestReCheckMsg() { LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); @@ -2849,15 +2857,6 @@ void DmAuthManager::RequestReCheckMsg() softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } -bool DmAuthManager::RemoteSupportRecheck() -{ - if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - return false; - } else { - return true; - } -} - void DmAuthManager::SendResponseReCheckMsg() { char localDeviceId[DEVICE_UUID_LENGTH] = {0}; @@ -2912,7 +2911,6 @@ void DmAuthManager::RequestReCheckMsgDone() LOGI("[temp003] RequestReCheckMsgDone recheckSinkSuccess_ = %{public}d", recheckSinkSuccess_); if (!recheckSinkSuccess_) { - LOGI("[temp003] RequestReCheckMsgDone recheckSinkSuccess_ = true"); recheckSinkSuccess_ = true; PutAccessControlList(); -- Gitee From ae50db38dd21f70eaedb65fc92647d2284f54987 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 15:59:59 +0800 Subject: [PATCH 05/16] src change Change-Id: I56c7c03a33813d483932f92688a7015bc3051237 --- services/implementation/src/authentication/dm_auth_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 553dd1b87..2a40ccdf5 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -626,8 +626,7 @@ void DmAuthManager::ProcessSinkMsg() } break; case MSG_TYPE_REQ_RECHECK_MSG: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || - authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH) { authResponseState_->TransitionTo(std::make_shared()); } if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { -- Gitee From 4d5af01d1c93e2818aab87e29f98d8367d0dbe15 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 16:26:08 +0800 Subject: [PATCH 06/16] src change Change-Id: I8902d262805111a1437626b29ba8051b015c6254 --- .../src/authentication/dm_auth_manager.cpp | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 2a40ccdf5..c820ab689 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2090,6 +2090,7 @@ bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, u void DmAuthManager::SrcAuthDeviceFinish() { + LOGI("[temp003] SrcAuthDeviceFinish"); CHECK_NULL_VOID(authRequestState_); authRequestState_->TransitionTo(std::make_shared()); if (authResponseContext_->confirmOperation != USER_OPERATION_TYPE_ALLOW_AUTH && @@ -2114,10 +2115,18 @@ void DmAuthManager::SrcAuthDeviceFinish() SetProcessInfo(); } softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); - if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - authRequestState_->TransitionTo(std::make_shared()); + if (recheckSinkSuccess_) { + LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); + auto sendMsg = std::make_shared(); + sendMsg->Enter(); } else { - authRequestState_->TransitionTo(std::make_shared()); + if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); + authRequestState_->TransitionTo(std::make_shared()); + } else { + LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestCredential"); + authRequestState_->TransitionTo(std::make_shared()); + } } return; } @@ -2129,10 +2138,18 @@ void DmAuthManager::SrcAuthDeviceFinish() } if (!authResponseContext_->isOnline && !authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); - if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - authRequestState_->TransitionTo(std::make_shared()); + if (recheckSinkSuccess_) { + LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); + auto sendMsg = std::make_shared(); + sendMsg->Enter(); } else { - authRequestState_->TransitionTo(std::make_shared()); + if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); + authRequestState_->TransitionTo(std::make_shared()); + } else { + LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestCredential"); + authRequestState_->TransitionTo(std::make_shared()); + } } return; } -- Gitee From 464aaea1054f9067b75ea0148ea6d89bb2dc9732 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 16:34:01 +0800 Subject: [PATCH 07/16] src change Change-Id: I0f9d61244490d5a5163c77bf444fd2be07735ad3 --- .../implementation/src/authentication/dm_auth_manager.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index c820ab689..1deab5815 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2117,8 +2117,7 @@ void DmAuthManager::SrcAuthDeviceFinish() softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); if (recheckSinkSuccess_) { LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); - auto sendMsg = std::make_shared(); - sendMsg->Enter(); + RequestReCheckMsg(); } else { if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); @@ -2140,8 +2139,7 @@ void DmAuthManager::SrcAuthDeviceFinish() authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); if (recheckSinkSuccess_) { LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); - auto sendMsg = std::make_shared(); - sendMsg->Enter(); + RequestReCheckMsg(); } else { if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); -- Gitee From 400660b4f2d14bd1ae28357a7eb82524707ff20a Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 16:41:21 +0800 Subject: [PATCH 08/16] src change Change-Id: I67a11e5211641abedd289bbff7cff65193c100da --- .../implementation/include/authentication/dm_auth_manager.h | 1 + .../implementation/src/authentication/dm_auth_manager.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 1ab446aeb..1e03c3dec 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -596,6 +596,7 @@ private: std::string srcReqMsg_ = ""; bool recheckSourceSuccess_ = false; bool recheckSinkSuccess_ = false; + std::mutex recheckMutex_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 1deab5815..e4d3c8e39 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -574,12 +574,14 @@ void DmAuthManager::ProcessSourceMsg() } break; case MSG_TYPE_RESP_RECHECK_MSG: + recheckMutex_.lock(); if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH || authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { authRequestState_->TransitionTo(std::make_shared()); } else { LOGI("[temp003] skip MSG_TYPE_RESP_RECHECK_MSG"); } + recheckMutex_.unlock(); break; default: break; @@ -2115,6 +2117,7 @@ void DmAuthManager::SrcAuthDeviceFinish() SetProcessInfo(); } softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); + recheckMutex_.lock(); if (recheckSinkSuccess_) { LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); RequestReCheckMsg(); @@ -2127,6 +2130,7 @@ void DmAuthManager::SrcAuthDeviceFinish() authRequestState_->TransitionTo(std::make_shared()); } } + recheckMutex_.unlock(); return; } if (!authResponseContext_->isOnline && authResponseContext_->haveCredential) { @@ -2137,6 +2141,7 @@ void DmAuthManager::SrcAuthDeviceFinish() } if (!authResponseContext_->isOnline && !authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); + recheckMutex_.lock(); if (recheckSinkSuccess_) { LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); RequestReCheckMsg(); @@ -2149,6 +2154,7 @@ void DmAuthManager::SrcAuthDeviceFinish() authRequestState_->TransitionTo(std::make_shared()); } } + recheckMutex_.unlock(); return; } } -- Gitee From 3f8227b2c3b2293811418a05571e6f427c41c091 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 17:12:35 +0800 Subject: [PATCH 09/16] src change Change-Id: I3e90bac74c3561e983faa7ef0b9b31e75a818b63 --- .../include/authentication/dm_auth_manager.h | 11 ++++++++++ .../authentication/auth_message_processor.cpp | 1 + .../src/authentication/dm_auth_manager.cpp | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 1e03c3dec..183300f56 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -191,8 +191,19 @@ typedef struct DmAuthResponseContext { bool isFinish = false; std::string edition; int32_t localBindLevel; + bool recheckDone = false; } DmAuthResponseContext; +typedef struct DMRecheckData { + std::string edition; + std::string localDeviceId; + int32_t localUserId; + std::string localAccountId; + int64_t tokenId; + std::string bundleName; + int32_t bindLevel; +} DMRecheckData; + class AuthMessageProcessor; class DmAuthManager final : public ISoftbusSessionCallback, diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index b67246a0b..ddf742103 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -687,6 +687,7 @@ void AuthMessageProcessor::CreateReqReCheckMessage(nlohmann::json &jsonObj) void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) { + authResponseContext_->recheckDone = true; std::string encryptStr = ""; if (IsString(json, TAG_CRYPTIC_MSG)) { encryptStr = json[TAG_CRYPTIC_MSG].get(); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index e4d3c8e39..fb69a489c 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2859,6 +2859,16 @@ bool DmAuthManager::RemoteSupportRecheck() void DmAuthManager::RequestReCheckMsg() { LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); + DMRecheckData savedData; + if (authResponseContext_->recheckDone) { + savedData.edition = authResponseContext_->edition; + savedData.localDeviceId = authResponseContext_->localDeviceId; + savedData.localUserId = authResponseContext_->localUserId; + savedData.localAccountId = authResponseContext_->localAccountId; + savedData.tokenId = authResponseContext_->tokenId; + savedData.bundleName = authResponseContext_->bundleName; + savedData.bindLevel = authResponseContext_->bindLevel; + } char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); uint32_t tokenId = 0; @@ -2875,6 +2885,17 @@ void DmAuthManager::RequestReCheckMsg() authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_RECHECK_MSG); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); + + if (authResponseContext_->recheckDone) { + authResponseContext_->edition = savedData.edition; + authResponseContext_->localDeviceId = savedData.localDeviceId; + authResponseContext_->localUserId = savedData.localUserId; + authResponseContext_->localAccountId = savedData.localAccountId; + authResponseContext_->tokenId = savedData.tokenId; + authResponseContext_->bundleName = savedData.bundleName; + authResponseContext_->bindLevel = savedData.bindLevel; + LOGI("[temp003] restore recheck data"); + } } void DmAuthManager::SendResponseReCheckMsg() -- Gitee From ad21b2233c6fa9e44fe625185e3ecaf3d66e478a Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 17:54:49 +0800 Subject: [PATCH 10/16] src change Change-Id: I8a35db2a3e2768666c21c24c77a26377fa73ab72 --- .../include/authentication/dm_auth_manager.h | 22 +++++----- .../authentication/auth_message_processor.cpp | 9 +++- .../src/authentication/dm_auth_manager.cpp | 42 +++++-------------- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 183300f56..6508cd43f 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -136,6 +136,16 @@ typedef struct DmAuthRequestContext { int32_t closeSessionDelaySeconds = 0; } DmAuthRequestContext; +typedef struct DMRecheckData { + std::string edition; + std::string localDeviceId; + int32_t localUserId; + std::string localAccountId; + int64_t tokenId; + std::string bundleName; + int32_t localBindLevel; +} DMRecheckData; + typedef struct DmAuthResponseContext { int32_t authType; std::string deviceId; @@ -191,18 +201,10 @@ typedef struct DmAuthResponseContext { bool isFinish = false; std::string edition; int32_t localBindLevel; - bool recheckDone = false; + DMRecheckData recheckData; } DmAuthResponseContext; -typedef struct DMRecheckData { - std::string edition; - std::string localDeviceId; - int32_t localUserId; - std::string localAccountId; - int64_t tokenId; - std::string bundleName; - int32_t bindLevel; -} DMRecheckData; + class AuthMessageProcessor; diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index ddf742103..5b6d7bf44 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -687,7 +687,6 @@ void AuthMessageProcessor::CreateReqReCheckMessage(nlohmann::json &jsonObj) void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) { - authResponseContext_->recheckDone = true; std::string encryptStr = ""; if (IsString(json, TAG_CRYPTIC_MSG)) { encryptStr = json[TAG_CRYPTIC_MSG].get(); @@ -731,6 +730,14 @@ void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { authResponseContext_->localBindLevel = jsonObject[TAG_BIND_LEVEL].get(); } + + authResponseContext_->recheckData.edition = authResponseContext_->edition; + authResponseContext_->recheckData.localDeviceId = authResponseContext_->localDeviceId; + authResponseContext_->recheckData.localUserId = authResponseContext_->localUserId; + authResponseContext_->recheckData.localAccountId = authResponseContext_->localAccountId; + authResponseContext_->recheckData.tokenId = authResponseContext_->tokenId; + authResponseContext_->recheckData.bundleName = authResponseContext_->bundleName; + authResponseContext_->recheckData.localBindLevel = authResponseContext_->localBindLevel; } int32_t AuthMessageProcessor::SaveSessionKey(const uint8_t *sessionKey, const uint32_t keyLen) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index fb69a489c..ad33a1387 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -299,6 +299,7 @@ int32_t DmAuthManager::GetCloseSessionDelaySeconds(std::string &delaySecondsStr) void DmAuthManager::InitAuthState(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { + LOGI("[temp003] InitAuthState"); if (authenticationMap_.find(authType) != authenticationMap_.end()) { authPtr_ = authenticationMap_[authType]; } @@ -2859,16 +2860,6 @@ bool DmAuthManager::RemoteSupportRecheck() void DmAuthManager::RequestReCheckMsg() { LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); - DMRecheckData savedData; - if (authResponseContext_->recheckDone) { - savedData.edition = authResponseContext_->edition; - savedData.localDeviceId = authResponseContext_->localDeviceId; - savedData.localUserId = authResponseContext_->localUserId; - savedData.localAccountId = authResponseContext_->localAccountId; - savedData.tokenId = authResponseContext_->tokenId; - savedData.bundleName = authResponseContext_->bundleName; - savedData.bindLevel = authResponseContext_->bindLevel; - } char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); uint32_t tokenId = 0; @@ -2885,17 +2876,6 @@ void DmAuthManager::RequestReCheckMsg() authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_RECHECK_MSG); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); - - if (authResponseContext_->recheckDone) { - authResponseContext_->edition = savedData.edition; - authResponseContext_->localDeviceId = savedData.localDeviceId; - authResponseContext_->localUserId = savedData.localUserId; - authResponseContext_->localAccountId = savedData.localAccountId; - authResponseContext_->tokenId = savedData.tokenId; - authResponseContext_->bundleName = savedData.bundleName; - authResponseContext_->bindLevel = savedData.bindLevel; - LOGI("[temp003] restore recheck data"); - } } void DmAuthManager::SendResponseReCheckMsg() @@ -2962,11 +2942,11 @@ void DmAuthManager::RequestReCheckMsgDone() bool DmAuthManager::IsSinkMsgValid() { - if (authResponseContext_->edition != remoteVersion_ || - authResponseContext_->localDeviceId != remoteDeviceId_ || - authResponseContext_->localUserId != authResponseContext_->remoteUserId || - authResponseContext_->bundleName != authResponseContext_->hostPkgName || - authResponseContext_->localBindLevel != authResponseContext_->bindLevel) { + if (authResponseContext_->recheckData.edition != remoteVersion_ || + authResponseContext_->recheckData.localDeviceId != remoteDeviceId_ || + authResponseContext_->recheckData.localUserId != authResponseContext_->remoteUserId || + authResponseContext_->recheckData.bundleName != authResponseContext_->hostPkgName || + authResponseContext_->recheckData.localBindLevel != authResponseContext_->bindLevel) { return false; } return true; @@ -2974,11 +2954,11 @@ bool DmAuthManager::IsSinkMsgValid() bool DmAuthManager::IsSourceMsgValid() { - if (authResponseContext_->edition != remoteVersion_ || - authResponseContext_->localDeviceId != remoteDeviceId_ || - authResponseContext_->localUserId != authRequestContext_->remoteUserId || - authResponseContext_->bundleName != authResponseContext_->peerBundleName || - authResponseContext_->localBindLevel != authResponseContext_->bindLevel) { + if (authResponseContext_->recheckData.edition != remoteVersion_ || + authResponseContext_->recheckData.localDeviceId != remoteDeviceId_ || + authResponseContext_->recheckData.localUserId != authRequestContext_->remoteUserId || + authResponseContext_->recheckData.bundleName != authResponseContext_->peerBundleName || + authResponseContext_->recheckData.localBindLevel != authResponseContext_->bindLevel) { return false; } authResponseContext_->localAccountId = authRequestContext_->localAccountId; -- Gitee From 38b513a434d474d08391b5bf2f5ef6b9fe909cda Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 19:54:21 +0800 Subject: [PATCH 11/16] home --- .../src/authentication/dm_auth_manager.cpp | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ad33a1387..9e3f0276c 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -575,14 +575,17 @@ void DmAuthManager::ProcessSourceMsg() } break; case MSG_TYPE_RESP_RECHECK_MSG: - recheckMutex_.lock(); + std::lock_guard guard(recheckMutex_); if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH || authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { + if(authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH) { + LOGI("[temp003] not send recheckmsg, send RequestReCheckMsg"); + RequestReCheckMsg(); + } authRequestState_->TransitionTo(std::make_shared()); } else { - LOGI("[temp003] skip MSG_TYPE_RESP_RECHECK_MSG"); + LOGI("[temp003] not in state, skip MSG_TYPE_RESP_RECHECK_MSG"); } - recheckMutex_.unlock(); break; default: break; @@ -2118,10 +2121,9 @@ void DmAuthManager::SrcAuthDeviceFinish() SetProcessInfo(); } softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); - recheckMutex_.lock(); + std::lock_guard guard(recheckMutex_); if (recheckSinkSuccess_) { - LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); - RequestReCheckMsg(); + LOGI("[temp003] SrcAuthDeviceFinish, recheckSinkSuccess_ , return"); } else { if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); @@ -2131,7 +2133,6 @@ void DmAuthManager::SrcAuthDeviceFinish() authRequestState_->TransitionTo(std::make_shared()); } } - recheckMutex_.unlock(); return; } if (!authResponseContext_->isOnline && authResponseContext_->haveCredential) { @@ -2144,8 +2145,7 @@ void DmAuthManager::SrcAuthDeviceFinish() authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); recheckMutex_.lock(); if (recheckSinkSuccess_) { - LOGI("[temp003] recheckSinkSuccess_ sendRecheckMsg only"); - RequestReCheckMsg(); + LOGI("[temp003] SrcAuthDeviceFinish, recheckSinkSuccess_ , return"); } else { if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); @@ -2155,14 +2155,13 @@ void DmAuthManager::SrcAuthDeviceFinish() authRequestState_->TransitionTo(std::make_shared()); } } - recheckMutex_.unlock(); return; } } void DmAuthManager::SinkAuthDeviceFinish() { - LOGI("isNeedProcCachedSrcReqMsg %{public}d. srcReqMsg_ %{public}d", isNeedProcCachedSrcReqMsg_, srcReqMsg_.empty()); + LOGI("isNeedProcCachedSrcReqMsg %{public}d.", isNeedProcCachedSrcReqMsg_); CHECK_NULL_VOID(authResponseState_); authResponseState_->TransitionTo(std::make_shared()); if (!authResponseContext_->haveCredential) { @@ -2194,7 +2193,7 @@ void DmAuthManager::SinkAuthDeviceFinish() authResponseState_->TransitionTo(std::make_shared()); } } else { - if (RemoteSupportRecheck()) { + if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2)) { LOGE("[temp003] SinkAuthDeviceFinish SendResponseReCheckMsg"); SendResponseReCheckMsg(); } @@ -2929,7 +2928,6 @@ void DmAuthManager::RequestReCheckMsgDone() authRequestState_->TransitionTo(std::make_shared()); return; } - LOGI("[temp003] RequestReCheckMsgDone recheckSinkSuccess_ = %{public}d", recheckSinkSuccess_); if (!recheckSinkSuccess_) { recheckSinkSuccess_ = true; -- Gitee From 35774d747ea82be8c4ac3e3cef2487bd6af0f7ad Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 20:01:16 +0800 Subject: [PATCH 12/16] home --- .../src/authentication/dm_auth_manager.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9e3f0276c..132d4f53b 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -576,12 +576,11 @@ void DmAuthManager::ProcessSourceMsg() break; case MSG_TYPE_RESP_RECHECK_MSG: std::lock_guard guard(recheckMutex_); - if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH || - authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { - if(authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH) { - LOGI("[temp003] not send recheckmsg, send RequestReCheckMsg"); - RequestReCheckMsg(); - } + if(authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH) { + LOGI("[temp003] not send recheckmsg, send RequestReCheckMsg"); + RequestReCheckMsg(); + authRequestState_->TransitionTo(std::make_shared()); + } else if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { authRequestState_->TransitionTo(std::make_shared()); } else { LOGI("[temp003] not in state, skip MSG_TYPE_RESP_RECHECK_MSG"); -- Gitee From c5593a316d8f74c66bdae225d068ed834aa607e7 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 20:04:25 +0800 Subject: [PATCH 13/16] home --- .../include/authentication/dm_auth_manager.h | 3 --- .../src/authentication/dm_auth_manager.cpp | 9 --------- 2 files changed, 12 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 6508cd43f..f8a6bd4a3 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -204,8 +204,6 @@ typedef struct DmAuthResponseContext { DMRecheckData recheckData; } DmAuthResponseContext; - - class AuthMessageProcessor; class DmAuthManager final : public ISoftbusSessionCallback, @@ -568,7 +566,6 @@ private: void ConverToFinish(); bool IsSinkMsgValid(); bool IsSourceMsgValid(); - bool RemoteSupportRecheck(); private: std::shared_ptr softbusConnector_; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 132d4f53b..5cf68e224 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2846,15 +2846,6 @@ void DmAuthManager::ConverToFinish() authRequestState_->TransitionTo(std::make_shared()); } -bool DmAuthManager::RemoteSupportRecheck() -{ - if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - return false; - } else { - return true; - } -} - void DmAuthManager::RequestReCheckMsg() { LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); -- Gitee From 55d88cc11515ebcc6880216e585dba534c52d944 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 20:42:35 +0800 Subject: [PATCH 14/16] home --- services/implementation/src/authentication/dm_auth_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 5cf68e224..1dc911743 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2103,6 +2103,7 @@ void DmAuthManager::SrcAuthDeviceFinish() LOGE("auth failed %{public}d.", authResponseContext_->confirmOperation); return; } + std::lock_guard guard(recheckMutex_); if (authResponseContext_->isOnline && authResponseContext_->haveCredential) { if (!authResponseContext_->isIdenticalAccount && !authResponseContext_->hostPkgName.empty()) { SetProcessInfo(); @@ -2120,7 +2121,6 @@ void DmAuthManager::SrcAuthDeviceFinish() SetProcessInfo(); } softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); - std::lock_guard guard(recheckMutex_); if (recheckSinkSuccess_) { LOGI("[temp003] SrcAuthDeviceFinish, recheckSinkSuccess_ , return"); } else { @@ -2142,7 +2142,6 @@ void DmAuthManager::SrcAuthDeviceFinish() } if (!authResponseContext_->isOnline && !authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); - recheckMutex_.lock(); if (recheckSinkSuccess_) { LOGI("[temp003] SrcAuthDeviceFinish, recheckSinkSuccess_ , return"); } else { -- Gitee From 8518d2e9cf68976b595d34c15f82d6fa97de61e1 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 11 Jan 2025 20:54:37 +0800 Subject: [PATCH 15/16] home --- services/implementation/src/authentication/dm_auth_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 1dc911743..d48ba8880 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2097,13 +2097,13 @@ void DmAuthManager::SrcAuthDeviceFinish() { LOGI("[temp003] SrcAuthDeviceFinish"); CHECK_NULL_VOID(authRequestState_); + std::lock_guard guard(recheckMutex_); authRequestState_->TransitionTo(std::make_shared()); if (authResponseContext_->confirmOperation != USER_OPERATION_TYPE_ALLOW_AUTH && authResponseContext_->confirmOperation != USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS) { LOGE("auth failed %{public}d.", authResponseContext_->confirmOperation); return; } - std::lock_guard guard(recheckMutex_); if (authResponseContext_->isOnline && authResponseContext_->haveCredential) { if (!authResponseContext_->isIdenticalAccount && !authResponseContext_->hostPkgName.empty()) { SetProcessInfo(); -- Gitee From 8cd321894a7a74066e9053822d1b9fcfde65b712 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Mon, 13 Jan 2025 09:48:04 +0800 Subject: [PATCH 16/16] fix Change-Id: Ie08525eb0f799664b7647fbfdf3db7070cbcd1e8 --- .../include/authentication/dm_auth_manager.h | 5 +- .../src/authentication/dm_auth_manager.cpp | 83 ++++++++++--------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index f8a6bd4a3..82e1ad3fc 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -604,9 +604,10 @@ private: std::mutex srcReqMsgLock_; bool isNeedProcCachedSrcReqMsg_ = false; std::string srcReqMsg_ = ""; - bool recheckSourceSuccess_ = false; - bool recheckSinkSuccess_ = false; std::mutex recheckMutex_; + bool recheckMsgReceived_ = false; + std::string savedRecheckMsg_; + std::recursive_mutex savedRecheckMsgMutex_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index d48ba8880..06f4a1e4a 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -345,8 +345,9 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au LOGE("CheckAuthParamVaildExtra failed, param is invaild."); return ret; } - recheckSinkSuccess_ = false; - recheckSourceSuccess_ = false; + recheckMsgReceived_ = false; + savedRecheckMsg_.clear(); + isAuthenticateDevice_ = true; if (authType == AUTH_TYPE_CRE) { LOGI("DmAuthManager::AuthenticateDevice for credential type, joinLNN directly."); @@ -575,15 +576,13 @@ void DmAuthManager::ProcessSourceMsg() } break; case MSG_TYPE_RESP_RECHECK_MSG: - std::lock_guard guard(recheckMutex_); - if(authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH) { - LOGI("[temp003] not send recheckmsg, send RequestReCheckMsg"); - RequestReCheckMsg(); - authRequestState_->TransitionTo(std::make_shared()); - } else if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { - authRequestState_->TransitionTo(std::make_shared()); - } else { - LOGI("[temp003] not in state, skip MSG_TYPE_RESP_RECHECK_MSG"); + { + std::lock_guard guard(recheckMutex_); + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { + authRequestState_->TransitionTo(std::make_shared()); + } else { + LOGI("[temp003] not in state, skip MSG_TYPE_RESP_RECHECK_MSG"); + } } break; default: @@ -662,6 +661,16 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me if ((authRequestState_ != nullptr) && (authResponseState_ == nullptr)) { // source device auth process + if (authResponseContext_->msgType == MSG_TYPE_RESP_RECHECK_MSG) { + std::lock_guard guard(savedRecheckMsgMutex_); + recheckMsgReceived_ = true; + if (authResponseContext_->edition.empty()) { + LOGE("[temp003] parse failed, save MSG_TYPE_RESP_RECHECK_MSG"); + savedRecheckMsg_ = message; + return; + } + } + ProcessSourceMsg(); } else if ((authResponseState_ != nullptr) && (authRequestState_ == nullptr)) { // sink device auth process @@ -2115,22 +2124,26 @@ void DmAuthManager::SrcAuthDeviceFinish() ConverToFinish(); return; } + + savedRecheckMsgMutex_.lock(); + if (!savedRecheckMsg_.empty()) { + LOGI("[temp003] process savedRecheckMsg_"); + authMessageProcessor_->SetResponseContext(authResponseContext_); + authMessageProcessor_->ParseMessage(savedRecheckMsg_); + savedRecheckMsg_.clear(); + } + savedRecheckMsgMutex_.unlock(); + if (authResponseContext_->isOnline && !authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); if (!authResponseContext_->isIdenticalAccount && !authResponseContext_->hostPkgName.empty()) { SetProcessInfo(); } softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); - if (recheckSinkSuccess_) { - LOGI("[temp003] SrcAuthDeviceFinish, recheckSinkSuccess_ , return"); + if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + authRequestState_->TransitionTo(std::make_shared()); } else { - if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); - authRequestState_->TransitionTo(std::make_shared()); - } else { - LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestCredential"); - authRequestState_->TransitionTo(std::make_shared()); - } + authRequestState_->TransitionTo(std::make_shared()); } return; } @@ -2142,16 +2155,10 @@ void DmAuthManager::SrcAuthDeviceFinish() } if (!authResponseContext_->isOnline && !authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); - if (recheckSinkSuccess_) { - LOGI("[temp003] SrcAuthDeviceFinish, recheckSinkSuccess_ , return"); + if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + authRequestState_->TransitionTo(std::make_shared()); } else { - if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestReCheckMsg"); - authRequestState_->TransitionTo(std::make_shared()); - } else { - LOGI("[temp003] SrcAuthDeviceFinish enter AuthRequestCredential"); - authRequestState_->TransitionTo(std::make_shared()); - } + authRequestState_->TransitionTo(std::make_shared()); } return; } @@ -2191,7 +2198,7 @@ void DmAuthManager::SinkAuthDeviceFinish() authResponseState_->TransitionTo(std::make_shared()); } } else { - if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2)) { + if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { LOGE("[temp003] SinkAuthDeviceFinish SendResponseReCheckMsg"); SendResponseReCheckMsg(); } @@ -2864,6 +2871,11 @@ void DmAuthManager::RequestReCheckMsg() authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_RECHECK_MSG); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); + + if (recheckMsgReceived_) { + LOGI("[temp003] recheckMsgReceived_ enter AuthRequestReCheckMsgDone"); + authRequestState_->TransitionTo(std::make_shared()); + } } void DmAuthManager::SendResponseReCheckMsg() @@ -2909,7 +2921,7 @@ void DmAuthManager::RequestReCheckMsgDone() { LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", remoteVersion_.c_str(), authResponseContext_->edition.c_str()); - if (!recheckSinkSuccess_ && !IsSourceMsgValid()) { + if (!IsSourceMsgValid()) { LOGE("peer deviceId not trust."); authResponseContext_->isFinish = false; isFinishOfLocal_ = false; @@ -2918,13 +2930,8 @@ void DmAuthManager::RequestReCheckMsgDone() return; } - if (!recheckSinkSuccess_) { - recheckSinkSuccess_ = true; - PutAccessControlList(); - - LOGI("[temp003] RequestReCheckMsgDone enter AuthRequestCredential"); - authRequestState_->TransitionTo(std::make_shared()); - } + PutAccessControlList(); + authRequestState_->TransitionTo(std::make_shared()); } bool DmAuthManager::IsSinkMsgValid() -- Gitee