1 /* 2 * Copyright (c) 2022 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 #define LOG_TAG "SystemChecker" 16 #include "system_checker.h" 17 #include "accesstoken_kit.h" 18 #include "log_print.h" 19 namespace OHOS { 20 namespace DistributedData { 21 using namespace Security::AccessToken; 22 __attribute__((used)) SystemChecker SystemChecker::instance_; SystemChecker()23SystemChecker::SystemChecker() noexcept 24 { 25 CheckerManager::GetInstance().RegisterPlugin( 26 "SystemChecker", [this]() -> auto { return this; }); 27 } 28 ~SystemChecker()29SystemChecker::~SystemChecker() 30 { 31 } 32 Initialize()33void SystemChecker::Initialize() 34 { 35 } 36 SetTrustInfo(const CheckerManager::Trust & trust)37bool SystemChecker::SetTrustInfo(const CheckerManager::Trust &trust) 38 { 39 trusts_[trust.bundleName] = trust.appId; 40 return true; 41 } 42 GetAppId(const CheckerManager::StoreInfo & info)43std::string SystemChecker::GetAppId(const CheckerManager::StoreInfo &info) 44 { 45 if (!IsValid(info)) { 46 return ""; 47 } 48 std::string appId = (trusts_.find(info.bundleName) != trusts_.end()) ? trusts_[info.bundleName] : info.bundleName; 49 ZLOGD("bundleName:%{public}s, appId:%{public}s", info.bundleName.c_str(), appId.c_str()); 50 return appId; 51 } 52 IsValid(const CheckerManager::StoreInfo & info)53bool SystemChecker::IsValid(const CheckerManager::StoreInfo &info) 54 { 55 auto type = AccessTokenKit::GetTokenTypeFlag(info.tokenId); 56 return (type == TOKEN_NATIVE || type == TOKEN_SHELL || info.uid == CheckerManager::ROOT_UID); 57 } 58 } // namespace DistributedData 59 } // namespace OHOS