1 /* 2 * Copyright (c) 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 #ifndef ROSEN_RENDER_SERVICE_BASE_RS_IPC_INTERFACE_CODE_ACCESS_VERIFIER_BASE_H 17 #define ROSEN_RENDER_SERVICE_BASE_RS_IPC_INTERFACE_CODE_ACCESS_VERIFIER_BASE_H 18 19 #include <memory> 20 #include <unordered_map> 21 #include <unordered_set> 22 23 #ifdef ENABLE_IPC_SECURITY 24 #include "ipc_skeleton.h" 25 #include "tokenid_kit.h" 26 #endif 27 28 #include "common/rs_macros.h" 29 #include "ipc_security/rs_ipc_interface_code_underlying_type.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 using TokenIdType = uint64_t; 34 35 class RSB_EXPORT RSInterfaceCodeAccessVerifierBase { 36 public: 37 virtual ~RSInterfaceCodeAccessVerifierBase() noexcept = default; 38 39 bool IsInterfaceCodeAccessible(CodeUnderlyingType code, const std::string& caller); 40 41 /* specify the initialization of accessMap_ in the derived class */ 42 virtual void InitializeAccessMap() = 0; 43 44 protected: 45 /* this class cannot be instantiated */ 46 RSInterfaceCodeAccessVerifierBase() = default; 47 48 /* specify the exclusive verification rules in the derived class */ 49 virtual bool IsExtraVerificationPassed(CodeUnderlyingType code, const std::string& caller) = 0; 50 51 /* specify tools for verifying the access right */ 52 TokenIdType GetCallingFullTokenID() const; 53 bool IsSystemApp() const; 54 55 std::unordered_map<CodeUnderlyingType, std::unordered_set<TokenIdType>> accessMap_; 56 57 private: 58 RSInterfaceCodeAccessVerifierBase(const RSInterfaceCodeAccessVerifierBase&) = delete; 59 RSInterfaceCodeAccessVerifierBase& operator=(const RSInterfaceCodeAccessVerifierBase&) = delete; 60 RSInterfaceCodeAccessVerifierBase(RSInterfaceCodeAccessVerifierBase&&) = delete; 61 RSInterfaceCodeAccessVerifierBase& operator=(RSInterfaceCodeAccessVerifierBase&&) = delete; 62 63 /* specify the communal verification rules in the base class */ 64 bool IsCommonVerificationPassed(CodeUnderlyingType code, const std::string& caller); 65 }; 66 } // namespace Rosen 67 } // namespace OHOS 68 #endif // ROSEN_RENDER_SERVICE_BASE_RS_IPC_INTERFACE_CODE_ACCESS_VERIFIER_BASE_H 69