diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 64fdfae08f319b2c7d8d2e51625fc6c89e08a053..486ac4d665bfab35e23870fd5c1d4571baf6f460 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -355,7 +355,7 @@ public: * @tc.desc: Get Pin Code of the DeviceManager Authenticate Manager * @tc.type: FUNC */ - int32_t GetPinCode(); + int32_t GetPinCode(int32_t &code); /** * @tc.name: DmAuthManager::GenerateGroupName diff --git a/services/implementation/include/dependency/hichain/hichain_connector_callback.h b/services/implementation/include/dependency/hichain/hichain_connector_callback.h index 7918c3274351f3f675eb33913e30236a56522ac8..1e8e73f430f2a86209dad621e8fa96be5731e84d 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector_callback.h +++ b/services/implementation/include/dependency/hichain/hichain_connector_callback.h @@ -23,7 +23,7 @@ public: virtual void OnGroupCreated(int64_t requestId, const std::string &groupId) = 0; virtual void OnMemberJoin(int64_t requestId, int32_t status) = 0; virtual std::string GetConnectAddr(std::string deviceId) = 0; - virtual int32_t GetPinCode() = 0; + virtual int32_t GetPinCode(int32_t &code) = 0; }; class IDmGroupResCallback { @@ -37,7 +37,7 @@ public: virtual void AuthDeviceFinish(int64_t requestId) = 0; virtual void AuthDeviceError(int64_t requestId, int32_t errorCode) = 0; virtual void AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) = 0; - virtual int32_t GetPinCode() = 0; + virtual int32_t GetPinCode(int32_t &code) = 0; virtual void GetRemoteDeviceId(std::string &deviceId) = 0; }; } // namespace DistributedHardware diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 798d20687ecfd7008a1c95c3a9ea9cfa62e17dfa..79d2a96f7adeb2e71e144a9620da1b0579790bf3 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace DistributedHardware { const int32_t MSG_MAX_SIZE = 45 * 1024; const int32_t GROUP_VISIBILITY_IS_PRIVATE = 0; - +const int32_t MAX_BINDTYPE_SIZE = 1000; constexpr const char* TAG_HOST = "HOST"; constexpr const char* TAG_VISIBILITY = "VISIBILITY"; constexpr const char* TAG_APP_THUMBNAIL = "APPTHUM"; @@ -401,7 +401,6 @@ int32_t AuthMessageProcessor::ParseAuthRequestMessage(nlohmann::json &json) GetAuthReqMessage(json); authResponseContext_->appThumbnail = ""; } - if (idx < sliceNum && IsString(json, TAG_APP_THUMBNAIL)) { std::string appSliceThumbnail = json[TAG_APP_THUMBNAIL].get(); authResponseContext_->appThumbnail = authResponseContext_->appThumbnail + appSliceThumbnail; @@ -414,6 +413,10 @@ int32_t AuthMessageProcessor::ParseAuthRequestMessage(nlohmann::json &json) } if (IsInt32(json, TAG_BIND_TYPE_SIZE)) { int32_t bindTypeSize = json[TAG_BIND_TYPE_SIZE].get(); + if (bindTypeSize > MAX_BINDTYPE_SIZE) { + LOGE("ParseAuthRequestMessage bindTypeSize is over size."); + return ERR_DM_FAILED; + } authResponseContext_->bindType.clear(); for (int32_t item = 0; item < bindTypeSize; item++) { std::string itemStr = std::to_string(item); @@ -491,6 +494,10 @@ void AuthMessageProcessor::ParsePkgNegotiateMessage(const nlohmann::json &json) } if (IsInt32(json, TAG_BIND_TYPE_SIZE)) { int32_t bindTypeSize = json[TAG_BIND_TYPE_SIZE].get(); + if (bindTypeSize > MAX_BINDTYPE_SIZE) { + LOGE("ParsePkgNegotiateMessage bindTypeSize is over size."); + return; + } authResponseContext_->bindType.clear(); for (int32_t item = 0; item < bindTypeSize; item++) { std::string itemStr = std::to_string(item); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index e5c5c0c3d8ef516890001c73324f63a542433ce7..f7e092f8f77e04a9d943abb5f3250e8c55516dba 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1239,14 +1239,16 @@ int32_t DmAuthManager::SetAuthResponseState(std::shared_ptr a return DM_OK; } -int32_t DmAuthManager::GetPinCode() +int32_t DmAuthManager::GetPinCode(int32_t &code) { if (authResponseContext_ == nullptr) { LOGE("failed to GetPinCode because authResponseContext_ is nullptr"); - return ERR_DM_AUTH_NOT_START; + code = ERR_DM_AUTH_NOT_START; + return ERR_DM_FAILED; } LOGI("ShowConfigDialog start add member pin code."); - return authResponseContext_->code; + code = authResponseContext_->code; + return DM_OK; } void DmAuthManager::ShowConfigDialog() diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index 8d84c64e1ec453d1c6f9ca22a620900372a75ee7..c7887c985c4816c75e238df57f1c920e6b17852b 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 = dmDeviceAuthCallback_->GetPinCode(); - if (pinCode == ERR_DM_AUTH_NOT_START) { + int32_t pinCode = 0; + if (dmDeviceAuthCallback_->GetPinCode(pinCode) == ERR_DM_FAILED) { 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 4d6aa22108376737fdc158b725086ba637c0083d..6ce0cff39dabae178a0565021ea5d2e651889b56 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -493,8 +493,8 @@ char *HiChainConnector::onRequest(int64_t requestId, int operationCode, const ch return nullptr; } nlohmann::json jsonObj; - int32_t pinCode = hiChainConnectorCallback_->GetPinCode(); - if (pinCode == ERR_DM_AUTH_NOT_START) { + int32_t pinCode = 0; + if (hiChainConnectorCallback_->GetPinCode(pinCode) == ERR_DM_FAILED) { jsonObj[FIELD_CONFIRMATION] = REQUEST_REJECTED; } else { jsonObj[FIELD_CONFIRMATION] = REQUEST_ACCEPTED; diff --git a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp index 9ccd8a9beade3e395fa56595ab40a55010b0634d..34fc06070f8467311cf8bc3d952b99f95c74bd1e 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp +++ b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp @@ -46,8 +46,9 @@ public: (void)deviceId; return ""; } - int32_t GetPinCode() override + int32_t GetPinCode(int32_t &code) override { + (void)code; return DM_OK; } }; diff --git a/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp b/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp index 3c64218e70eb96343599d93c99ed923c4063e9f2..ea8c7f86a817e88339af2cd5f1a3e0d7dd1778dd 100644 --- a/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp +++ b/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp @@ -46,8 +46,9 @@ public: (void)deviceId; return ""; } - int32_t GetPinCode() override + int32_t GetPinCode(int32_t &code) override { + (void)code; return DM_OK; } }; diff --git a/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp b/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp index 36fd4412398aff390132c6e791303f5e7e4368a6..196069accd5b4693f16e6385a3e18d19e9daaa76 100644 --- a/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp +++ b/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp @@ -46,8 +46,9 @@ public: (void)deviceId; return ""; } - int32_t GetPinCode() override + int32_t GetPinCode(int32_t &code) override { + (void)code; return DM_OK; } }; diff --git a/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp b/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp index 784dcf4a87f9f0216cd6993ec5ab99e5d3105ad9..d3b7df0b7b32c73ed8a1f79537e0855d86093673 100644 --- a/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp +++ b/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp @@ -45,8 +45,9 @@ public: (void)deviceId; return ""; } - int32_t GetPinCode() override + int32_t GetPinCode(int32_t &code) override { + (void)code; return DM_OK; } }; diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 2d6282c6c22669ebc630952c39ef4ab2ec47ecb5..d2abfa1b57c0e97937adb86270c52808fde97e03 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -260,8 +260,9 @@ HWTEST_F(DmAuthManagerTest, SetAuthResponseState_002, testing::ext::TestSize.Lev HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) { authManager_->authResponseContext_->code = 123456; - int32_t ret = authManager_->GetPinCode(); - ASSERT_EQ(ret, 123456); + int32_t code = 0; + authManager_->GetPinCode(code); + ASSERT_EQ(code, 123456); } HWTEST_F(DmAuthManagerTest, GetPinCode_002, testing::ext::TestSize.Level0) @@ -270,8 +271,9 @@ HWTEST_F(DmAuthManagerTest, GetPinCode_002, testing::ext::TestSize.Level0) authManager_->ShowConfigDialog(); authManager_->ShowAuthInfoDialog(); authManager_->ShowStartAuthDialog(); - int32_t ret = authManager_->GetPinCode(); - ASSERT_EQ(ret, ERR_DM_AUTH_NOT_START); + int32_t code = 0; + authManager_->GetPinCode(code); + ASSERT_EQ(code, ERR_DM_AUTH_NOT_START); } HWTEST_F(DmAuthManagerTest, SetPageId_001, testing::ext::TestSize.Level0) diff --git a/test/commonunittest/UTTest_hichain_auth_connector.cpp b/test/commonunittest/UTTest_hichain_auth_connector.cpp index 0bf38649562dd66e79c9c680c62355c5d5d9c1c0..2a9142c63756ede7033efd8175565e7fcfa59c2e 100644 --- a/test/commonunittest/UTTest_hichain_auth_connector.cpp +++ b/test/commonunittest/UTTest_hichain_auth_connector.cpp @@ -62,11 +62,13 @@ public: (void)sessionKey; (void)sessionKeyLen; } - int32_t GetPinCode() override + int32_t GetPinCode(int32_t &code) override { if (pinCode == 0) { + code = 0; return DM_OK; } + code = ERR_DM_AUTH_NOT_START; return ERR_DM_AUTH_NOT_START; } void GetRemoteDeviceId(std::string &deviceId) override diff --git a/test/commonunittest/UTTest_hichain_connector.cpp b/test/commonunittest/UTTest_hichain_connector.cpp index e1c427e3d0441c1ac321c33642747f8e37a0f8d3..23acd37713a857b7e842bc5415fe5294243919c2 100755 --- a/test/commonunittest/UTTest_hichain_connector.cpp +++ b/test/commonunittest/UTTest_hichain_connector.cpp @@ -61,10 +61,11 @@ public: { return ""; } - int32_t GetPinCode() + int32_t GetPinCode(int32_t &code) { int32_t pinCode = 123456; - return pinCode; + code = pinCode; + return DM_OK; } };