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 22 namespace OHOS::Security::SecurityGuard { 23 using Field = struct { 24 std::string fieldName; 25 std::string fieldType; 26 std::string value; 27 }; 28 29 using Rule = struct { 30 int64_t eventId; 31 std::vector<Field> fields; 32 std::string fieldsRelation; 33 }; 34 35 using BuildInDetectionCfg = struct { 36 std::vector<Rule> rules; 37 std::string rulesRelation; 38 std::string trueResult; 39 std::string falseResult; 40 }; 41 42 using AppDetectionCfg = struct { 43 std::string detectionCategory; 44 std::string configFileName; 45 std::string trueResult; 46 std::string falseResult; 47 }; 48 49 using ModelCfg = struct { 50 uint32_t modelId; 51 std::string path; 52 std::string format; 53 uint32_t startMode; 54 std::vector<int64_t> preload; 55 std::vector<int64_t> eventList; 56 std::string permissions; 57 std::string dbTable; 58 uint32_t runningCntl; 59 std::vector<std::string> caller; 60 std::string type; 61 BuildInDetectionCfg config; 62 AppDetectionCfg appDetectionConfig; 63 }; 64 65 enum class EventTypeEnum { 66 NORMALE_COLL = 0, 67 QUERY_COLL = 1, 68 START_STOP_COLL = 2, 69 SUBSCRIBE_COLL = 3 70 }; 71 72 using EventCfg = struct { 73 int64_t eventId; 74 std::string eventName; 75 uint32_t version; 76 uint32_t eventType; 77 uint32_t collectOnStart; 78 uint32_t dataSensitivityLevel; 79 uint32_t storageRamNums; 80 uint32_t storageRomNums; 81 int32_t storageTime; 82 std::vector<std::string> owner; 83 uint32_t source; 84 std::string dbTable; 85 std::string prog; 86 }; 87 88 using DataMgrCfgSt = struct { 89 uint32_t deviceRom; 90 uint32_t deviceRam; 91 uint32_t eventMaxRamNum; 92 uint32_t eventMaxRomNum; 93 }; 94 95 using EventContentSt = struct { 96 uint32_t status; 97 uint32_t cred; 98 std::string extra; 99 }; 100 101 using SecEvent = struct { 102 int64_t eventId; 103 std::string version; 104 std::string date; 105 std::string content; 106 int32_t eventType; 107 int32_t dataSensitivityLevel; 108 std::string owner; 109 int32_t userId; 110 std::string deviceId; 111 }; 112 113 using AppAttribute = enum { 114 NORMAL, 115 PAYMENT, 116 MALICIOUS, 117 MONITORING, 118 ATTRMAX 119 }; 120 121 using AppInfo = struct { 122 std::string appName; 123 std::string appHash; 124 std::vector<std::string> attrs; 125 int isGlobalApp; 126 int isUpdate; 127 }; 128 using StartMode = enum { 129 NOT_SUPPORT, 130 START_ON_STARTUP, 131 START_ON_DEMAND 132 }; 133 134 using DataSource = enum { 135 USER_SOURCE, 136 KERNEL_SOURCE, 137 MODEL_SOURCE, 138 HIVIEW_SOURCE 139 }; 140 141 using LoadMode = enum { 142 INIT_MODE, 143 UPDATE_MODE 144 }; 145 146 using PathIndex = enum { 147 EVENT_CFG_INDEX, 148 MODEL_CFG_INDEX, 149 SIG_RULE_CFG_INDEX, 150 URL_RULE_CFG_INDEX, 151 LOCAL_APP_CFG_INDEX, 152 GLOBAL_APP_CFG_INDEX, 153 RELATED_EVENT_ANALYSIS_CFG_INDEX 154 }; 155 156 const std::vector<std::string> CONFIG_CACHE_FILES = { 157 "/data/test/unittest/resource/security_guard/security_guard/security_guard_cache_event.cfg", 158 "/data/test/unittest/resource/security_guard/security_guard/security_guard_cache_model.cfg", 159 "", 160 "", 161 "/data/test/unittest/resource/security_guard/security_guard/local_app_attribute.json", 162 "/data/test/unittest/resource/security_guard/security_guard/global_app_attribute.json", 163 "/data/test/unittest/resource/security_guard/security_guard/related_event_analysis.json" 164 }; 165 166 const std::vector<std::string> CONFIG_UPTATE_FILES = { 167 "/data/test/unittest/resource/security_guard_update_event.cfg", 168 "/data/test/unittest/resource/security_guard_update_model.cfg", 169 "", 170 "", 171 "/data/test/unittest/resource/local_app_attribute_update.json.json", 172 "/data/test/unittest/resource/global_app_attribute_update.json.json", 173 "/data/test/unittest/resource/related_event_analysis_update.json" 174 }; 175 176 const std::vector<std::string> CONFIG_PRESET_FILES = { 177 "/data/test/unittest/resource/security_guard_preset_event.cfg", 178 "/data/test/unittest/resource/security_guard_preset_model.cfg" 179 }; 180 181 const std::string CONFIG_ROOT_PATH = "/data/test/unittest/resource/"; 182 } // namespace OHOS::Security::SecurityGuard 183 184 #endif // SECURITY_GUARD_CONFIG_DEFINE_H 185