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