mirror of
https://github.com/openharmony/notification_ces_standard.git
synced 2026-07-01 04:39:51 -04:00
@@ -17,6 +17,7 @@
|
||||
#define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_PUBLIC_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include "singleton.h"
|
||||
@@ -38,6 +39,7 @@ public:
|
||||
bool CheckIsFloodAttack(pid_t appUid);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::map<pid_t, std::vector<int64_t>> floodAttackAppStatistics_;
|
||||
const uint32_t FLOOD_ATTACK_NUMBER_MAX = 20; // Frequency of decision
|
||||
const int64_t FLOOD_ATTACK_INTERVAL_MAX = 5; // Period of decision (unit: millisecond)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -31,18 +31,15 @@ PublishManager::~PublishManager()
|
||||
bool PublishManager::CheckIsFloodAttack(pid_t appUid)
|
||||
{
|
||||
EVENT_LOGI("enter");
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
bool isAttacked = false;
|
||||
|
||||
int64_t now = SystemTime::GetNowSysTime();
|
||||
EVENT_LOGI("dispatch common event by app (uid = %{publish}d) at now = %{public}" PRId64, appUid, now);
|
||||
|
||||
auto iter = floodAttackAppStatistics_.find(appUid);
|
||||
if (iter == floodAttackAppStatistics_.end()) {
|
||||
floodAttackAppStatistics_[appUid].emplace_back(now);
|
||||
return isAttacked;
|
||||
}
|
||||
|
||||
// Remove expired record
|
||||
auto iterVec = iter->second.begin();
|
||||
while (iterVec != iter->second.end()) {
|
||||
@@ -52,13 +49,11 @@ bool PublishManager::CheckIsFloodAttack(pid_t appUid)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (iter->second.size() + 1 > FLOOD_ATTACK_NUMBER_MAX) {
|
||||
EVENT_LOGW("CES was maliciously attacked by app (uid = %{publish}d)", appUid);
|
||||
isAttacked = true;
|
||||
}
|
||||
iter->second.emplace_back(now);
|
||||
|
||||
return isAttacked;
|
||||
}
|
||||
} // namespace EventFwk
|
||||
|
||||
Reference in New Issue
Block a user