1 /*
2 * Copyright (c) 2023-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 #include "app_module_checker.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "module_checker_delegate.h"
20 #include "utils/log.h"
21
22 #include <algorithm>
23 #include <cctype>
24 #include <string>
25
AppModuleChecker(int32_t extensionType,const std::unordered_map<int32_t,std::unordered_set<std::string>> & extensionBlocklist)26 AppModuleChecker::AppModuleChecker(int32_t extensionType,
27 const std::unordered_map<int32_t, std::unordered_set<std::string>>& extensionBlocklist)
28 {
29 auto iter = extensionBlocklist.find(extensionType);
30 if (iter == extensionBlocklist.end()) {
31 return;
32 }
33 TAG_LOGD(AAFwkTag::ABILITY, "transform begin");
34 for (const auto& module: iter->second) {
35 std::string lowermodule;
36 lowermodule.reserve(module.size());
37 std::transform(module.cbegin(), module.cend(), std::back_inserter(lowermodule),
38 [](unsigned char c) { return std::tolower(c); });
39 blockList_.emplace(std::move(lowermodule));
40 }
41 TAG_LOGD(AAFwkTag::ABILITY, "transform end");
42 }
43
CheckModuleLoadable(const char * moduleName,std::unique_ptr<ApiAllowListChecker> & apiAllowListChecker,bool isAppModule)44 bool AppModuleChecker::CheckModuleLoadable(const char *moduleName,
45 std::unique_ptr<ApiAllowListChecker> &apiAllowListChecker,
46 bool isAppModule)
47 {
48 apiAllowListChecker = nullptr;
49 TAG_LOGD(AAFwkTag::ABILITY, "check blocklist, moduleName:%{public}s", moduleName);
50
51 std::string strModuleName(moduleName);
52 std::string lowerModuleName;
53 lowerModuleName.reserve(strModuleName.size());
54 std::transform(strModuleName.cbegin(), strModuleName.cend(), std::back_inserter(lowerModuleName),
55 [](unsigned char c) { return std::tolower(c); });
56 if (blockList_.find(lowerModuleName) == blockList_.end()) {
57 return true;
58 }
59 return false;
60 }
61
DiskCheckOnly()62 bool AppModuleChecker::DiskCheckOnly()
63 {
64 return false;
65 }