1 /* 2 * Copyright (c) 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 AUTH_MANAGER_H 17 #define AUTH_MANAGER_H 18 19 #include "auth_device.h" 20 #include "auth_interface.h" 21 #include "auth_normalize_request.h" 22 #include "auth_session_fsm.h" 23 #include "auth_session_key.h" 24 #include "common_list.h" 25 #include "lnn_lane_interface.h" 26 27 #ifdef __cplusplus 28 #if __cplusplus 29 extern "C" { 30 #endif 31 #endif 32 33 typedef struct { 34 int64_t authId; 35 bool isServer; 36 /* connInfo */ 37 uint64_t connId[AUTH_LINK_TYPE_MAX]; 38 AuthConnInfo connInfo[AUTH_LINK_TYPE_MAX]; 39 uint64_t lastActiveTime; 40 /* sessionKeyInfo */ 41 int64_t lastAuthSeq[AUTH_LINK_TYPE_MAX]; 42 uint64_t lastVerifyTime; 43 SessionKeyList sessionKeyList; 44 /* deviceInfo */ 45 char p2pMac[MAC_LEN]; 46 char udid[UDID_BUF_LEN]; 47 char uuid[UUID_BUF_LEN]; 48 SoftBusVersion version; 49 /* authState */ 50 bool hasAuthPassed[AUTH_LINK_TYPE_MAX]; 51 ListNode node; 52 } AuthManager; 53 54 typedef struct { 55 int32_t messageType; 56 ModeCycle cycle; 57 } DeviceMessageParse; 58 59 int32_t AuthManagerSetSessionKey(int64_t authSeq, AuthSessionInfo *info, const SessionKey *sessionKey, 60 bool isConnect, bool isOldKey); 61 int32_t AuthManagerGetSessionKey(int64_t authSeq, const AuthSessionInfo *info, SessionKey *sessionKey); 62 63 void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info); 64 void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int32_t reason); 65 void AuthManagerSetAuthFinished(int64_t authSeq, const AuthSessionInfo *info); 66 bool IsNeedAuthLimit(const char *udidHash); 67 void ClearAuthLimitMap(void); 68 69 void AuthNotifyAuthPassed(int64_t authSeq, const AuthSessionInfo *info); 70 71 /* Note: must call DelAuthManager to free. */ 72 AuthManager *GetAuthManagerByAuthId(int64_t authId); 73 AuthManager *GetAuthManagerByConnInfo(const AuthConnInfo *connInfo, bool isServer); 74 void RemoveAuthSessionKeyByIndex(int64_t authId, int32_t index, AuthLinkType type); 75 void DelAuthManager(AuthManager *auth, int32_t type); 76 void DelDupAuthManager(AuthManager *auth); 77 void RemoveAuthManagerByAuthId(AuthHandle authHandle); 78 int32_t AuthDeviceGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo); 79 int32_t AuthDeviceGetConnInfoByType(const char *uuid, AuthLinkType type, AuthConnInfo *connInfo); 80 int32_t AuthDeviceGetP2pConnInfo(const char *uuid, AuthConnInfo *connInfo); 81 int32_t AuthDeviceGetHmlConnInfo(const char *uuid, AuthConnInfo *connInfo); 82 /*check whether AUTH device is exist or not*/ 83 bool AuthDeviceCheckConnInfo(const char* uuid, AuthLinkType type, bool checkConnection); 84 int32_t AuthDeviceGetUsbConnInfo(const char *uuid, AuthConnInfo *connInfo); 85 86 /* for ProxyChannel & P2P TcpDirectchannel */ 87 void AuthDeviceGetLatestIdByUuid(const char *uuid, AuthLinkType type, AuthHandle *authHandle); 88 int64_t AuthDeviceGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer); 89 int64_t AuthDeviceGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer); 90 int32_t AuthDeviceGetAuthHandleByIndex(const char *udid, bool isServer, int32_t index, AuthHandle *authHandle); 91 AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info); 92 int32_t AuthDeviceSetP2pMac(int64_t authId, const char *p2pMac); 93 94 int32_t AuthDeviceInit(const AuthTransCallback *callback); 95 int32_t RegTrustListenerOnHichainSaStart(void); 96 int32_t GetHmlOrP2pAuthHandle(AuthHandle **authHandle, int32_t *num); 97 void AuthDeviceDeinit(void); 98 int64_t GetActiveAuthIdByConnInfo(const AuthConnInfo *connInfo, bool judgeTimeOut); 99 int64_t GetLatestIdByConnInfo(const AuthConnInfo *connInfo); 100 int32_t GetAuthConnInfoByUuid(const char *uuid, AuthLinkType type, AuthConnInfo *connInfo); 101 int32_t GetConnectionIdByHandle(AuthHandle handle); 102 int32_t TryGetBrConnInfo(const char *uuid, AuthConnInfo *connInfo); 103 void RemoveNotPassedAuthManagerByUdid(const char *udid); 104 AuthManager *GetDeviceAuthManager(int64_t authSeq, const AuthSessionInfo *info, bool *isNewCreated, 105 int64_t lastAuthSeq); 106 bool IsHaveAuthIdByConnId(uint64_t connId); 107 void DelAuthManagerByConnectionId(uint32_t connectionId); 108 bool RawLinkNeedUpdateAuthManager(const char *uuid, bool isServer); 109 110 #ifdef __cplusplus 111 #if __cplusplus 112 } 113 #endif 114 #endif 115 #endif /* AUTH_MANAGER_H */ 116