1 /* 2 * Copyright (c) 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 16 #ifndef AUTH_SESSION_JOSN_DEPS_MOCK_H 17 #define AUTH_SESSION_JOSN_DEPS_MOCK_H 18 19 #include <gmock/gmock.h> 20 #include <mutex> 21 22 #include "auth_attest_interface.h" 23 #include "auth_common.h" 24 #include "auth_connection.h" 25 #include "auth_device_common_key.h" 26 #include "auth_hichain_adapter.h" 27 #include "auth_interface.h" 28 #include "auth_manager.h" 29 #include "auth_meta_manager.h" 30 #include "auth_session_json.h" 31 #include "auth_session_key.h" 32 #include "auth_pre_link.h" 33 #include "bus_center_manager.h" 34 #include "lnn_cipherkey_manager.h" 35 #include "lnn_common_utils.h" 36 #include "lnn_device_info.h" 37 #include "lnn_device_info_recovery.h" 38 #include "lnn_extdata_config.h" 39 #include "lnn_feature_capability.h" 40 #include "lnn_local_net_ledger.h" 41 #include "lnn_node_info.h" 42 #include "lnn_p2p_info.h" 43 #include "lnn_settingdata_event_monitor.h" 44 #include "softbus_adapter_bt_common.h" 45 #include "softbus_adapter_crypto.h" 46 #include "softbus_adapter_json.h" 47 #include "softbus_adapter_socket.h" 48 #include "softbus_adapter_timer.h" 49 #include "softbus_feature_config.h" 50 #include "softbus_utils.h" 51 52 namespace OHOS { 53 class AuthSessionJsonDepsInterface { 54 public: AuthSessionJsonDepsInterface()55 AuthSessionJsonDepsInterface() {}; ~AuthSessionJsonDepsInterface()56 virtual ~AuthSessionJsonDepsInterface() {}; 57 virtual bool JSON_GetStringFromOject(const JsonObj *obj, const char *key, char *value, uint32_t size) = 0; 58 virtual bool JSON_GetInt32FromOject(const JsonObj *obj, const char *key, int32_t *value) = 0; 59 virtual bool JSON_GetInt64FromOject(const JsonObj *obj, const char *key, int64_t *value) = 0; 60 virtual bool JSON_GetBoolFromOject(const JsonObj *obj, const char *key, bool *value) = 0; 61 virtual int32_t LnnEncryptAesGcm(AesGcmInputParam *in, int32_t keyIndex, 62 uint8_t **out, uint32_t *outLen) = 0; 63 virtual int32_t LnnDecryptAesGcm(AesGcmInputParam *in, uint8_t **out, uint32_t *outLen) = 0; 64 virtual bool JSON_AddStringToObject(JsonObj *obj, const char *key, const char *value) = 0; 65 virtual int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned char *hash) = 0; 66 virtual int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, 67 const unsigned char *inBuf, uint32_t inLen) = 0; 68 virtual int32_t LnnGetUdidByBrMac(const char *brMac, char *udid, uint32_t udidLen) = 0; 69 virtual int32_t AuthFindLatestNormalizeKey(const char *udidHash, 70 AuthDeviceKeyInfo *deviceKey, bool clearOldKey) = 0; 71 virtual bool AuthIsLatestNormalizeKeyInTime(const char *udidHash, uint64_t time) = 0; 72 virtual int32_t AuthFindDeviceKey(const char *udidHash, int32_t keyType, AuthDeviceKeyInfo *deviceKey) = 0; 73 virtual void AuthGetLatestIdByUuid(const char *uuid, 74 AuthLinkType type, bool isMeta, AuthHandle *authHandle) = 0; 75 virtual AuthManager *GetAuthManagerByAuthId(int64_t authId) = 0; 76 virtual int32_t GetLatestSessionKey(const SessionKeyList *list, 77 AuthLinkType type, int32_t *index, SessionKey *key) = 0; 78 virtual void DelDupAuthManager(AuthManager *auth) = 0; 79 virtual bool IsPotentialTrustedDevice(TrustedRelationIdType idType, 80 const char *deviceId, bool isPrecise, bool isPointToPoint) = 0; 81 virtual bool IsPotentialTrustedDeviceDp(const char *deviceIdHash, bool isPointToPoint) = 0; 82 virtual int32_t ConvertBytesToUpperCaseHexString(char *outBuf, uint32_t outBufLen, 83 const unsigned char *inBuf, uint32_t inLen) = 0; 84 virtual int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, 85 const char *inBuf, uint32_t inLen) = 0; 86 virtual int32_t AuthFindNormalizeKeyByServerSide(const char *udidHash, bool isServer, 87 AuthDeviceKeyInfo *deviceKey) = 0; 88 virtual void AuthUpdateCreateTime(const char *udidHash, int32_t keyType, bool isServer) = 0; 89 virtual bool IsFeatureSupport(uint64_t feature, FeatureCapability capaBit) = 0; 90 virtual int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len) = 0; 91 virtual bool IsSupportUDIDAbatement(void) = 0; 92 virtual bool JSON_AddBoolToObject(JsonObj *obj, const char *key, bool value) = 0; 93 virtual bool IsNeedUDIDAbatement(const AuthSessionInfo *info) = 0; 94 virtual bool JSON_AddInt32ToObject(JsonObj *obj, const char *key, int32_t value) = 0; 95 virtual bool IsSupportFeatureByCapaBit(uint32_t feature, AuthCapability capaBit) = 0; 96 virtual JsonObj *JSON_CreateObject() = 0; 97 virtual void JSON_Delete(JsonObj *obj) = 0; 98 virtual JsonObj *JSON_Parse(const char *str, uint32_t len) = 0; 99 virtual const NodeInfo *LnnGetLocalNodeInfo(void) = 0; 100 virtual char *JSON_PrintUnformatted(const JsonObj *obj) = 0; 101 virtual int32_t GetFd(uint64_t connId) = 0; 102 virtual int32_t SoftBusSocketGetPeerName(int32_t socketFd, SoftBusSockAddr *addr) = 0; 103 virtual const char *SoftBusInetNtoP(int32_t af, const void *src, char *dst, int32_t size) = 0; 104 virtual int32_t GetPeerUdidByNetworkId(const char *networkId, char *udid, uint32_t len) = 0; 105 virtual int32_t GetIsExchangeUdidByNetworkId(const char *networkId, bool *isExchangeUdid) = 0; 106 virtual int32_t LnnGetUnifiedDeviceName(char *unifiedName, uint32_t len) = 0; 107 virtual int32_t LnnSetLocalStrInfo(InfoKey key, const char *info) = 0; 108 virtual int32_t GetExtData(char *value, uint32_t len) = 0; 109 virtual int32_t AuthMetaGetConnIdByInfo(const AuthConnInfo *connInfo, uint32_t *connectionId) = 0; 110 virtual int32_t LnnGetMetaPtk(uint32_t connId, char *metaPtk, uint32_t len) = 0; 111 virtual int32_t LnnGetLocalPtkByUuid(const char *uuid, char *localPtk, uint32_t len) = 0; 112 virtual void LnnDumpRemotePtk(const char *oldPtk, const char *newPtk, const char *log) = 0; 113 virtual int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen, size_t *olen, 114 const unsigned char *src, size_t slen) = 0; 115 virtual int32_t SoftBusBase64Decode(unsigned char *dst, size_t dlen, size_t *olen, 116 const unsigned char *src, size_t slen) = 0; 117 virtual int32_t LnnUpdateLocalBroadcastCipherKey(BroadcastCipherKey *broadcastKey) = 0; 118 virtual void ProcessCipherKeySyncInfo(const void *json, const char *networkId) = 0; 119 virtual bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type) = 0; 120 virtual int32_t LnnGetNetworkIdByUuid(const char *uuid, char *buf, uint32_t len) = 0; 121 virtual int32_t LnnGetRemoteNumInfo(const char *netWorkId, InfoKey key, int32_t *info) = 0; 122 virtual int32_t SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len); 123 virtual int32_t GenerateCertificate(SoftbusCertChain *softbusCertChain, const AuthSessionInfo *info) = 0; 124 virtual void FreeSoftbusChain(SoftbusCertChain *softbusCertChain) = 0; 125 virtual int32_t InitSoftbusChain(SoftbusCertChain *softbusCertChain) = 0; 126 virtual int32_t VerifyCertificate(SoftbusCertChain *softbusCertChain, 127 const NodeInfo *nodeInfo, const AuthSessionInfo *info) = 0; 128 virtual int32_t LnnGetLocalNodeInfoSafe(NodeInfo *info) = 0; 129 virtual const char *LnnGetBtMac(const NodeInfo *info) = 0; 130 virtual int32_t SoftBusGetBtState(void) = 0; 131 virtual int32_t SoftBusGetBtMacAddr(SoftBusBtAddr *mac) = 0; 132 virtual int32_t ConvertBtMacToStr(char *strMac, uint32_t strMacLen, 133 const uint8_t *binMac, uint32_t binMacLen) = 0; 134 virtual int32_t LnnGetDeviceDisplayName(const char *nickName, 135 const char *defaultName, char *deviceName, uint32_t len) = 0; 136 virtual uint64_t SoftBusGetSysTimeMs(void) = 0; 137 virtual uint64_t LnnGetSupportedProtocols(const NodeInfo *info) = 0; 138 virtual int32_t StringToUpperCase(const char *str, char *buf, int32_t size) = 0; 139 virtual int32_t LnnGetAuthPort(const NodeInfo *info) = 0; 140 virtual int32_t LnnGetSessionPort(const NodeInfo *info) = 0; 141 virtual int32_t LnnGetProxyPort(const NodeInfo *info) = 0; 142 virtual bool JSON_AddBytesToObject(JsonObj *obj, const char *key, uint8_t *value, uint32_t size) = 0; 143 virtual bool JSON_GetBytesFromObject(const JsonObj *obj, const char *key, uint8_t *value, 144 uint32_t bufLen, uint32_t *size) = 0; 145 virtual bool JSON_AddInt16ToObject(JsonObj *obj, const char *key, int16_t value) = 0; 146 virtual bool JSON_AddInt64ToObject(JsonObj *obj, const char *key, int64_t value) = 0; 147 virtual const char *LnnGetP2pMac(const NodeInfo *info) = 0; 148 virtual const char *LnnGetDeviceName(const DeviceBasicInfo *info) = 0; 149 virtual char *LnnConvertIdToDeviceType(uint16_t typeId) = 0; 150 virtual const char *LnnGetDeviceUdid(const NodeInfo *info) = 0; 151 virtual bool PackCipherKeySyncMsg(void *json) = 0; 152 virtual int32_t LnnGetP2pRole(const NodeInfo *info) = 0; 153 virtual int32_t LnnGetStaFrequency(const NodeInfo *info) = 0; 154 virtual int32_t FindAuthPreLinkNodeById(uint32_t requestId, AuthPreLinkNode *reuseNode) = 0; 155 }; 156 class AuthSessionJsonDepsInterfaceMock : public AuthSessionJsonDepsInterface { 157 public: 158 AuthSessionJsonDepsInterfaceMock(); 159 ~AuthSessionJsonDepsInterfaceMock() override; 160 MOCK_METHOD4(JSON_GetStringFromOject, bool (const JsonObj *, const char *, char *, uint32_t)); 161 MOCK_METHOD3(JSON_GetInt32FromOject, bool (const JsonObj *, const char *, int32_t *)); 162 MOCK_METHOD3(JSON_GetInt64FromOject, bool (const JsonObj *, const char *, int64_t *)); 163 MOCK_METHOD3(JSON_GetBoolFromOject, bool (const JsonObj *, const char *, bool *)); 164 MOCK_METHOD4(LnnEncryptAesGcm, int32_t (AesGcmInputParam *, int32_t, uint8_t **, uint32_t *)); 165 MOCK_METHOD3(JSON_AddStringToObject, bool (JsonObj *, const char *, const char *)); 166 MOCK_METHOD3(SoftBusGenerateStrHash, int32_t (const unsigned char *, uint32_t, unsigned char *)); 167 MOCK_METHOD4(ConvertBytesToHexString, int32_t (char *, uint32_t, const unsigned char *, uint32_t)); 168 MOCK_METHOD3(LnnGetUdidByBrMac, int32_t (const char *, char *, uint32_t)); 169 MOCK_METHOD3(AuthFindLatestNormalizeKey, int32_t (const char *, AuthDeviceKeyInfo *, bool)); 170 MOCK_METHOD2(AuthIsLatestNormalizeKeyInTime, bool (const char *, uint64_t)); 171 MOCK_METHOD3(AuthFindDeviceKey, int32_t (const char *, int32_t, AuthDeviceKeyInfo *)); 172 MOCK_METHOD4(AuthGetLatestIdByUuid, void (const char *, AuthLinkType, bool, AuthHandle *)); 173 MOCK_METHOD1(GetAuthManagerByAuthId, AuthManager *(int64_t authId)); 174 MOCK_METHOD4(GetLatestSessionKey, int32_t (const SessionKeyList *, AuthLinkType, int32_t *, SessionKey *)); 175 MOCK_METHOD1(DelDupAuthManager, void (AuthManager *)); 176 MOCK_METHOD4(IsPotentialTrustedDevice, bool (TrustedRelationIdType, const char *, bool, bool)); 177 MOCK_METHOD2(IsPotentialTrustedDeviceDp, bool (const char *, bool)); 178 MOCK_METHOD4(ConvertBytesToUpperCaseHexString, int32_t (char *, uint32_t, const unsigned char *, uint32_t)); 179 MOCK_METHOD4(ConvertHexStringToBytes, int32_t (unsigned char *, uint32_t, const char *, uint32_t)); 180 MOCK_METHOD3(LnnDecryptAesGcm, int32_t (AesGcmInputParam *, uint8_t **, uint32_t *)); 181 MOCK_METHOD3(AuthFindNormalizeKeyByServerSide, int32_t (const char *, bool, AuthDeviceKeyInfo *)); 182 MOCK_METHOD3(AuthUpdateCreateTime, void (const char *, int32_t, bool)); 183 MOCK_METHOD2(IsFeatureSupport, bool (uint64_t feature, FeatureCapability capaBit)); 184 MOCK_METHOD3(LnnGetLocalStrInfo, int32_t (InfoKey, char *, uint32_t)); 185 MOCK_METHOD0(IsSupportUDIDAbatement, bool ()); 186 MOCK_METHOD3(JSON_AddBoolToObject, bool (JsonObj *, const char *, bool)); 187 MOCK_METHOD1(IsNeedUDIDAbatement, bool (const AuthSessionInfo *)); 188 MOCK_METHOD3(JSON_AddInt32ToObject, bool (JsonObj *, const char *, int32_t)); 189 MOCK_METHOD2(IsSupportFeatureByCapaBit, bool (uint32_t, AuthCapability)); 190 MOCK_METHOD0(JSON_CreateObject, JsonObj *()); 191 MOCK_METHOD1(JSON_Delete, void (JsonObj *obj)); 192 MOCK_METHOD2(JSON_Parse, JsonObj *(const char *str, uint32_t len)); 193 MOCK_METHOD0(LnnGetLocalNodeInfo, const NodeInfo *()); 194 MOCK_METHOD1(JSON_PrintUnformatted, char *(const JsonObj *obj)); 195 MOCK_METHOD1(GetFd, int32_t (uint64_t)); 196 MOCK_METHOD2(SoftBusSocketGetPeerName, int32_t (int32_t, SoftBusSockAddr *)); 197 MOCK_METHOD4(SoftBusInetNtoP, const char *(int32_t, const void *, char *, int32_t)); 198 MOCK_METHOD3(GetPeerUdidByNetworkId, int32_t (const char *, char *, uint32_t)); 199 MOCK_METHOD2(GetIsExchangeUdidByNetworkId, int32_t (const char *, bool *)); 200 MOCK_METHOD2(LnnGetUnifiedDeviceName, int32_t (char *, uint32_t)); 201 MOCK_METHOD2(LnnSetLocalStrInfo, int32_t (InfoKey, const char *)); 202 MOCK_METHOD2(GetExtData, int32_t (char *, uint32_t)); 203 MOCK_METHOD2(AuthMetaGetConnIdByInfo, int32_t (const AuthConnInfo *, uint32_t *)); 204 MOCK_METHOD3(LnnGetMetaPtk, int32_t (uint32_t, char *, uint32_t)); 205 MOCK_METHOD3(LnnGetLocalPtkByUuid, int32_t (const char *, char *, uint32_t)); 206 MOCK_METHOD3(LnnDumpRemotePtk, void (const char *, const char *, const char *)); 207 MOCK_METHOD5(SoftBusBase64Encode, int32_t (unsigned char *, size_t, size_t *, const unsigned char *, size_t)); 208 MOCK_METHOD5(SoftBusBase64Decode, int32_t (unsigned char *, size_t, size_t *, const unsigned char *, size_t)); 209 MOCK_METHOD1(LnnUpdateLocalBroadcastCipherKey, int32_t (BroadcastCipherKey *)); 210 MOCK_METHOD2(ProcessCipherKeySyncInfo, void (const void *, const char *)); 211 MOCK_METHOD2(LnnHasDiscoveryType, bool (const NodeInfo *, DiscoveryType)); 212 MOCK_METHOD3(LnnGetNetworkIdByUuid, int32_t (const char *, char *, uint32_t)); 213 MOCK_METHOD3(LnnGetRemoteNumInfo, int32_t(const char *, InfoKey, int32_t *)); 214 MOCK_METHOD3(SoftbusGetConfig, int32_t (ConfigType, unsigned char *, uint32_t)); 215 MOCK_METHOD2(GenerateCertificate, int32_t (SoftbusCertChain *, const AuthSessionInfo *)); 216 MOCK_METHOD1(FreeSoftbusChain, void (SoftbusCertChain *)); 217 MOCK_METHOD2(FindAuthPreLinkNodeById, int32_t (uint32_t, AuthPreLinkNode *)); 218 MOCK_METHOD1(InitSoftbusChain, int32_t (SoftbusCertChain *)); 219 MOCK_METHOD3(VerifyCertificate, int32_t (SoftbusCertChain *, const NodeInfo *, const AuthSessionInfo *)); 220 MOCK_METHOD1(LnnGetLocalNodeInfoSafe, int32_t (NodeInfo *)); 221 MOCK_METHOD1(LnnGetBtMac, const char *(const NodeInfo *)); 222 MOCK_METHOD0(SoftBusGetBtState, int32_t (void)); 223 MOCK_METHOD1(SoftBusGetBtMacAddr, int32_t (SoftBusBtAddr *)); 224 MOCK_METHOD4(ConvertBtMacToStr, int32_t (char *, uint32_t, const uint8_t *, uint32_t)); 225 MOCK_METHOD4(LnnGetDeviceDisplayName, int32_t (const char *, const char *, char *, uint32_t)); 226 MOCK_METHOD0(SoftBusGetSysTimeMs, uint64_t (void)); 227 MOCK_METHOD1(LnnGetSupportedProtocols, uint64_t (const NodeInfo *)); 228 MOCK_METHOD3(StringToUpperCase, int32_t (const char *, char *, int32_t)); 229 MOCK_METHOD1(LnnGetAuthPort, int32_t (const NodeInfo *)); 230 MOCK_METHOD1(LnnGetSessionPort, int32_t (const NodeInfo *)); 231 MOCK_METHOD1(LnnGetProxyPort, int32_t (const NodeInfo *)); 232 MOCK_METHOD4(JSON_AddBytesToObject, bool (JsonObj *, const char *, uint8_t *, uint32_t)); 233 MOCK_METHOD5(JSON_GetBytesFromObject, bool (const JsonObj *, const char *, uint8_t *, uint32_t, uint32_t *)); 234 MOCK_METHOD3(JSON_AddInt16ToObject, bool (JsonObj *, const char *, int16_t)); 235 MOCK_METHOD3(JSON_AddInt64ToObject, bool (JsonObj *, const char *, int64_t)); 236 MOCK_METHOD1(LnnGetP2pMac, const char * (const NodeInfo *)); 237 MOCK_METHOD1(LnnGetDeviceName, const char * (const DeviceBasicInfo *)); 238 MOCK_METHOD1(LnnConvertIdToDeviceType, char * (uint16_t)); 239 MOCK_METHOD1(LnnGetDeviceUdid, const char * (const NodeInfo *)); 240 MOCK_METHOD1(PackCipherKeySyncMsg, bool (void *)); 241 MOCK_METHOD1(LnnGetP2pRole, int32_t (const NodeInfo *)); 242 MOCK_METHOD1(LnnGetStaFrequency, int32_t (const NodeInfo *)); 243 }; 244 } // namespace OHOS 245 #endif // AUTH_TCP_CONNECTION_MOCK_H