mirror of
https://github.com/openharmony/security_security_component_manager.git
synced 2026-08-25 12:39:40 -04:00
dont add malicious app list when click point is not in component rect.
Signed-off-by: libing23 <libing23@huawei.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<uint64_t>(
|
||||
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<unsigned long long>(touchInfo.timestamp), static_cast<unsigned long long>(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
|
||||
|
||||
@@ -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<SecCompBase> componentInfo_;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<uint64_t>(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<uint64_t>(
|
||||
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<uint64_t>(
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user