From 9fa3d8c64187ae98f393d09a39fe58f0837be4a1 Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Sat, 6 Jul 2024 20:20:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9DM=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../include/authentication/dm_auth_manager.h | 2 +- .../dependency/hichain/hichain_connector_callback.h | 4 ++-- .../src/authentication/auth_message_processor.cpp | 11 +++++++++-- .../src/authentication/dm_auth_manager.cpp | 8 +++++--- .../src/dependency/hichain/hichain_auth_connector.cpp | 4 ++-- .../src/dependency/hichain/hichain_connector.cpp | 4 ++-- .../hichain_connector_fuzzer.cpp | 3 ++- .../commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp | 3 ++- .../onfinish_fuzzer/on_finish_fuzzer.cpp | 3 ++- .../onrequest_fuzzer/on_request_fuzzer.cpp | 3 ++- test/commonunittest/UTTest_dm_auth_manager_first.cpp | 10 ++++++---- test/commonunittest/UTTest_hichain_auth_connector.cpp | 4 +++- test/commonunittest/UTTest_hichain_connector.cpp | 6 +++--- 13 files changed, 41 insertions(+), 24 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 64fdfae08..486ac4d66 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 7918c3274..1e8e73f43 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 798d20687..79d2a96f7 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 e5c5c0c3d..f7e092f8f 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 8d84c64e1..c7887c985 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 4d6aa2210..6ce0cff39 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 9ccd8a9be..34fc06070 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 3c64218e7..ea8c7f86a 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 36fd44123..196069acc 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 784dcf4a8..d3b7df0b7 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 2d6282c6c..d2abfa1b5 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 0bf386495..2a9142c63 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 e1c427e3d..ffe4da9f1 100755 --- a/test/commonunittest/UTTest_hichain_connector.cpp +++ b/test/commonunittest/UTTest_hichain_connector.cpp @@ -61,10 +61,10 @@ public: { return ""; } - int32_t GetPinCode() + int32_t GetPinCode(int32_t &code) { - int32_t pinCode = 123456; - return pinCode; + code = 123456; + return DM_OK; } }; -- Gitee From 3355cebc2e59d87da478875188ea7ea54323132e Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Sat, 6 Jul 2024 20:41:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9DM=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- test/commonunittest/UTTest_hichain_connector.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/commonunittest/UTTest_hichain_connector.cpp b/test/commonunittest/UTTest_hichain_connector.cpp index ffe4da9f1..23acd3771 100755 --- a/test/commonunittest/UTTest_hichain_connector.cpp +++ b/test/commonunittest/UTTest_hichain_connector.cpp @@ -63,7 +63,8 @@ public: } int32_t GetPinCode(int32_t &code) { - code = 123456; + int32_t pinCode = 123456; + code = pinCode; return DM_OK; } }; -- Gitee