1 /*
2  * Copyright (c) 2021-2023 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 /**
17  * @addtogroup AccessToken
18  * @{
19  *
20  * @brief Provides permission management interfaces.
21  *
22  * Provides tokenID-based application permission verification mechanism.
23  * When an application accesses sensitive data or APIs, this module can check
24  * whether the application has the corresponding permission. Allows applications
25  * to query their access token information or APL levcels based on token IDs.
26  *
27  * @since 7.0
28  * @version 7.0
29  */
30 
31 /**
32  * @file hap_token_info.h
33  *
34  * @brief Declares hap token infos.
35  *
36  * @since 7.0
37  * @version 7.0
38  */
39 
40 #ifndef ACCESSTOKEN_HAP_TOKEN_INFO_H
41 #define ACCESSTOKEN_HAP_TOKEN_INFO_H
42 
43 #include "access_token.h"
44 #include "permission_def.h"
45 #include "permission_state_full.h"
46 #include <string>
47 #include <vector>
48 
49 namespace OHOS {
50 namespace Security {
51 namespace AccessToken {
52 /**
53  * @brief Declares hap info params class
54  */
55 class HapInfoParams final {
56 public:
57     int userID;
58     std::string bundleName;
59     /** instance index */
60     int instIndex;
61     /**
62      * dlp type, for details about the valid values,
63      * see the definition of HapDlpType in the access_token.h file.
64      */
65     int dlpType;
66     std::string appIDDesc;
67     /** which version of the SDK is used to develop the hap */
68     int32_t apiVersion;
69     /** indicates whether the hap is a system app */
70     bool isSystemApp;
71     /* app type */
72     std::string appDistributionType;
73 };
74 
75 /**
76  * @brief Declares hap info params class
77  */
78 class UpdateHapInfoParams final {
79 public:
80     std::string appIDDesc;
81     /** which version of the SDK is used to develop the hap */
82     int32_t apiVersion;
83     /** indicates whether the hap is a system app */
84     bool isSystemApp;
85     /* app type */
86     std::string appDistributionType;
87 };
88 
89 /**
90  * @brief Declares hap token info class
91  */
92 class HapTokenInfo final {
93 public:
94     /**
95      * apl level, for details about the valid values,
96      * see the definition of ATokenAplEnum in the access_token.h file.
97      */
98     ATokenAplEnum apl;
99     char ver;
100     int userID;
101     std::string bundleName;
102     /** which version of the SDK is used to develop this hap */
103     int32_t apiVersion;
104     /** instance index */
105     int instIndex;
106     /**
107      * dlp type, for details about the valid values,
108      * see the definition of HapDlpType in the access_token.h file.
109      */
110     int dlpType;
111     std::string appID;
112     std::string deviceID;
113     AccessTokenID tokenID;
114     /** token attribute */
115     AccessTokenAttr tokenAttr;
116 };
117 
118 /**
119  * @brief Declares hap token info for distributed synchronize class
120  */
121 class HapTokenInfoForSync final {
122 public:
123     /** hap token info */
124     HapTokenInfo baseInfo;
125     /** permission state list */
126     std::vector<PermissionStateFull> permStateList;
127 };
128 
129 /**
130  * @brief Declares hap base token info class
131  */
132 class HapBaseInfo final {
133 public:
134     int32_t userID;
135     std::string bundleName = "";
136     /** instance index */
137     int32_t instIndex = 0;
138 };
139 
140 /**
141  * @brief Pre-authorization token info class
142  */
143 class PreAuthorizationInfo final {
144 public:
145     std::string permissionName;
146     /** Whether the pre-authorization is non-cancelable */
147     bool userCancelable = false;
148 };
149 /**
150  * @brief Declares hap policy params class
151  */
152 class HapPolicyParams final {
153 public:
154     /**
155      * apl level, for details about the valid values,
156      * see the definition of ATokenAplEnum in the access_token.h file.
157      */
158     ATokenAplEnum apl;
159     std::string domain;
160     std::vector<PermissionDef> permList;
161     std::vector<PermissionStateFull> permStateList;
162     std::vector<std::string> aclRequestedList;
163     std::vector<PreAuthorizationInfo> preAuthorizationInfo;
164 };
165 
166 } // namespace AccessToken
167 } // namespace Security
168 } // namespace OHOS
169 #endif // ACCESSTOKEN_HAP_TOKEN_INFO_H
170