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 int32_t AuthManagerGetSessionKey(int64_t authSeq, const AuthSessionInfo *info, SessionKey *sessionKey); 56 57 void AuthManagerSetAuthPassed(int64_t authSeq, const AuthSessionInfo *info); 58 void AuthManagerSetAuthFailed(int64_t authSeq, const AuthSessionInfo *info, int32_t reason); 59 60 /* Note: must call DelAuthManager to free. */ 61 AuthManager *GetAuthManagerByAuthId(int64_t authId); 62 void DelAuthManager(AuthManager *auth, bool removeAuthFromList); 63 64 int32_t AuthDeviceOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback); 65 int32_t AuthDevicePostTransData(int64_t authId, const AuthTransData *dataInfo); 66 void AuthDeviceCloseConn(int64_t authId); 67 int32_t AuthDeviceGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo); 68 69 /* for ProxyChannel & P2P TcpDirectchannel */ 70 int64_t AuthDeviceGetLatestIdByUuid(const char *uuid, bool isIpConnection); 71 int64_t AuthDeviceGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer); 72 int64_t AuthDeviceGetIdByP2pMac(const char *p2pMac, AuthLinkType type, bool isServer); 73 74 int32_t AuthDeviceEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 75 int32_t AuthDeviceDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 76 int32_t AuthDeviceSetP2pMac(int64_t authId, const char *p2pMac); 77 78 int32_t AuthDeviceGetConnInfo(int64_t authId, AuthConnInfo *connInfo); 79 int32_t AuthDeviceGetDeviceUuid(int64_t authId, char *uuid, uint16_t size); 80 int32_t AuthDeviceGetVersion(int64_t authId, SoftBusVersion *version); 81 int32_t AuthDeviceGetServerSide(int64_t authId, bool *isServer); 82 int32_t AuthDeviceInit(const AuthTransCallback *callback); 83 void AuthDeviceDeinit(void); 84 85 #ifdef __cplusplus 86 #if __cplusplus 87 } 88 #endif 89 #endif 90 #endif /* AUTH_MANAGER_H */ 91