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 
16 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H
18 
19 #include <vector>
20 #include <string>
21 
22 namespace OHOS {
23 namespace Security {
24 namespace AccessToken {
25 typedef unsigned int AccessTokenID;
26 typedef unsigned int AccessTokenAttr;
27 static const int DEFAULT_TOKEN_VERSION = 1;
28 static const int FIRSTCALLER_TOKENID_DEFAULT = 0;
29 
30 enum AccessTokenKitRet {
31     RET_FAILED = -1,
32     RET_SUCCESS = 0,
33 };
34 
35 typedef struct {
36     unsigned int tokenUniqueID : 24;
37     unsigned int res : 3;
38     unsigned int type : 2;
39     unsigned int version : 3;
40 } AccessTokenIDInner;
41 
42 typedef enum TypeATokenTypeEnum {
43     TOKEN_INVALID = -1,
44     TOKEN_HAP = 0,
45     TOKEN_NATIVE,
46     TOKEN_SHELL,
47 } ATokenTypeEnum;
48 
49 typedef enum TypeATokenAplEnum {
50     APL_NORMAL = 1,
51     APL_SYSTEM_BASIC = 2,
52     APL_SYSTEM_CORE = 3,
53 } ATokenAplEnum;
54 
55 typedef union {
56     unsigned long long tokenIDEx;
57     struct {
58         AccessTokenID tokenID;
59         AccessTokenAttr tokenAttr;
60     } tokenIdExStruct;
61 } AccessTokenIDEx;
62 
63 typedef enum TypePermissionState {
64     PERMISSION_DENIED = -1,
65     PERMISSION_GRANTED = 0,
66 } PermissionState;
67 
68 typedef enum TypeGrantMode {
69     USER_GRANT = 0,
70     SYSTEM_GRANT = 1,
71 } GrantMode;
72 
73 typedef enum TypeATokenAvailableTypeEnum {
74     INVALID = 0,
75     NORMAL = 1,
76     MDM = 2,
77 } ATokenAvailableTypeEnum;
78 
79 typedef enum TypePermissionFlag {
80     PERMISSION_DEFAULT_FLAG = 0,
81     PERMISSION_USER_SET = 1 << 0,
82     PERMISSION_USER_FIXED = 1 << 1,
83     PERMISSION_SYSTEM_FIXED = 1 << 2,
84     PERMISSION_GRANTED_BY_POLICY = 1 << 3,
85 } PermissionFlag;
86 
87 class NativeTokenInfo final {
88 public:
89     ATokenTypeEnum apl;
90     std::string processName;
91     std::vector<std::string> dcap;
92     AccessTokenID tokenID;
93     AccessTokenAttr tokenAttr;
94     std::vector<std::string> nativeAcls;
95 };
96 
97 class PermissionDef final {
98 public:
99     std::string permissionName;
100     std::string bundleName;
101     int grantMode;
102     TypeATokenAplEnum availableLevel;
103     bool provisionEnable;
104     bool distributedSceneEnable;
105     std::string label;
106     int labelId;
107     std::string description;
108     int descriptionId;
109     ATokenAvailableTypeEnum availableType = ATokenAvailableTypeEnum::NORMAL;
110 };
111 
112 class PermissionStateFull final {
113 public:
114     std::string permissionName;
115     bool isGeneral;
116     std::vector<std::string> resDeviceID;
117     std::vector<int> grantStatus;
118     std::vector<int> grantFlags;
119 };
120 
121 class HapInfoParams final {
122 public:
123     int userID;
124     std::string bundleName;
125     /** instance index */
126     int instIndex;
127     /**
128      * dlp type, for details about the valid values,
129      * see the definition of HapDlpType in the access_token.h file.
130      */
131     int dlpType;
132     std::string appIDDesc;
133     /** which version of the SDK is used to develop the hap */
134     int32_t apiVersion;
135     /** indicates whether the hap is a system app */
136     bool isSystemApp;
137     /* app type */
138     std::string appDistributionType;
139 };
140 
141 /**
142  * @brief Declares hap info params class
143  */
144 class UpdateHapInfoParams final {
145 public:
146     std::string appIDDesc;
147     /** which version of the SDK is used to develop the hap */
148     int32_t apiVersion;
149     /** indicates whether the hap is a system app */
150     bool isSystemApp;
151     /* app type */
152     std::string appDistributionType;
153 };
154 
155 class PreAuthorizationInfo final {
156 public:
157     std::string permissionName;
158     /** Whether the pre-authorization is non-cancelable */
159     bool userCancelable = false;
160 };
161 class HapPolicyParams final {
162 public:
163     /**
164      * apl level, for details about the valid values,
165      * see the definition of ATokenAplEnum in the access_token.h file.
166      */
167     ATokenAplEnum apl;
168     std::string domain;
169     std::vector<PermissionDef> permList;
170     std::vector<PermissionStateFull> permStateList;
171     std::vector<std::string> aclRequestedList;
172     std::vector<PreAuthorizationInfo> preAuthorizationInfo;
173 };
174 } // namespace AccessToken
175 } // namespace Security
176 } // namespace OHOS
177 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H