1 /* 2 * Copyright (c) 2024 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 INTERFACES_INNER_API_DLP_UTILS_H 17 #define INTERFACES_INNER_API_DLP_UTILS_H 18 19 #include "bundle_mgr_interface.h" 20 #include "bundle_mgr_proxy.h" 21 #include "system_ability_definition.h" 22 #include "iservice_registry.h" 23 #include "os_account_manager.h" 24 #include "file_operator.h" 25 26 namespace OHOS { 27 namespace Security { 28 namespace DlpPermission { 29 30 static const std::string DLP_AUTH_POLICY = "/system/etc/dlp_auth_policy.json"; 31 static const std::string DLP_DEFAULT_AUTH_POLICY = "default"; 32 static const std::string DLP_HIAE_TYPE = "mkv"; 33 static const uint32_t MIN_REALY_TYPE_LENGTH = 2; 34 static const uint32_t MAX_REALY_TYPE_LENGTH = 5; 35 36 static const std::unordered_map<std::string, uint32_t> TYPE_TO_NUM_MAP = { 37 {"txt", 1}, 38 {"pdf", 2}, 39 {"doc", 3}, 40 {"docx", 4}, 41 {"ppt", 5}, 42 {"pptx", 6}, 43 {"xls", 7}, 44 {"xlsx", 8}, 45 {"bmp", 9}, 46 {"bm", 10}, 47 {"dng", 11}, 48 {"gif", 12}, 49 {"heic", 13}, 50 {"heics", 14}, 51 {"heif", 15}, 52 {"heifs", 16}, 53 {"hif", 17}, 54 {"jpg", 18}, 55 {"jpeg", 19}, 56 {"jpe", 20}, 57 {"png", 21}, 58 {"webp", 22}, 59 {"cur", 23}, 60 {"raf", 24}, 61 {"ico", 25}, 62 {"nrw", 26}, 63 {"rw2", 27}, 64 {"pef", 28}, 65 {"srw", 29}, 66 {"svg", 30}, 67 {"arw", 31}, 68 {"3gpp2", 32}, 69 {"3gp2", 33}, 70 {"3g2", 34}, 71 {"3gpp", 35}, 72 {"3gp", 36}, 73 {"avi", 37}, 74 {"m4v", 38}, 75 {"f4v", 39}, 76 {"mp4v", 40}, 77 {"mpeg4", 41}, 78 {"mp4", 42}, 79 {"m2ts", 43}, 80 {"mts", 44}, 81 {"ts", 45}, 82 {"vt", 46}, 83 {"wrf", 47}, 84 {"mpeg", 48}, 85 {"mpeg2", 49}, 86 {"mpv2", 50}, 87 {"mp2v", 51}, 88 {"m2v", 52}, 89 {"m2t", 53}, 90 {"mpeg1", 54}, 91 {"mpv1", 55}, 92 {"mp1v", 56}, 93 {"m1v", 57}, 94 {"mpg", 58}, 95 {"mov", 59}, 96 {"mkv", 60}, 97 {"webm", 61}, 98 {"h264", 62}, 99 {"wbmp", 63}, 100 {"nef", 64}, 101 {"cr2", 65}, 102 }; 103 104 static const std::unordered_map<uint32_t, std::string> NUM_TO_TYPE_MAP = { 105 {1, "txt"}, 106 {2, "pdf"}, 107 {3, "doc"}, 108 {4, "docx"}, 109 {5, "ppt"}, 110 {6, "pptx"}, 111 {7, "xls"}, 112 {8, "xlsx"}, 113 {9, "bmp"}, 114 {10, "bm"}, 115 {11, "dng"}, 116 {12, "gif"}, 117 {13, "heic"}, 118 {14, "heics"}, 119 {15, "heif"}, 120 {16, "heifs"}, 121 {17, "hif"}, 122 {18, "jpg"}, 123 {19, "jpeg"}, 124 {20, "jpe"}, 125 {21, "png"}, 126 {22, "webp"}, 127 {23, "cur"}, 128 {24, "raf"}, 129 {25, "ico"}, 130 {26, "nrw"}, 131 {27, "rw2"}, 132 {28, "pef"}, 133 {29, "srw"}, 134 {30, "svg"}, 135 {31, "arw"}, 136 {32, "3gpp2"}, 137 {33, "3gp2"}, 138 {34, "3g2"}, 139 {35, "3gpp"}, 140 {36, "3gp"}, 141 {37, "avi"}, 142 {38, "m4v"}, 143 {39, "f4v"}, 144 {40, "mp4v"}, 145 {41, "mpeg4"}, 146 {42, "mp4"}, 147 {43, "m2ts"}, 148 {44, "mts"}, 149 {45, "ts"}, 150 {46, "vt"}, 151 {47, "wrf"}, 152 {48, "mpeg"}, 153 {49, "mpeg2"}, 154 {50, "mpv2"}, 155 {51, "mp2v"}, 156 {52, "m2v"}, 157 {53, "m2t"}, 158 {54, "mpeg1"}, 159 {55, "mpv1"}, 160 {56, "mp1v"}, 161 {57, "m1v"}, 162 {58, "mpg"}, 163 {59, "mov"}, 164 {60, "mkv"}, 165 {61, "webm"}, 166 {62, "h264"}, 167 {63, "wbmp"}, 168 {64, "nef"}, 169 {65, "cr2"}, 170 }; 171 172 static const std::unordered_map<std::string, std::string> FILE_TYPE_MAP = { 173 {"txt", "support_txt_dlp"}, 174 {"pdf", "support_pdf_dlp"}, 175 {"doc", "support_office_dlp"}, 176 {"docx", "support_office_dlp"}, 177 {"ppt", "support_office_dlp"}, 178 {"pptx", "support_office_dlp"}, 179 {"xls", "support_office_dlp"}, 180 {"xlsx", "support_office_dlp"}, 181 {"bmp", "support_photo_dlp"}, 182 {"bm", "support_photo_dlp"}, 183 {"dng", "support_photo_dlp"}, 184 {"gif", "support_photo_dlp"}, 185 {"heic", "support_photo_dlp"}, 186 {"heics", "support_photo_dlp"}, 187 {"heif", "support_photo_dlp"}, 188 {"heifs", "support_photo_dlp"}, 189 {"hif", "support_photo_dlp"}, 190 {"jpg", "support_photo_dlp"}, 191 {"jpeg", "support_photo_dlp"}, 192 {"jpe", "support_photo_dlp"}, 193 {"png", "support_photo_dlp"}, 194 {"webp", "support_photo_dlp"}, 195 {"cur", "support_photo_dlp"}, 196 {"raf", "support_photo_dlp"}, 197 {"ico", "support_photo_dlp"}, 198 {"nrw", "support_photo_dlp"}, 199 {"rw2", "support_photo_dlp"}, 200 {"pef", "support_photo_dlp"}, 201 {"srw", "support_photo_dlp"}, 202 {"svg", "support_photo_dlp"}, 203 {"arw", "support_photo_dlp"}, 204 {"3gpp2", "support_video_dlp"}, 205 {"3gp2", "support_video_dlp"}, 206 {"3g2", "support_video_dlp"}, 207 {"3gpp", "support_video_dlp"}, 208 {"3gp", "support_video_dlp"}, 209 {"avi", "support_video_dlp"}, 210 {"m4v", "support_video_dlp"}, 211 {"f4v", "support_video_dlp"}, 212 {"mp4v", "support_video_dlp"}, 213 {"mpeg4", "support_video_dlp"}, 214 {"mp4", "support_video_dlp"}, 215 {"m2ts", "support_video_dlp"}, 216 {"mts", "support_video_dlp"}, 217 {"ts", "support_video_dlp"}, 218 {"vt", "support_video_dlp"}, 219 {"wrf", "support_video_dlp"}, 220 {"mpeg", "support_video_dlp"}, 221 {"mpeg2", "support_video_dlp"}, 222 {"mpv2", "support_video_dlp"}, 223 {"mp2v", "support_video_dlp"}, 224 {"m2v", "support_video_dlp"}, 225 {"m2t", "support_video_dlp"}, 226 {"mpeg1", "support_video_dlp"}, 227 {"mpv1", "support_video_dlp"}, 228 {"mp1v", "support_video_dlp"}, 229 {"m1v", "support_video_dlp"}, 230 {"mpg", "support_video_dlp"}, 231 {"mov", "support_video_dlp"}, 232 {"mkv", "support_video_dlp"}, 233 {"webm", "support_video_dlp"}, 234 {"h264", "support_video_dlp"}, 235 {"wbmp", "support_photo_dlp"}, 236 {"nef", "support_photo_dlp"}, 237 {"cr2", "support_photo_dlp"}, 238 }; 239 240 class DlpUtils { 241 public: 242 static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy(void); 243 static bool GetAuthPolicyWithType(const std::string &cfgFile, const std::string &type, 244 std::vector<std::string> &authPolicy); 245 static std::string GetFileTypeBySuffix(const std::string& suffix, const bool isFromUriName); 246 static std::string GetDlpFileRealSuffix(const std::string& dlpFileName, bool& isFromUriName); 247 static int32_t GetFileNameWithFd(const int32_t& fd, std::string& srcFileName); 248 static int32_t GetFileNameWithDlpFd(const int32_t &fd, std::string &srcFileName); 249 static std::string GetRealTypeWithRawFile(const int32_t& fd); 250 static int32_t GetFilePathWithFd(const int32_t& fd, std::string& srcFilePath); 251 static std::string ToLowerString(const std::string& str); 252 static std::string GetRealTypeWithFd(const int32_t& fd, bool& isFromUriName); 253 static bool GetBundleInfoWithBundleName(const std::string &bundleName, int32_t flag, 254 AppExecFwk::BundleInfo &bundleInfo, int32_t userId); 255 static bool GetFileType(const std::string& realFileType); 256 static bool GetUserIdByForegroundAccount(int32_t &userId); 257 static std::string GetRealTypeForEnterpriseWithFd(const int32_t& fd, bool& isFromUriName); 258 }; 259 } // namespace DlpPermission 260 } // namespace Security 261 } // namespace OHOS 262 #endif /* INTERFACES_INNER_API_DLP_UTILS_H */ 263