diff --git a/frameworks/common/include/sec_comp_err.h b/frameworks/common/include/sec_comp_err.h index 8cacb68c3e7bc94f9d77bf292a238885ba056370..ff2cb6b11dcc93983b00ef865ce659511077b3a4 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 f1b361c39b51f83817a559456a39d84904321f24..865633756f9d937fcf9fc2b05daf135d2509660b 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 5d1ba492f9a794d2f72f64c852dfde9b8340bdbe..5c78fa48d042ad4c2cf1948c4c950dbcb0edb20f 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 49d0785e67b2978dac0b65b9e4b6f0fb90af913f..4c319910580e3e71d41a7a30d1fe0d7c0cba0be2 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 f306dc569f7feffbd224065901635610692102a7..04d04b7faaff501ab030f810e9320ae804bc8bf0 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 }