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 #include "accesstoken_kit.h"
17 
18 namespace OHOS {
19 namespace Security {
20 namespace AccessToken {
21 #ifdef BUNDLE_PERMISSION_DEF_LIST
22 
VerifyAccessToken(AccessTokenID tokenID,const std::string & permissionName)23 int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName)
24 {
25     if (tokenID == 0) {
26         return PermissionState::PERMISSION_DENIED;
27     } else {
28         return 0;
29     }
30 }
31 
GetTokenTypeFlag(AccessTokenID tokenID)32 ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID)
33 {
34     switch (tokenID) {
35         case TOKEN_HAP: {
36             return TOKEN_HAP;
37         }
38         case TOKEN_NATIVE: {
39             return TOKEN_NATIVE;
40         }
41         case TOKEN_SHELL: {
42             return TOKEN_SHELL;
43         }
44         default: {
45             return TOKEN_INVALID;
46         }
47     }
48 }
49 #else
50 int AccessTokenKit::GetReqPermissions(AccessTokenID tokenID, std::vector<PermissionStateFull>& reqPermList,
51     bool isSystemGrant)
52 {
53     return 0;
54 }
55 
56 int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName)
57 {
58     if (tokenID == 0) {
59         return PermissionState::PERMISSION_DENIED;
60     } else {
61         return 0;
62     }
63 }
64 
65 ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID)
66 {
67 #ifdef BUNDLE_FRAMEWORK_SYSTEM_APP_FALSE
68     switch (tokenID) {
69         case TOKEN_HAP: {
70             return TOKEN_HAP;
71         }
72         case TOKEN_NATIVE: {
73             return TOKEN_NATIVE;
74         }
75         case TOKEN_SHELL: {
76             return TOKEN_SHELL;
77         }
78         default: {
79             return TOKEN_INVALID;
80         }
81     }
82 #else
83     switch (tokenID) {
84         case TOKEN_HAP: {
85             return TOKEN_HAP;
86         }
87         case TOKEN_NATIVE: {
88             return TOKEN_NATIVE;
89         }
90         case TOKEN_SHELL: {
91             return TOKEN_SHELL;
92         }
93         default: {
94             return TOKEN_INVALID;
95         }
96     }
97 #endif
98 }
99 #endif
100 
VerifyAccessToken(AccessTokenID callerTokenID,AccessTokenID firstTokenID,const std::string & permissionName)101 int AccessTokenKit::VerifyAccessToken(
102     AccessTokenID callerTokenID, AccessTokenID firstTokenID, const std::string& permissionName)
103 {
104     return 0;
105 }
GetNativeTokenInfo(AccessTokenID tokenID,NativeTokenInfo & nativeTokenInfo)106 int AccessTokenKit::GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo &nativeTokenInfo)
107 {
108     if (tokenID == TOKEN_SHELL) {
109         return TOKEN_NATIVE;
110     } else {
111         nativeTokenInfo.processName = "foundation";
112         return 0;
113     }
114 }
115 }
116 }
117 }