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