From a6ffd16b99fba34e85b9109af06590da67f9eb24 Mon Sep 17 00:00:00 2001 From: libing23 Date: Thu, 21 Sep 2023 17:38:21 +0800 Subject: [PATCH] fixed ca04c33 from https://gitee.com/libing23/security_security_component/pulls/32 dont add malicious app list when click point is not in component rect. Signed-off-by: libing23 --- frameworks/common/include/sec_comp_err.h | 3 ++- .../sa/sa_main/sec_comp_entity.cpp | 10 +++++----- .../sa/sa_main/sec_comp_entity.h | 2 +- .../sa/sa_main/sec_comp_manager.cpp | 7 +++++-- .../sa/test/unittest/src/sec_comp_entity_test.cpp | 10 +++++----- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/frameworks/common/include/sec_comp_err.h b/frameworks/common/include/sec_comp_err.h index 8cacb68..ff2cb6b 100644 --- a/frameworks/common/include/sec_comp_err.h +++ b/frameworks/common/include/sec_comp_err.h @@ -46,7 +46,8 @@ enum SCErrCode : int32_t { SC_ENHANCE_ERROR_CALLBACK_OPER_FAIL = -107, SC_ENHANCE_ERROR_CALLBACK_CHECK_FAIL = -108, SC_ENHANCE_ERROR_IN_MALICIOUS_LIST = -109, - SC_ENHANCE_ERROR_CHALLENGE_CHECK_FAIL = -110 + SC_ENHANCE_ERROR_CHALLENGE_CHECK_FAIL = -110, + SC_ENHANCE_ERROR_CLICK_EXTRA_CHECK_FAIL = -111, }; } // namespace SecurityComponent } // namespace Security diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp index f1b361c..8656337 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp @@ -52,20 +52,20 @@ bool SecCompEntity::CompareComponentBasicInfo(SecCompBase* other, bool isRectChe return componentInfo_->CompareComponentBasicInfo(other, isRectCheck); } -bool SecCompEntity::CheckTouchInfo(const SecCompClickEvent& touchInfo) const +int32_t SecCompEntity::CheckTouchInfo(const SecCompClickEvent& touchInfo) const { auto current = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TIME_CONVERSION_UNIT; if (touchInfo.timestamp < current - MAX_TOUCH_INTERVAL || touchInfo.timestamp > current) { SC_LOG_ERROR(LABEL, "touch timestamp invalid touchInfo. timestamp: %{public}llu, current: %{public}llu", static_cast(touchInfo.timestamp), static_cast(current)); - return false; + return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } if (!componentInfo_->rect_.IsInRect(touchInfo.touchX, touchInfo.touchY)) { SC_LOG_ERROR(LABEL, "touch point is not in component rect, %{public}lf, %{public}lf", touchInfo.touchX, touchInfo.touchY); - return false; + return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } int32_t res = SecCompEnhanceAdapter::CheckExtraInfo(touchInfo); @@ -77,9 +77,9 @@ bool SecCompEntity::CheckTouchInfo(const SecCompClickEvent& touchInfo) const HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "CLICK_INFO_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, "CALLER_UID", IPCSkeleton::GetCallingUid(), "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId_, "SC_TYPE", componentInfo_->type_); - return false; + return SC_ENHANCE_ERROR_CLICK_EXTRA_CHECK_FAIL; } - return true; + return SC_OK; } } // namespace SecurityComponent } // namespace Security diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.h b/services/security_component_service/sa/sa_main/sec_comp_entity.h index 5d1ba49..5c78fa4 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.h +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.h @@ -66,7 +66,7 @@ public: }; bool CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const; - bool CheckTouchInfo(const SecCompClickEvent& touchInfo) const; + int32_t CheckTouchInfo(const SecCompClickEvent& touchInfo) const; private: std::shared_ptr componentInfo_; diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp index 49d0785..4c31991 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp @@ -459,11 +459,14 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, return res; } - if (!sc->CheckTouchInfo(touchInfo)) { + res = sc->CheckTouchInfo(touchInfo); + if (res != SC_OK) { HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "CLICK_INFO_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, "CALLER_UID", IPCSkeleton::GetCallingUid(), "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId, "SC_TYPE", sc->GetType()); - AddAppToMaliciousAppList(caller.pid); + if (res == SC_ENHANCE_ERROR_CLICK_EXTRA_CHECK_FAIL) { + AddAppToMaliciousAppList(caller.pid); + } return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } res = sc->GrantTempPermission(); diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp index f306dc5..04d04b7 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp @@ -134,11 +134,11 @@ HWTEST_F(SecCompEntityTest, CheckTouchInfo001, TestSize.Level1) .touchY = ServiceTestCommon::TEST_COORDINATE, .timestamp = 0, }; - ASSERT_FALSE(entity_->CheckTouchInfo(touch)); + ASSERT_NE(entity_->CheckTouchInfo(touch), SC_OK); uint64_t current = static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count()); touch.timestamp = current + 10000L; // 10s - ASSERT_FALSE(entity_->CheckTouchInfo(touch)); + ASSERT_NE(entity_->CheckTouchInfo(touch), SC_OK); entity_->componentInfo_->rect_.x_ = ServiceTestCommon::TEST_DIFF_COORDINATE; // click event will not hit this rect entity_->componentInfo_->rect_.y_ = ServiceTestCommon::TEST_DIFF_COORDINATE; @@ -146,15 +146,15 @@ HWTEST_F(SecCompEntityTest, CheckTouchInfo001, TestSize.Level1) entity_->componentInfo_->rect_.height_ = ServiceTestCommon::TEST_DIFF_COORDINATE; touch.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; - ASSERT_FALSE(entity_->CheckTouchInfo(touch)); + ASSERT_NE(entity_->CheckTouchInfo(touch), SC_OK); entity_->componentInfo_->rect_.x_ = ServiceTestCommon::TEST_COORDINATE; entity_->componentInfo_->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; touch.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - ASSERT_FALSE(entity_->CheckTouchInfo(touch)); + ASSERT_NE(entity_->CheckTouchInfo(touch), SC_OK); #else - ASSERT_TRUE(entity_->CheckTouchInfo(touch)); + ASSERT_EQ(entity_->CheckTouchInfo(touch), SC_OK); #endif } -- Gitee