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 class NativeTokenInfoInner final { 34 public: 35 NativeTokenInfoInner(); 36 NativeTokenInfoInner(NativeTokenInfo& info, 37 const std::vector<PermissionStateFull>& permStateList); 38 virtual ~NativeTokenInfoInner(); 39 40 int Init(AccessTokenID id, const std::string& processName, int apl, 41 const std::vector<std::string>& dcap, 42 const std::vector<std::string>& nativeAcls, 43 const std::vector<PermissionStateFull>& permStateList); 44 void StoreNativeInfo(std::vector<GenericValues>& valueList, 45 std::vector<GenericValues>& permStateValues) const; 46 void TranslateToNativeTokenInfo(NativeTokenInfo& infoParcel) const; 47 void SetDcaps(const std::string& dcapStr); 48 void SetNativeAcls(const std::string& AclsStr); 49 void ToString(std::string& info) const; 50 int RestoreNativeTokenInfo(AccessTokenID tokenId, const GenericValues& inGenericValues, 51 const std::vector<GenericValues>& permStateRes); 52 void Update(AccessTokenID tokenId, const std::string& processName, 53 int apl, const std::vector<std::string>& dcap, 54 const std::vector<std::string>& nativeAcls); 55 56 std::vector<std::string> GetDcap() const; 57 std::vector<std::string> GetNativeAcls() const; 58 AccessTokenID GetTokenID() const; 59 std::string GetProcessName() const; 60 NativeTokenInfo GetNativeTokenInfo() const; 61 std::shared_ptr<PermissionPolicySet> GetNativeInfoPermissionPolicySet() const; 62 bool IsRemote() const; 63 void SetRemote(bool isRemote); 64 65 private: 66 int TranslationIntoGenericValues(GenericValues& outGenericValues) const; 67 std::string DcapToString(const std::vector<std::string>& dcap) const; 68 std::string NativeAclsToString(const std::vector<std::string>& nativeAcls) const; 69 70 // true means sync from remote. 71 bool isRemote_; 72 NativeTokenInfo tokenInfoBasic_; 73 std::shared_ptr<PermissionPolicySet> permPolicySet_; 74 }; 75 } // namespace AccessToken 76 } // namespace Security 77 } // namespace OHOS 78 #endif // ACCESSTOKEN_NATIVE_TOKEN_INFO_INNER_H 79