1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef SECURITY_GUARD_CONFIG_DEFINE_H
17#define SECURITY_GUARD_CONFIG_DEFINE_H
18
19#include <string>
20#include <vector>
21
22namespace OHOS::Security::SecurityGuard {
23using Field = struct {
24    std::string fieldName;
25    std::string fieldType;
26    std::string value;
27};
28
29using Rule = struct {
30    int64_t eventId;
31    std::vector<Field> fields;
32    std::string fieldsRelation;
33};
34
35using BuildInDetectionCfg = struct {
36    std::vector<Rule> rules;
37    std::string rulesRelation;
38    std::string trueResult;
39    std::string falseResult;
40};
41
42using AppDetectionCfg = struct {
43    std::string detectionCategory;
44    std::string configFileName;
45    std::string trueResult;
46    std::string falseResult;
47};
48
49using AppAttribute = enum {
50    NORMAL,
51    PAYMENT,
52    MALICIOUS,
53    MONITORING,
54    ATTRMAX
55};
56
57using AppInfo = struct {
58    std::string appName;
59    std::string appHash;
60    std::vector<std::string> attrs;
61    int isGlobalApp;
62    int isUpdate;
63};
64
65using ModelCfg = struct {
66    uint32_t modelId;
67    std::string path;
68    std::string format;
69    uint32_t startMode;
70    std::vector<int64_t> preload;
71    std::vector<int64_t> eventList;
72    std::string permissions;
73    std::string dbTable;
74    uint32_t runningCntl;
75    std::vector<std::string> caller;
76    std::string type;
77    BuildInDetectionCfg config;
78    AppDetectionCfg appDetectionConfig;
79};
80
81enum class EventTypeEnum {
82    NORMALE_COLL = 0,
83    QUERY_COLL = 1,
84    START_STOP_COLL = 2,
85    SUBSCRIBE_COLL = 3
86};
87
88
89using DataMgrCfgSt = struct {
90    uint32_t deviceRom;
91    uint32_t deviceRam;
92    uint32_t eventMaxRamNum;
93    uint32_t eventMaxRomNum;
94    std::string prog;
95};
96
97using EventContentSt = struct {
98    uint32_t status;
99    uint32_t cred;
100    std::string extra;
101};
102
103using SecEvent = struct {
104    int64_t eventId;
105    std::string version;
106    std::string date;
107    std::string content;
108    int32_t eventType;
109    int32_t dataSensitivityLevel;
110    std::string owner;
111    int32_t userId;
112    std::string deviceId;
113};
114
115using StartMode = enum {
116    NOT_SUPPORT,
117    START_ON_STARTUP,
118    START_ON_DEMAND
119};
120
121using DataSource = enum {
122    USER_SOURCE,
123    KERNEL_SOURCE,
124    MODEL_SOURCE,
125    HIVIEW_SOURCE
126};
127
128using LoadMode = enum {
129    INIT_MODE,
130    UPDATE_MODE
131};
132
133using PathIndex = enum {
134    EVENT_CFG_INDEX,
135    MODEL_CFG_INDEX,
136    SIG_RULE_CFG_INDEX,
137    URL_RULE_CFG_INDEX,
138    LOCAL_APP_CFG_INDEX,
139    GLOBAL_APP_CFG_INDEX,
140    RELATED_EVENT_ANALYSIS_CFG_INDEX
141};
142
143const std::vector<std::string> CONFIG_CACHE_FILES = {
144    "/data/service/el1/public/security_guard/tmp/security_guard_event.json",
145    "/data/service/el1/public/security_guard/tmp/security_guard_model.cfg",
146    "/data/service/el1/public/security_guard/tmp/signature_rule.json",
147    "/data/service/el1/public/security_guard/tmp/url_rule.json",
148    "/data/service/el1/public/security_guard/tmp/local_app_attribute.json",
149    "/data/service/el1/public/security_guard/tmp/global_app_attribute.json",
150    "/data/service/el1/public/security_guard/tmp/related_event_analysis.json"
151};
152
153const std::vector<std::string> CONFIG_UPTATE_FILES = {
154    "/data/service/el1/public/security_guard/security_guard_event.json",
155    "/data/service/el1/public/security_guard/security_guard_model.cfg",
156    "/data/service/el1/public/security_guard/signature_rule.json",
157    "/data/service/el1/public/security_guard/url_rule.json",
158    "/data/service/el1/public/security_guard/local_app_attr.json",
159    "/data/service/el1/public/security_guard/global_app_attr.json",
160    "/data/service/el1/public/security_guard/related_event_analysis.json"
161};
162
163const std::vector<std::string> CONFIG_PRESET_FILES = {
164    "/system/etc/security_guard_event.json",
165    "/system/etc/security_guard_model.cfg"
166};
167
168const std::string CONFIG_ROOT_PATH = "/data/service/el1/public/security_guard/";
169} // namespace OHOS::Security::SecurityGuard
170
171#endif // SECURITY_GUARD_CONFIG_DEFINE_H
172