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 #define AUTH_IDENTICAL_ACCOUNT_GROUP 1 35 #define AUTH_PEER_TO_PEER_GROUP 256 36 37 typedef enum { 38 /* nearby type v1 */ 39 SOFTBUS_OLD_V1 = 1, 40 /* nearby type v2 */ 41 SOFTBUS_OLD_V2 = 2, 42 /* softbus type v1 */ 43 SOFTBUS_NEW_V1 = 100, 44 /* softbus type v2 */ 45 SOFTBUS_NEW_V2 = 101, 46 } SoftBusVersion; 47 48 typedef enum { 49 AUTH_LINK_TYPE_WIFI = 1, 50 AUTH_LINK_TYPE_BR, 51 AUTH_LINK_TYPE_BLE, 52 AUTH_LINK_TYPE_P2P, 53 } AuthLinkType; 54 55 typedef struct { 56 AuthLinkType type; 57 union { 58 struct { 59 char brMac[BT_MAC_LEN]; 60 } brInfo; 61 struct { 62 BleProtocolType protocol; 63 char bleMac[BT_MAC_LEN]; 64 uint8_t deviceIdHash[UDID_HASH_LEN]; 65 int32_t psm; 66 } bleInfo; 67 struct { 68 char ip[IP_LEN]; 69 int32_t port; 70 int64_t authId; /* for open p2p auth conn */ 71 } ipInfo; 72 } info; 73 char peerUid[MAX_ACCOUNT_HASH_LEN]; 74 } AuthConnInfo; 75 76 typedef enum { 77 ONLINE_HICHAIN = 0, 78 ONLINE_METANODE, 79 ONLINE_MIX, 80 81 AUTH_TYPE_BUTT, 82 } AuthType; 83 84 typedef struct { 85 void (*onDeviceVerifyPass)(int64_t authId, const NodeInfo *info); 86 void (*onDeviceNotTrusted)(const char *peerUdid); 87 void (*onDeviceDisconnect)(int64_t authId); 88 } AuthVerifyListener; 89 int32_t RegAuthVerifyListener(const AuthVerifyListener *listener); 90 void UnregAuthVerifyListener(void); 91 92 typedef struct { 93 void (*onVerifyPassed)(uint32_t requestId, int64_t authId, const NodeInfo *info); 94 void (*onVerifyFailed)(uint32_t requestId, int32_t reason); 95 } AuthVerifyCallback; 96 97 uint32_t AuthGenRequestId(void); 98 int32_t AuthStartVerify(const AuthConnInfo *connInfo, uint32_t requestId, 99 const AuthVerifyCallback *callback, bool isFastAuth); 100 void AuthHandleLeaveLNN(int64_t authId); 101 int32_t AuthFlushDevice(const char *uuid); 102 103 int32_t AuthMetaStartVerify(uint32_t connectionId, const uint8_t *key, uint32_t keyLen, 104 uint32_t requestId, int32_t callingPid, const AuthVerifyCallback *callBack); 105 void AuthMetaReleaseVerify(int64_t authId); 106 void AuthServerDeathCallback(const char *pkgName, int32_t pid); 107 108 typedef struct { 109 void (*onGroupCreated)(const char *groupId, int32_t groupType); 110 void (*onGroupDeleted)(const char *groupId); 111 void (*onDeviceBound)(const char *udid, const char *groupInfo); 112 } GroupChangeListener; 113 114 typedef enum { 115 TRUSTED_RELATION_IGNORE = 0, 116 TRUSTED_RELATION_NO, 117 TRUSTED_RELATION_YES, 118 } TrustedReturnType; 119 120 int32_t RegGroupChangeListener(const GroupChangeListener *listener); 121 void UnregGroupChangeListener(void); 122 123 TrustedReturnType AuthHasTrustedRelation(void); 124 bool AuthIsPotentialTrusted(const DeviceInfo *device, bool validAccount); 125 126 int32_t AuthStartListening(AuthLinkType type, const char *ip, int32_t port); 127 void AuthStopListening(AuthLinkType type); 128 129 typedef struct { 130 int32_t module; 131 int32_t flag; 132 int64_t seq; 133 uint32_t len; 134 const uint8_t *data; 135 } AuthTransData; 136 137 typedef struct { 138 void (*onDataReceived)(int64_t authId, const AuthTransData *data); 139 void (*onDisconnected)(int64_t authId); 140 } AuthTransListener; 141 int32_t RegAuthTransListener(int32_t module, const AuthTransListener *listener); 142 void UnregAuthTransListener(int32_t module); 143 144 typedef struct { 145 void (*onConnOpened)(uint32_t requestId, int64_t authId); 146 void (*onConnOpenFailed)(uint32_t requestId, int32_t reason); 147 } AuthConnCallback; 148 int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId, const AuthConnCallback *callback, bool isMeta); 149 int32_t AuthPostTransData(int64_t authId, const AuthTransData *dataInfo); 150 void AuthCloseConn(int64_t authId); 151 int32_t AuthGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta); 152 void AuthDeleteStoredAuthKey(const char *udid, int32_t discoveryType); 153 154 /* for ProxyChannel & P2P TcpDirectchannel */ 155 int64_t AuthGetLatestIdByUuid(const char *uuid, AuthLinkType type, bool isMeta); 156 int64_t AuthGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer, bool isMeta); 157 int64_t AuthGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer, bool isMeta); 158 159 uint32_t AuthGetEncryptSize(uint32_t inLen); 160 uint32_t AuthGetDecryptSize(uint32_t inLen); 161 int32_t AuthEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 162 int32_t AuthDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 163 164 int32_t AuthSetP2pMac(int64_t authId, const char *p2pMac); 165 166 int32_t AuthGetConnInfo(int64_t authId, AuthConnInfo *connInfo); 167 int32_t AuthGetServerSide(int64_t authId, bool *isServer); 168 int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size); 169 int32_t AuthGetVersion(int64_t authId, SoftBusVersion *version); 170 int32_t AuthGetMetaType(int64_t authId, bool *isMetaAuth); 171 int32_t AuthGetGroupType(const char *udid, const char *uuid); 172 173 int32_t AuthInit(void); 174 void AuthDeinit(void); 175 int32_t AuthRestoreAuthManager(const char *udidHash, 176 const AuthConnInfo *connInfo, int32_t requestId, NodeInfo *nodeInfo, int64_t *authId); 177 178 #ifdef __cplusplus 179 #if __cplusplus 180 } 181 #endif 182 #endif 183 #endif /* AUTH_INTERFACE_H */ 184