1 /* 2 * Copyright (c) 2021 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_INTERFACE_H 17 #define AUTH_INTERFACE_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 #include "lnn_node_info.h" 22 #include "softbus_common.h" 23 #include "softbus_conn_interface.h" 24 #include "softbus_def.h" 25 26 #ifdef __cplusplus 27 #if __cplusplus 28 extern "C" { 29 #endif 30 #endif 31 32 #define AUTH_INVALID_ID (-1) 33 34 typedef enum { 35 /* nearby type v1 */ 36 SOFTBUS_OLD_V1 = 1, 37 /* nearby type v2 */ 38 SOFTBUS_OLD_V2 = 2, 39 /* softbus type v1 */ 40 SOFTBUS_NEW_V1 = 100, 41 } SoftBusVersion; 42 43 typedef enum { 44 AUTH_LINK_TYPE_WIFI = 1, 45 AUTH_LINK_TYPE_BR, 46 AUTH_LINK_TYPE_BLE, 47 AUTH_LINK_TYPE_P2P, 48 } AuthLinkType; 49 50 typedef struct { 51 AuthLinkType type; 52 union { 53 struct { 54 char brMac[BT_MAC_LEN]; 55 } brInfo; 56 struct { 57 char bleMac[BT_MAC_LEN]; 58 uint8_t deviceIdHash[UDID_HASH_LEN]; 59 } bleInfo; 60 struct { 61 char ip[IP_LEN]; 62 int32_t port; 63 int64_t authId; /* for open p2p auth conn */ 64 } ipInfo; 65 } info; 66 char peerUid[MAX_ACCOUNT_HASH_LEN]; 67 } AuthConnInfo; 68 69 typedef enum { 70 ONLINE_HICHAIN = 0, 71 ONLINE_METANODE, 72 ONLINE_MIX, 73 74 AUTH_TYPE_BUTT, 75 } AuthType; 76 77 typedef struct { 78 void (*onDeviceVerifyPass)(int64_t authId, const NodeInfo *info); 79 void (*onDeviceNotTrusted)(const char *peerUdid); 80 void (*onDeviceDisconnect)(int64_t authId); 81 } AuthVerifyListener; 82 int32_t RegAuthVerifyListener(const AuthVerifyListener *listener); 83 void UnregAuthVerifyListener(void); 84 85 typedef struct { 86 void (*onVerifyPassed)(uint32_t requestId, int64_t authId, const NodeInfo *info); 87 void (*onVerifyFailed)(uint32_t requestId, int32_t reason); 88 } AuthVerifyCallback; 89 90 uint32_t AuthGenRequestId(void); 91 int32_t AuthStartVerify(const AuthConnInfo *connInfo, uint32_t requestId, const AuthVerifyCallback *callback); 92 void AuthHandleLeaveLNN(int64_t authId); 93 int32_t AuthFlushDevice(const char *uuid); 94 95 int32_t AuthMetaStartVerify(uint32_t connectionId, const uint8_t *key, uint32_t keyLen, 96 uint32_t requestId, const AuthVerifyCallback *callBack); 97 void AuthMetaReleaseVerify(int64_t authId); 98 99 typedef struct { 100 void (*onGroupCreated)(const char *groupId); 101 void (*onGroupDeleted)(const char *groupId); 102 } GroupChangeListener; 103 int32_t RegGroupChangeListener(const GroupChangeListener *listener); 104 void UnregGroupChangeListener(void); 105 106 int32_t AuthStartListening(AuthLinkType type, const char *ip, int32_t port); 107 void AuthStopListening(AuthLinkType type); 108 109 typedef struct { 110 int32_t module; 111 int32_t flag; 112 int64_t seq; 113 uint32_t len; 114 const uint8_t *data; 115 } AuthTransData; 116 117 typedef struct { 118 void (*onDataReceived)(int64_t authId, const AuthTransData *data); 119 void (*onDisconnected)(int64_t authId); 120 } AuthTransListener; 121 int32_t RegAuthTransListener(int32_t module, const AuthTransListener *listener); 122 void UnregAuthTransListener(int32_t module); 123 124 typedef struct { 125 void (*onConnOpened)(uint32_t requestId, int64_t authId); 126 void (*onConnOpenFailed)(uint32_t requestId, int32_t reason); 127 } AuthConnCallback; 128 int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback, bool isMeta); 129 int32_t AuthPostTransData(int64_t authId, const AuthTransData *dataInfo); 130 void AuthCloseConn(int64_t authId); 131 int32_t AuthGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta); 132 133 /* for ProxyChannel & P2P TcpDirectchannel */ 134 int64_t AuthGetLatestIdByUuid(const char *uuid, bool isIpConnection, bool isMeta); 135 int64_t AuthGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer, bool isMeta); 136 int64_t AuthGetIdByP2pMac(const char *p2pMac, AuthLinkType type, bool isServer, bool isMeta); 137 138 uint32_t AuthGetEncryptSize(uint32_t inLen); 139 uint32_t AuthGetDecryptSize(uint32_t inLen); 140 int32_t AuthEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 141 int32_t AuthDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 142 143 int32_t AuthSetP2pMac(int64_t authId, const char *p2pMac); 144 145 int32_t AuthGetConnInfo(int64_t authId, AuthConnInfo *connInfo); 146 int32_t AuthGetServerSide(int64_t authId, bool *isServer); 147 int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size); 148 int32_t AuthGetVersion(int64_t authId, SoftBusVersion *version); 149 int32_t AuthGetMetaType(int64_t authId, bool *isMetaAuth); 150 151 int32_t AuthInit(void); 152 void AuthDeinit(void); 153 154 #ifdef __cplusplus 155 #if __cplusplus 156 } 157 #endif 158 #endif 159 #endif /* AUTH_INTERFACE_H */ 160