回退 'Pull Request !6723 : bug:fd reuse causes auth to fail'

This commit is contained in:
宋晨曦 2024-07-06 04:00:14 +00:00 committed by Gitee
parent 31faf31a4e
commit ba9fe6f99d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 8 additions and 52 deletions

View File

@ -122,7 +122,6 @@ typedef enum {
EVENT_AUTH_META_TIMEOUT,
EVENT_AUTH_DISCONNECT,
EVENT_BLE_DISCONNECT_DELAY,
EVENT_RECV_AUTH_DATA,
} EventType;
typedef void(*EventHandler)(const void *obj);
int32_t PostAuthEvent(EventType event, EventHandler handler,

View File

@ -61,15 +61,6 @@ typedef struct {
ModeCycle cycle;
} DeviceMessageParse;
typedef struct {
uint64_t connId;
AuthConnInfo connInfo;
bool fromServer;
AuthDataHead head;
uint32_t len;
uint8_t *data;
} RecvDeviceIdData;
int32_t AuthManagerSetSessionKey(int64_t authSeq, AuthSessionInfo *info, const SessionKey *sessionKey,
bool isConnect, bool isOldKey);
int32_t AuthManagerGetSessionKey(int64_t authSeq, const AuthSessionInfo *info, SessionKey *sessionKey);

View File

@ -192,6 +192,7 @@ static void NotifyDisconnected(uint64_t connId, const AuthConnInfo *connInfo)
}
}
static void NotifyDataReceived(
uint64_t connId, const AuthConnInfo *connInfo, bool fromServer, const AuthDataHead *head, const uint8_t *data)
{

View File

@ -1150,43 +1150,6 @@ static void HandleDeviceIdData(
}
}
static void HandleRecvDeviceId(const void *para)
{
RecvDeviceIdData *recvData = (RecvDeviceIdData *)para;
if (recvData == NULL) {
AUTH_LOGE(AUTH_FSM, "recvData is null");
SoftBusFree(recvData->data);
return;
}
HandleDeviceIdData(recvData->connId, &recvData->connInfo, recvData->fromServer, &recvData->head, recvData->data);
SoftBusFree(recvData->data);
}
static void NotifyRecvDeviceId(
uint64_t connId, const AuthConnInfo *connInfo, bool fromServer, const AuthDataHead *head, const uint8_t *data)
{
uint8_t *postData = (uint8_t *)SoftBusCalloc(head->len);
if (postData == NULL) {
AUTH_LOGE(AUTH_FSM, "malloc postData fail");
return;
}
if (memcpy_s(postData, head->len, data, head->len) != EOK) {
AUTH_LOGE(AUTH_FSM, "memcpy postData fail");
SoftBusFree(postData);
return;
}
RecvDeviceIdData recvData = {
.connId = connId,
.connInfo = *connInfo,
.fromServer = fromServer,
.head = *head,
.len = head->len,
.data = postData,
};
(void)PostAuthEvent(EVENT_RECV_AUTH_DATA, HandleRecvDeviceId, &recvData, sizeof(RecvDeviceIdData), 0);
}
static void HandleAuthData(const AuthConnInfo *connInfo, const AuthDataHead *head, const uint8_t *data)
{
int32_t ret = AuthSessionProcessAuthData(head->seq, data, head->len);
@ -1441,7 +1404,7 @@ static void OnDataReceived(
head->dataType, head->module, head->seq, head->flag, head->len, CONN_DATA(connId), GetAuthSideStr(fromServer));
switch (head->dataType) {
case DATA_TYPE_DEVICE_ID:
NotifyRecvDeviceId(connId, connInfo, fromServer, head, data);
HandleDeviceIdData(connId, connInfo, fromServer, head, data);
break;
case DATA_TYPE_AUTH:
HandleAuthData(connInfo, head, data);
@ -1464,8 +1427,10 @@ static void OnDataReceived(
SoftbusHitraceStop();
}
static void HandleDisconnectedEvent(uint64_t connId)
static void HandleDisconnectedEvent(const void *para)
{
AUTH_CHECK_AND_RETURN_LOGE(para != NULL, AUTH_FSM, "para is null");
uint64_t connId = *((uint64_t *)para);
uint32_t num = 0;
uint64_t dupConnId = connId;
int64_t authIds[2]; /* 2: client and server may use same connection. */
@ -1496,7 +1461,7 @@ static void HandleDisconnectedEvent(uint64_t connId)
static void OnDisconnected(uint64_t connId, const AuthConnInfo *connInfo)
{
(void)connInfo;
HandleDisconnectedEvent(connId);
(void)PostAuthEvent(EVENT_AUTH_DISCONNECT, HandleDisconnectedEvent, &connId, sizeof(connId), 0);
}
uint32_t AuthGenRequestId(void)

View File

@ -426,10 +426,10 @@ static void DelAllConnInfo(ListenerModule moduleId)
TcpConnInfoNode *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_tcpConnInfoList->list, TcpConnInfoNode, node) {
if (item->info.socketInfo.moduleId == (int32_t)moduleId) {
g_tcpConnCallback->OnDisconnected(item->connectionId, &item->info);
(void)DelTrigger(moduleId, item->info.socketInfo.fd, RW_TRIGGER);
ListDelete(&item->node);
ConnShutdownSocket(item->info.socketInfo.fd);
g_tcpConnCallback->OnDisconnected(item->connectionId, &item->info);
SoftBusFree(item);
g_tcpConnInfoList->cnt--;
}

View File

@ -556,7 +556,7 @@ HWTEST_F(AuthManagerTest, TRY_GET_BR_CONN_INFO_TEST_001, TestSize.Level1)
HWTEST_F(AuthManagerTest, AUTH_DEVICE_GET_P2P_CONN_INFO_TEST_001, TestSize.Level1)
{
uint64_t connId = CONN_ID;
HandleDisconnectedEvent(connId);
HandleDisconnectedEvent(reinterpret_cast<void *>(&connId));
AuthHandle authHandle = { .authId = AUTH_SEQ_1, .type = AUTH_LINK_TYPE_WIFI };
AuthHandleLeaveLNN(authHandle);
authHandle.authId = AUTH_SEQ;