• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 ACCESSTOKEN_NATIVE_TOKEN_INFO_INNER_H
17 #define ACCESSTOKEN_NATIVE_TOKEN_INFO_INNER_H
18 
19 #include <string>
20 #include <vector>
21 #include "access_token.h"
22 #include "generic_values.h"
23 #include "native_token_info.h"
24 #include "permission_policy_set.h"
25 #include "permission_state_full.h"
26 
27 namespace OHOS {
28 namespace Security {
29 namespace AccessToken {
30 static const int MAX_DCAPS_NUM = 32;
31 static const int MAX_REQ_PERM_NUM = 32;
32 
33 struct TokenInfo {
34     AccessTokenID id;
35     std::string processName;
36     int apl;
37 };
38 
39 class NativeTokenInfoInner final {
40 public:
41     NativeTokenInfoInner();
42     NativeTokenInfoInner(NativeTokenInfo& info,
43         const std::vector<PermissionStateFull>& permStateList);
44     virtual ~NativeTokenInfoInner();
45 
46     int Init(const TokenInfo& tokenInfo, const std::vector<std::string>& dcap,
47         const std::vector<std::string>& nativeAcls,
48         const std::vector<PermissionStateFull>& permStateList);
49     void StoreNativeInfo(std::vector<GenericValues>& valueList,
50         std::vector<GenericValues>& permStateValues) const;
51     void TranslateToNativeTokenInfo(NativeTokenInfo& infoParcel) const;
52     void SetDcaps(const std::string& dcapStr);
53     void SetNativeAcls(const std::string& AclsStr);
54     void ToString(std::string& info) const;
55     int RestoreNativeTokenInfo(AccessTokenID tokenId, const GenericValues& inGenericValues,
56         const std::vector<GenericValues>& permStateRes);
57     void Update(AccessTokenID tokenId, const std::string& processName,
58         int apl, const std::vector<std::string>& dcap,
59         const std::vector<std::string>& nativeAcls);
60 
61     std::vector<std::string> GetDcap() const;
62     std::vector<std::string> GetNativeAcls() const;
63     AccessTokenID GetTokenID() const;
64     std::string GetProcessName() const;
65     NativeTokenInfo GetNativeTokenInfo() const;
66     std::shared_ptr<PermissionPolicySet> GetNativeInfoPermissionPolicySet() const;
67     bool IsRemote() const;
68     void SetRemote(bool isRemote);
69 
70 private:
71     int TranslationIntoGenericValues(GenericValues& outGenericValues) const;
72     std::string DcapToString(const std::vector<std::string>& dcap) const;
73     std::string NativeAclsToString(const std::vector<std::string>& nativeAcls) const;
74 
75     // true means sync from remote.
76     bool isRemote_;
77     NativeTokenInfo tokenInfoBasic_;
78     std::shared_ptr<PermissionPolicySet> permPolicySet_;
79 };
80 } // namespace AccessToken
81 } // namespace Security
82 } // namespace OHOS
83 #endif // ACCESSTOKEN_NATIVE_TOKEN_INFO_INNER_H
84