diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 09bfd45bd447b71f39331913e0acc25c2a0bea09..50b550689931715da8ee13bc8831e45d13ddf119 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -166,6 +166,7 @@ constexpr int32_t CHECK_AUTH_ALWAYS_POS = 0; constexpr const char AUTH_ALWAYS = '1'; constexpr const char AUTH_ONCE = '0'; constexpr const char* TAG_TARGET_DEVICE_NAME = "targetDeviceName"; +constexpr int32_t INVALID_PINCODE = -1; // HiChain constexpr int32_t SERVICE_INIT_TRY_MAX_NUM = 200; diff --git a/services/implementation/include/authentication/auth_request_state.h b/services/implementation/include/authentication/auth_request_state.h index 05b4642dfe4545f1347c80674f6da2952c3e0055..997012de7064ea234537c072b559d5138dacdcf0 100644 --- a/services/implementation/include/authentication/auth_request_state.h +++ b/services/implementation/include/authentication/auth_request_state.h @@ -193,6 +193,12 @@ public: int32_t GetStateType() override; int32_t Enter() override; }; + +class AuthRequestAuthFinish : public AuthRequestState { +public: + int32_t GetStateType() override; + int32_t Enter() override; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_AUTH_REQUEST_STATE_H diff --git a/services/implementation/include/authentication/auth_response_state.h b/services/implementation/include/authentication/auth_response_state.h index c84a83aeb422c8f73b7725d5e1ce55d02bd5b1ae..cbf9eb9121914232259970d79288780c9409e5e3 100644 --- a/services/implementation/include/authentication/auth_response_state.h +++ b/services/implementation/include/authentication/auth_response_state.h @@ -112,6 +112,12 @@ public: int32_t GetStateType() override; int32_t Enter() override; }; + +class AuthResponseAuthFinish : public AuthResponseState { +public: + int32_t GetStateType() override; + int32_t Enter() override; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_AUTH_RESPONSE_STATE_H diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 75d1875612cc03550732e50f4d20c947f46224e2..70c6dd645dc2f9ab652cb9b9d8e92eb3df6c8341 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -47,6 +47,7 @@ typedef enum AuthState { AUTH_REQUEST_FINISH, AUTH_REQUEST_CREDENTIAL, AUTH_REQUEST_CREDENTIAL_DONE, + AUTH_REQUEST_AUTH_FINISH, AUTH_RESPONSE_INIT = 20, AUTH_RESPONSE_NEGOTIATE, @@ -55,6 +56,7 @@ typedef enum AuthState { AUTH_RESPONSE_SHOW, AUTH_RESPONSE_FINISH, AUTH_RESPONSE_CREDENTIAL, + AUTH_RESPONSE_AUTH_FINISH, } AuthState; enum DmMsgType : int32_t { @@ -156,7 +158,7 @@ typedef struct DmAuthResponseContext { std::string authToken; int32_t pageId; int64_t requestId; - int32_t code; + int32_t code = INVALID_PINCODE; int32_t state; std::vector syncGroupList; std::string accountGroupIdHash; diff --git a/services/implementation/src/authentication/auth_request_state.cpp b/services/implementation/src/authentication/auth_request_state.cpp index 7181d29470a0bce50db328800e0953c0081b97af..8dbcb3b84667547ca632eb8fa2c008b14b66cf12 100644 --- a/services/implementation/src/authentication/auth_request_state.cpp +++ b/services/implementation/src/authentication/auth_request_state.cpp @@ -204,5 +204,15 @@ int32_t AuthRequestCredentialDone::Enter() stateAuthManager->RequestCredentialDone(); return DM_OK; } + +int32_t AuthRequestAuthFinish::GetStateType() +{ + return AuthState::AUTH_REQUEST_AUTH_FINISH; +} + +int32_t AuthRequestAuthFinish::Enter() +{ + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/auth_response_state.cpp b/services/implementation/src/authentication/auth_response_state.cpp index 7f1803fa0414bca0b27d141b842c267002d5173c..afe61b0dc554b21294c922c397a16edfb57c66f3 100644 --- a/services/implementation/src/authentication/auth_response_state.cpp +++ b/services/implementation/src/authentication/auth_response_state.cpp @@ -168,5 +168,15 @@ int32_t AuthResponseCredential::Enter() stateAuthManager->ResponseCredential(); return DM_OK; } + +int32_t AuthResponseAuthFinish::GetStateType() +{ + return AuthState::AUTH_RESPONSE_AUTH_FINISH; +} + +int32_t AuthResponseAuthFinish::Enter() +{ + return DM_OK; +} } // 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 a7772eb63753190f5f8a358b5789fdc64d28a164..18610d61cd3b926b9fa37b272636d3d2b38cb84b 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -545,7 +545,7 @@ void DmAuthManager::ProcessSinkMsg() } break; case MSG_TYPE_REQ_PUBLICKEY: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH) { authResponseState_->TransitionTo(std::make_shared()); } break; @@ -1984,6 +1984,8 @@ bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, u void DmAuthManager::SrcAuthDeviceFinish() { + CHECK_NULL_VOID(authRequestState_); + authRequestState_->TransitionTo(std::make_shared()); if (authResponseContext_->isOnline) { if (authResponseContext_->confirmOperation == USER_OPERATION_TYPE_ALLOW_AUTH || (authResponseContext_->confirmOperation == USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS && @@ -2030,6 +2032,8 @@ void DmAuthManager::SrcAuthDeviceFinish() void DmAuthManager::SinkAuthDeviceFinish() { + CHECK_NULL_VOID(authResponseState_); + authResponseState_->TransitionTo(std::make_shared()); if (!authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_SHOW); } diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index f0614dcf2d274501fd37080746032c47b51c4206..ddedb35df51a259c49a9d8e2159d74dbd5d4fcff 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -101,8 +101,8 @@ char *HiChainAuthConnector::onRequest(int64_t requestId, int operationCode, cons return nullptr; } nlohmann::json jsonObj; - int32_t pinCode = -1; - if (dmDeviceAuthCallback_->GetPinCode(pinCode) == ERR_DM_FAILED || pinCode == -1) { + int32_t pinCode = INVALID_PINCODE; + if (dmDeviceAuthCallback_->GetPinCode(pinCode) == ERR_DM_FAILED || pinCode == INVALID_PINCODE) { jsonObj[FIELD_CONFIRMATION] = RequestResponse::REQUEST_REJECTED; } else { jsonObj[FIELD_CONFIRMATION] = RequestResponse::REQUEST_ACCEPTED; diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index c1b4f837b384cf583a772ce52ddea0cf05c3bb72..2dc7efda681bd5fa30e3b7a912151375f648f910 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -475,8 +475,8 @@ char *HiChainConnector::onRequest(int64_t requestId, int operationCode, const ch return nullptr; } nlohmann::json jsonObj; - int32_t pinCode = -1; - if (hiChainConnectorCallback_->GetPinCode(pinCode) == ERR_DM_FAILED || pinCode == -1) { + int32_t pinCode = INVALID_PINCODE; + if (hiChainConnectorCallback_->GetPinCode(pinCode) == ERR_DM_FAILED || pinCode == INVALID_PINCODE) { jsonObj[FIELD_CONFIRMATION] = REQUEST_REJECTED; } else { jsonObj[FIELD_CONFIRMATION] = REQUEST_ACCEPTED;