• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 #ifndef SECURITY_COMPONENT_ENHANCE_ADAPTER_H
16 #define SECURITY_COMPONENT_ENHANCE_ADAPTER_H
17 
18 #include <mutex>
19 #include "iremote_object.h"
20 #include "nlohmann/json.hpp"
21 #include "sec_comp_base.h"
22 #include "sec_comp_info.h"
23 #include "sec_comp_rawdata.h"
24 
25 namespace OHOS {
26 namespace Security {
27 namespace SecurityComponent {
28 enum EnhanceInterfaceType {
29     SEC_COMP_ENHANCE_INPUT_INTERFACE = 0,
30     SEC_COMP_ENHANCE_SRV_INTERFACE = 1,
31     SEC_COMP_ENHANCE_CLIENT_INTERFACE = 2,
32 };
33 
34 // for multimodalinput to add enhance data to PointerEvent
35 class SecCompInputEnhanceInterface {
36 public:
37     // for multimodalinput to set enhance cfg which is from security component enhance service
38     virtual int32_t SetEnhanceCfg(uint8_t* cfg, uint32_t cfgLen) = 0;
39 
40     // for multimodalinput to get enhance data
41     virtual int32_t GetPointerEventEnhanceData(void* data, uint32_t dataLen,
42         uint8_t* enhanceData, uint32_t& enHancedataLen) = 0;
43 };
44 
45 // for security component service to send command to enhance service
46 class SecCompSrvEnhanceInterface {
47 public:
48     // enable input enhance, then enhance service send config to multimodalinput
49     virtual int32_t EnableInputEnhance() = 0;
50 
51     // disable input enhance
52     virtual int32_t DisableInputEnhance() = 0;
53 
54     // send click event to enhance service for checking extra data validity
55     virtual int32_t CheckExtraInfo(const SecCompClickEvent& clickInfo) = 0;
56 
57     // send component info to enhance service for checking its validity
58     virtual int32_t CheckComponentInfoEnhance(int32_t pid, std::shared_ptr<SecCompBase>& compInfo,
59         const nlohmann::json& jsonComponent) = 0;
60 
61     // start enhance service
62     virtual void StartEnhanceService() = 0;
63 
64     // exit enhance service
65     virtual void ExitEnhanceService() = 0;
66 
67     // notify process died
68     virtual void NotifyProcessDied(int32_t pid) = 0;
69 
70     // notify process registered
71     virtual void AddSecurityComponentProcess(int32_t pid) = 0;
72 
73     virtual bool EnhanceSrvSerialize(MessageParcel& input, SecCompRawdata& output) = 0;
74     virtual bool EnhanceSrvDeserialize(SecCompRawdata& input, MessageParcel& output) = 0;
75 };
76 
77 // for client
78 class SecCompClientEnhanceInterface {
79 public:
80     // preprocess component info which is send to security component service, e.g. RegisterSecurityComponent
81     virtual bool EnhanceDataPreprocess(const uintptr_t caller, std::string& componentInfo) = 0;
82     virtual bool EnhanceDataPreprocess(const uintptr_t caller, int32_t scId, std::string& componentInfo) = 0;
83 
84     virtual bool EnhanceClientSerialize(const uintptr_t caller, MessageParcel& input, SecCompRawdata& output) = 0;
85     virtual bool EnhanceClientDeserialize(const uintptr_t caller, SecCompRawdata& input, MessageParcel& output) = 0;
86 
87     // regiter scid to enhance client
88     virtual void RegisterScIdEnhance(const uintptr_t caller, int32_t scId) = 0;
89     // unregiter scid to enhance client
90     virtual void UnregisterScIdEnhance(const uintptr_t caller, int32_t scId) = 0;
91 };
92 
93 #ifndef SEC_COMP_SERVICE_COMPILE_ENABLE
94 class SecCompEnhanceAdapter final {
95 #else
96 class __attribute__((visibility("default"))) SecCompEnhanceAdapter final {
97 #endif
98 public:
99     static void InitEnhanceHandler(EnhanceInterfaceType type);
100     static int32_t SetEnhanceCfg(uint8_t* cfg, uint32_t cfgLen);
101     static int32_t GetPointerEventEnhanceData(void* data, uint32_t dataLen,
102         uint8_t* enhanceData, uint32_t& enHancedataLen);
103 
104     static int32_t CheckExtraInfo(const SecCompClickEvent& clickInfo);
105     static int32_t EnableInputEnhance();
106     static int32_t DisableInputEnhance();
107     static int32_t CheckComponentInfoEnhance(int32_t pid, std::shared_ptr<SecCompBase>& compInfo,
108         const nlohmann::json& jsonComponent);
109     static void StartEnhanceService();
110     static void ExitEnhanceService();
111     static void NotifyProcessDied(int32_t pid);
112 
113     static bool EnhanceDataPreprocess(std::string& componentInfo);
114     static bool EnhanceDataPreprocess(int32_t scId, std::string& componentInfo);
115     static bool EnhanceClientSerialize(MessageParcel& input, SecCompRawdata& output);
116     static bool EnhanceClientDeserialize(SecCompRawdata& input, MessageParcel& output);
117     static void RegisterScIdEnhance(int32_t scId);
118     static void UnregisterScIdEnhance(int32_t scId);
119 
120     static void AddSecurityComponentProcess(int32_t pid);
121 
122     static bool EnhanceSrvSerialize(MessageParcel& input, SecCompRawdata& output);
123     static bool EnhanceSrvDeserialize(SecCompRawdata& input, MessageParcel& output);
124     static __attribute__((visibility("default"))) SecCompInputEnhanceInterface* inputHandler;
125     static bool isEnhanceInputHandlerInit;
126 
127     static __attribute__((visibility("default"))) SecCompSrvEnhanceInterface* srvHandler;
128     static bool isEnhanceSrvHandlerInit;
129 
130     static __attribute__((visibility("default"))) SecCompClientEnhanceInterface* clientHandler;
131     static bool isEnhanceClientHandlerInit;
132 
133     static std::mutex initMtx;
134 };
135 typedef SecCompClientEnhanceInterface* (*EnhanceInterface) (void);
136 }  // namespace SecurityComponent
137 }  // namespace Security
138 }  // namespace OHOS
139 #endif  // SECURITY_COMPONENT_ENHANCE_ADAPTER_H
140