• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ACCESSTOKEN_CONFIG_POLICY_LOADER_H
17 #define ACCESSTOKEN_CONFIG_POLICY_LOADER_H
18 
19 #include <string>
20 #include <vector>
21 #include "hap_token_info.h"
22 #include "permission_def.h"
23 #include "native_token_info_base.h"
24 #include "permission_dlp_mode.h"
25 
26 namespace OHOS {
27 namespace Security {
28 namespace AccessToken {
29 const static std::string CONFIG_PARSE_LIBPATH = "libaccesstoken_json_parse.z.so";
30 struct AccessTokenServiceConfig final {
31     std::string grantBundleName;
32     std::string grantAbilityName;
33     std::string grantServiceAbilityName;
34     std::string permStateAbilityName;
35     std::string globalSwitchAbilityName;
36     int32_t cancelTime = 0;
37     std::string applicationSettingAbilityName;
38     std::vector<std::string> enterpriseNormalPermissiveBundles;
39 };
40 
41 struct PrivacyServiceConfig final {
42     int32_t sizeMaxImum;
43     int32_t agingTime;
44     std::string globalDialogBundleName;
45     std::string globalDialogAbilityName;
46 };
47 
48 struct TokenSyncServiceConfig final {
49     int32_t sendRequestRepeatTimes;
50 };
51 
52 struct AccessTokenConfigValue {
53     AccessTokenServiceConfig atConfig;
54     PrivacyServiceConfig pConfig;
55     TokenSyncServiceConfig tsConfig;
56 };
57 
58 enum ServiceType {
59     ACCESSTOKEN_SERVICE = 0,
60     PRIVACY_SERVICE,
61     TOKENSYNC_SERVICE,
62 };
63 
64 struct PermissionDefParseRet {
65     PermissionDef permDef;
66     bool isSuccessful = false;
67 };
68 
69 class ConfigPolicyLoaderInterface {
70 public:
ConfigPolicyLoaderInterface()71     ConfigPolicyLoaderInterface() {}
~ConfigPolicyLoaderInterface()72     virtual ~ConfigPolicyLoaderInterface() {}
73     virtual bool GetConfigValue(const ServiceType& type, AccessTokenConfigValue& config);
74     virtual int32_t GetAllNativeTokenInfo(std::vector<NativeTokenInfoBase>& tokenInfos);
75     virtual int32_t GetDlpPermissions(std::vector<PermissionDlpMode>& dlpPerms);
76     virtual std::string DumpNativeTokenInfo(const NativeTokenInfoBase& native);
77     virtual std::string DumpHapTokenInfo(const HapTokenInfo& hapInfo, bool isRemote, bool isPermDialogForbidden,
78         const std::vector<PermissionStatus>& permStateList);
79 };
80 
81 class ConfigPolicLoader final: public ConfigPolicyLoaderInterface {
82     bool GetConfigValue(const ServiceType& type, AccessTokenConfigValue& config);
83     int32_t GetAllNativeTokenInfo(std::vector<NativeTokenInfoBase>& tokenInfos);
84     int32_t GetDlpPermissions(std::vector<PermissionDlpMode>& dlpPerms);
85     std::string DumpNativeTokenInfo(const NativeTokenInfoBase& native);
86     std::string DumpHapTokenInfo(const HapTokenInfo& hapInfo, bool isRemote, bool isPermDialogForbidden,
87         const std::vector<PermissionStatus>& permStateList);
88 private:
89 #ifdef CUSTOMIZATION_CONFIG_POLICY_ENABLE
90     void GetConfigFilePathList(std::vector<std::string>& pathList);
91     bool GetConfigValueFromFile(const ServiceType& type, const std::string& fileContent,
92         AccessTokenConfigValue& config);
93 #endif // CUSTOMIZATION_CONFIG_POLICY_ENABLE
94     bool ParserNativeRawData(const std::string& nativeRawData, std::vector<NativeTokenInfoBase>& tokenInfos);
95     bool ParserDlpPermsRawData(const std::string& dlpPermsRawData, std::vector<PermissionDlpMode>& dlpPerms);
96     int32_t ReadCfgFile(const std::string& file, std::string& rawData);
97     bool IsDirExsit(const std::string& file);
98 };
99 
100 #ifdef __cplusplus
101 extern "C" {
102 #endif
103     void* Create();
104     void Destroy(void* loaderPtr);
105 #ifdef __cplusplus
106 }
107 #endif
108 } // namespace AccessToken
109 } // namespace Security
110 } // namespace OHOS
111 #endif // ACCESSTOKEN_CONFIG_POLICY_LOADER_H
112