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 <stdint.h> 20 #include <stdbool.h> 21 22 #include "auth_common.h" 23 #include "auth_interface.h" 24 #include "auth_session_fsm.h" 25 #include "auth_session_key.h" 26 #include "common_list.h" 27 28 #ifdef __cplusplus 29 #if __cplusplus 30 extern "C" { 31 #endif 32 #endif 33 34 typedef struct { 35 int64_t authId; 36 bool isServer; 37 /* 连接信息 */ 38 uint64_t connId; 39 AuthConnInfo connInfo; 40 uint64_t lastActiveTime; 41 /* 密钥信息 */ 42 uint64_t lastVerifyTime; 43 SessionKeyList sessionKeyList; 44 /* 设备信息 */ 45 char p2pMac[MAC_LEN]; 46 char udid[UDID_BUF_LEN]; 47 char uuid[UUID_BUF_LEN]; 48 SoftBusVersion version; 49 /* 认证状态 */ 50 bool hasAuthPassed; 51 ListNode node; 52 } AuthManager; 53 54 int32_t AuthManagerSetSessionKey(int64_t authSeq, const AuthSessionInfo *info, const SessionKey *sessionKey, 55 bool isConnect); 56 int32_t AuthManagerGetSessionKey(int64_t authSeq, const AuthSessionInfo *info, SessionKey *sessionKey); 57 58 void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info); 59 void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int32_t reason); 60 void AuthManagerSetAuthFinished(int64_t authSeq, const AuthSessionInfo *info); 61 62 /* Note: must call DelAuthManager to free. */ 63 AuthManager *GetAuthManagerByAuthId(int64_t authId); 64 void RemoveAuthSessionKeyByIndex(int64_t authId, int32_t index); 65 void DelAuthManager(AuthManager *auth, bool removeAuthFromList); 66 void RemoveAuthManagerByAuthId(int64_t authId); 67 int32_t AuthDeviceOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback); 68 int32_t AuthDevicePostTransData(int64_t authId, const AuthTransData *dataInfo); 69 void AuthDeviceCloseConn(int64_t authId); 70 int32_t AuthDeviceGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo); 71 /*check whether AUTH device is exist or not*/ 72 bool AuthDeviceCheckConnInfo(const char* uuid, AuthLinkType type, bool checkConnection); 73 74 /* for ProxyChannel & P2P TcpDirectchannel */ 75 int64_t AuthDeviceGetLatestIdByUuid(const char *uuid, AuthLinkType type); 76 int64_t AuthDeviceGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer); 77 int64_t AuthDeviceGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer); 78 AuthManager *NewAuthManager(int64_t authSeq, const AuthSessionInfo *info); 79 80 int32_t AuthDeviceEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 81 int32_t AuthDeviceDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 82 int32_t AuthDeviceSetP2pMac(int64_t authId, const char *p2pMac); 83 84 int32_t AuthDeviceGetConnInfo(int64_t authId, AuthConnInfo *connInfo); 85 int32_t AuthDeviceGetDeviceUuid(int64_t authId, char *uuid, uint16_t size); 86 int32_t AuthDeviceGetVersion(int64_t authId, SoftBusVersion *version); 87 int32_t AuthDeviceGetServerSide(int64_t authId, bool *isServer); 88 int32_t AuthDeviceInit(const AuthTransCallback *callback); 89 void AuthDeviceDeinit(void); 90 91 #ifdef __cplusplus 92 #if __cplusplus 93 } 94 #endif 95 #endif 96 #endif /* AUTH_MANAGER_H */ 97