1 /*
2 * Copyright (c) 2025 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 #include "auth_pre_link.h"
16
17 #include <securec.h>
18 #include <stdatomic.h>
19 #include "anonymizer.h"
20 #include "auth_attest_interface.h"
21 #include "auth_connection.h"
22 #include "auth_deviceprofile.h"
23 #include "auth_hichain.h"
24 #include "auth_log.h"
25 #include "auth_request.h"
26 #include "auth_session_message.h"
27 #include "bus_center_manager.h"
28 #include "device_profile_listener.h"
29 #include "lnn_app_bind_interface.h"
30 #include "lnn_decision_db.h"
31 #include "lnn_heartbeat_ctrl.h"
32 #include "lnn_local_net_ledger.h"
33 #include "lnn_ohos_account_adapter.h"
34 #include "lnn_map.h"
35 #include "lnn_net_builder.h"
36 #include "legacy/softbus_adapter_hitrace.h"
37 #include "softbus_adapter_mem.h"
38
39 #define AUTH_GEN_CERT_PARA_EXPIRE_TIME 500
40 #define AUTH_GEN_CERT_PARA_TIME 10
41
42 static SoftBusList g_authPreLinkList;
43 static SoftBusList g_authGenCertParallelList;
44 static bool g_isInitAuthPreLinkList = false;
45 static bool g_isInitAuthGenCertList = false;
46
AuthGenCertParallelLock(void)47 static int32_t AuthGenCertParallelLock(void)
48 {
49 return SoftBusMutexLock(&g_authGenCertParallelList.lock);
50 }
51
AuthGenCertParallelUnLock(void)52 static void AuthGenCertParallelUnLock(void)
53 {
54 (void)SoftBusMutexUnlock(&g_authGenCertParallelList.lock);
55 }
56
InitAuthGenCertParallelList(void)57 int32_t InitAuthGenCertParallelList(void)
58 {
59 if (g_isInitAuthGenCertList) {
60 return SOFTBUS_OK;
61 }
62 if (SoftBusMutexInit(&g_authGenCertParallelList.lock, NULL) != SOFTBUS_OK) {
63 AUTH_LOGE(AUTH_CONN, "auth gen cert parallel init fail");
64 return SOFTBUS_NO_INIT;
65 }
66 ListInit(&g_authGenCertParallelList.list);
67 g_authGenCertParallelList.cnt = 0;
68 g_isInitAuthGenCertList = true;
69 return SOFTBUS_OK;
70 }
71
IsAuthGenCertParaNodeExist(int32_t requestId)72 static bool IsAuthGenCertParaNodeExist(int32_t requestId)
73 {
74 if (AuthGenCertParallelLock() != SOFTBUS_OK) {
75 AUTH_LOGE(AUTH_CONN, "auth generate certificate parallel lock fail");
76 return false;
77 }
78 AuthGenCertNode *item = NULL;
79 AuthGenCertNode *next = NULL;
80 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authGenCertParallelList.list, AuthGenCertNode, node) {
81 if (item->requestId == requestId) {
82 AuthGenCertParallelUnLock();
83 return true;
84 }
85 }
86 AuthGenCertParallelUnLock();
87 return false;
88 }
89
AddAuthGenCertParaNode(int32_t requestId)90 int32_t AddAuthGenCertParaNode(int32_t requestId)
91 {
92 if (IsAuthGenCertParaNodeExist(requestId)) {
93 AUTH_LOGE(AUTH_CONN, "auth gen cert parallel node exists");
94 return SOFTBUS_ALREADY_EXISTED;
95 }
96 AuthGenCertNode *item = (AuthGenCertNode *)SoftBusCalloc(sizeof(AuthGenCertNode));
97 if (item == NULL) {
98 AUTH_LOGE(AUTH_CONN, "item malloc fail");
99 return SOFTBUS_MALLOC_ERR;
100 }
101
102 item->requestId = requestId;
103 item->isValid = false;
104 atomic_store_explicit(&item->isParallelGen, 1, memory_order_release);
105 if (AuthGenCertParallelLock() != SOFTBUS_OK) {
106 AUTH_LOGE(AUTH_CONN, "auth generate certificate parallel lock fail");
107 SoftBusFree(item);
108 return SOFTBUS_LOCK_ERR;
109 }
110 ListAdd(&g_authGenCertParallelList.list, &item->node);
111 g_authGenCertParallelList.cnt++;
112 AuthGenCertParallelUnLock();
113 AUTH_LOGI(AUTH_CONN, "create new gencert parallel, authreq=%{public}d", requestId);
114 return SOFTBUS_OK;
115 }
116
FindAuthGenCertParaNodeById(int32_t requestId,AuthGenCertNode ** genCertParaNode)117 static int32_t FindAuthGenCertParaNodeById(int32_t requestId, AuthGenCertNode **genCertParaNode)
118 {
119 if (genCertParaNode == NULL) {
120 AUTH_LOGE(AUTH_CONN, "genCertParaNode pointer is null");
121 return SOFTBUS_INVALID_PARAM;
122 }
123 if (AuthGenCertParallelLock() != SOFTBUS_OK) {
124 AUTH_LOGE(AUTH_CONN, "auth generate certificate parallel lock fail");
125 return SOFTBUS_LOCK_ERR;
126 }
127 AuthGenCertNode *item = NULL;
128 AuthGenCertNode *next = NULL;
129 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authGenCertParallelList.list, AuthGenCertNode, node) {
130 if (item->requestId == requestId) {
131 *genCertParaNode = item;
132 AuthGenCertParallelUnLock();
133 return SOFTBUS_OK;
134 }
135 }
136 AuthGenCertParallelUnLock();
137 return SOFTBUS_NOT_FIND;
138 }
139
UpdateAuthGenCertParaNode(int32_t requestId,bool isParallelGen,bool isValid,SoftbusCertChain * softbusCertChain)140 int32_t UpdateAuthGenCertParaNode(int32_t requestId, bool isParallelGen, bool isValid,
141 SoftbusCertChain *softbusCertChain)
142 {
143 AUTH_CHECK_AND_RETURN_RET_LOGE(softbusCertChain != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "CertChain is NULL");
144 if (AuthGenCertParallelLock() != SOFTBUS_OK) {
145 AUTH_LOGE(AUTH_CONN, "auth generate certificate parallel lock fail");
146 return SOFTBUS_LOCK_ERR;
147 }
148 AuthGenCertNode *item = NULL;
149 AuthGenCertNode *next = NULL;
150 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authGenCertParallelList.list, AuthGenCertNode, node) {
151 if (item->requestId == requestId) {
152 item->isValid = isValid;
153 if (isParallelGen) {
154 atomic_store_explicit(&item->isParallelGen, 1, memory_order_release);
155 } else {
156 item->softbusCertChain = softbusCertChain;
157 atomic_store_explicit(&item->isParallelGen, 0, memory_order_release);
158 }
159 AuthGenCertParallelUnLock();
160 return SOFTBUS_OK;
161 }
162 }
163 AuthGenCertParallelUnLock();
164 return SOFTBUS_NOT_FIND;
165 }
166
FindAndWaitAuthGenCertParaNodeById(int32_t requestId,AuthGenCertNode ** genCertParaNode)167 int32_t FindAndWaitAuthGenCertParaNodeById(int32_t requestId, AuthGenCertNode **genCertParaNode)
168 {
169 AUTH_CHECK_AND_RETURN_RET_LOGE(genCertParaNode != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "CertParaNode is NULL");
170 int32_t ret = 0;
171 int32_t totalSleepMs = 0;
172 ret = FindAuthGenCertParaNodeById(requestId, genCertParaNode);
173 if (ret != SOFTBUS_OK) {
174 return ret;
175 }
176 while (((*genCertParaNode)->isParallelGen) && totalSleepMs < AUTH_GEN_CERT_PARA_EXPIRE_TIME) {
177 SoftBusSleepMs(AUTH_GEN_CERT_PARA_TIME);
178 totalSleepMs += AUTH_GEN_CERT_PARA_TIME;
179 }
180 if (totalSleepMs >= AUTH_GEN_CERT_PARA_EXPIRE_TIME || (*genCertParaNode)->isValid == false) {
181 DelAuthGenCertParaNodeById(requestId);
182 *genCertParaNode = NULL;
183 return SOFTBUS_AUTH_TIMEOUT;
184 }
185 if (*genCertParaNode == NULL) {
186 return SOFTBUS_AUTH_TIMEOUT;
187 }
188 if ((*genCertParaNode)->softbusCertChain == NULL) {
189 return SOFTBUS_AUTH_TIMEOUT;
190 }
191 return SOFTBUS_OK;
192 }
193
DelAuthGenCertParaNodeById(int32_t requestId)194 void DelAuthGenCertParaNodeById(int32_t requestId)
195 {
196 if (AuthGenCertParallelLock() != SOFTBUS_OK) {
197 AUTH_LOGE(AUTH_CONN, "auth generate certificate parallel lock fail");
198 return;
199 }
200 AuthGenCertNode *item = NULL;
201 AuthGenCertNode *next = NULL;
202 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authGenCertParallelList.list, AuthGenCertNode, node) {
203 if (item->requestId == requestId) {
204 ListDelete(&item->node);
205 FreeSoftbusChain(item->softbusCertChain);
206 SoftBusFree(item->softbusCertChain);
207 item->softbusCertChain = NULL;
208 SoftBusFree(item);
209 g_authGenCertParallelList.cnt--;
210 AuthGenCertParallelUnLock();
211 return;
212 }
213 }
214 AuthGenCertParallelUnLock();
215 }
216
DeinitAuthGenCertParallelList(void)217 void DeinitAuthGenCertParallelList(void)
218 {
219 if (AuthGenCertParallelLock() != SOFTBUS_OK) {
220 AUTH_LOGE(AUTH_CONN, "auth generate certificate parallel lock fail");
221 return;
222 }
223 AuthGenCertNode *item = NULL;
224 AuthGenCertNode *next = NULL;
225 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authGenCertParallelList.list, AuthGenCertNode, node) {
226 ListDelete(&item->node);
227 FreeSoftbusChain(item->softbusCertChain);
228 SoftBusFree(item->softbusCertChain);
229 item->softbusCertChain = NULL;
230 SoftBusFree(item);
231 if (g_authGenCertParallelList.cnt == 0) {
232 AUTH_LOGI(AUTH_CONN, "auth gencert parallel list cnt is 0.");
233 } else {
234 g_authGenCertParallelList.cnt--;
235 }
236 }
237 g_isInitAuthGenCertList = false;
238 AuthGenCertParallelUnLock();
239 SoftBusMutexDestroy(&g_authGenCertParallelList.lock);
240 }
241
AuthPreLinkLock(void)242 static int32_t AuthPreLinkLock(void)
243 {
244 return SoftBusMutexLock(&g_authPreLinkList.lock);
245 }
246
AuthPreLinkUnlock(void)247 static void AuthPreLinkUnlock(void)
248 {
249 (void)SoftBusMutexUnlock(&g_authPreLinkList.lock);
250 }
251
InitAuthPreLinkList(void)252 int32_t InitAuthPreLinkList(void)
253 {
254 if (g_isInitAuthPreLinkList) {
255 return SOFTBUS_OK;
256 }
257 if (SoftBusMutexInit(&g_authPreLinkList.lock, NULL) != SOFTBUS_OK) {
258 AUTH_LOGE(AUTH_CONN, "auth pre link init fail");
259 return SOFTBUS_NO_INIT;
260 }
261 ListInit(&g_authPreLinkList.list);
262 g_authPreLinkList.cnt = 0;
263 g_isInitAuthPreLinkList = true;
264 return SOFTBUS_OK;
265 }
266
IsAuthPreLinkNodeExist(uint32_t requestId)267 bool IsAuthPreLinkNodeExist(uint32_t requestId)
268 {
269 if (AuthPreLinkLock() != SOFTBUS_OK) {
270 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
271 return false;
272 }
273 AuthPreLinkNode *item = NULL;
274 AuthPreLinkNode *next = NULL;
275 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
276 if (item->requestId == requestId && item->connAddr.type == CONNECTION_ADDR_SESSION_WITH_KEY) {
277 AuthPreLinkUnlock();
278 return true;
279 }
280 }
281 AuthPreLinkUnlock();
282 return false;
283 }
284
AddToAuthPreLinkList(uint32_t requestId,int32_t fd,int32_t localDeviceKeyId,int32_t remoteDeviceKeyId,ConnectionAddr * connAddr)285 int32_t AddToAuthPreLinkList(uint32_t requestId, int32_t fd, int32_t localDeviceKeyId,
286 int32_t remoteDeviceKeyId, ConnectionAddr *connAddr)
287 {
288 if (IsAuthPreLinkNodeExist(requestId)) {
289 AUTH_LOGE(AUTH_CONN, "auth pre link exists");
290 return SOFTBUS_ALREADY_EXISTED;
291 }
292 AuthPreLinkNode *item = (AuthPreLinkNode *)SoftBusCalloc(sizeof(AuthPreLinkNode));
293 if (item == NULL) {
294 AUTH_LOGE(AUTH_CONN, "item malloc fail");
295 return SOFTBUS_MALLOC_ERR;
296 }
297 if (connAddr != NULL) {
298 if (memcpy_s(&item->connAddr, sizeof(ConnectionAddr), connAddr, sizeof(ConnectionAddr)) != EOK) {
299 AUTH_LOGE(AUTH_CONN, "copy connection addr failed");
300 }
301 }
302
303 item->fd = fd;
304 item->requestId = requestId;
305 item->connAddr.type = CONNECTION_ADDR_SESSION_WITH_KEY;
306 item->localDeviceKeyId = localDeviceKeyId;
307 item->remoteDeviceKeyId = remoteDeviceKeyId;
308 item->keyLen = 0;
309 if (AuthPreLinkLock() != SOFTBUS_OK) {
310 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
311 SoftBusFree(item);
312 return SOFTBUS_LOCK_ERR;
313 }
314 ListAdd(&g_authPreLinkList.list, &item->node);
315 g_authPreLinkList.cnt++;
316 AuthPreLinkUnlock();
317 AUTH_LOGI(AUTH_CONN, "create new auth reuse key node, requestId=%{public}d, fd=%{public}u", requestId, fd);
318 return SOFTBUS_OK;
319 }
320
FindAuthPreLinkNodeById(uint32_t requestId,AuthPreLinkNode * reuseNode)321 int32_t FindAuthPreLinkNodeById(uint32_t requestId, AuthPreLinkNode *reuseNode)
322 {
323 AUTH_CHECK_AND_RETURN_RET_LOGE(reuseNode != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "reuseNode is NULL");
324 if (AuthPreLinkLock() != SOFTBUS_OK) {
325 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
326 return SOFTBUS_LOCK_ERR;
327 }
328 AuthPreLinkNode *item = NULL;
329 AuthPreLinkNode *next = NULL;
330 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
331 if (item->requestId == requestId && item->connAddr.type == CONNECTION_ADDR_SESSION_WITH_KEY) {
332 if (memcpy_s(reuseNode, sizeof(AuthPreLinkNode), item, sizeof(AuthPreLinkNode)) != EOK) {
333 AUTH_LOGE(AUTH_CONN, "copy AuthPreLinkNode failed");
334 AuthPreLinkUnlock();
335 return SOFTBUS_MEM_ERR;
336 }
337 AuthPreLinkUnlock();
338 return SOFTBUS_OK;
339 }
340 }
341 AuthPreLinkUnlock();
342 return SOFTBUS_NOT_FIND;
343 }
344
FindAuthPreLinkNodeByUuid(const char * uuid,AuthPreLinkNode * preLinkNode)345 int32_t FindAuthPreLinkNodeByUuid(const char *uuid, AuthPreLinkNode *preLinkNode)
346 {
347 AUTH_CHECK_AND_RETURN_RET_LOGE(uuid != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "uuid is NULL");
348 AUTH_CHECK_AND_RETURN_RET_LOGE(preLinkNode != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "uuid is NULL");
349 if (AuthPreLinkLock() != SOFTBUS_OK) {
350 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
351 return SOFTBUS_LOCK_ERR;
352 }
353 AuthPreLinkNode *item = NULL;
354 AuthPreLinkNode *next = NULL;
355 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
356 if (memcmp(item->uuid, uuid, UUID_BUF_LEN) == 0) {
357 if (memcpy_s(preLinkNode, sizeof(AuthPreLinkNode), item, sizeof(AuthPreLinkNode)) != EOK) {
358 AUTH_LOGE(AUTH_CONN, "copy AuthPreLinkNode failed");
359 AuthPreLinkUnlock();
360 return SOFTBUS_MEM_ERR;
361 }
362 AuthPreLinkUnlock();
363 return SOFTBUS_OK;
364 }
365 }
366 AuthPreLinkUnlock();
367 return SOFTBUS_NOT_FIND;
368 }
369
UpdateAuthPreLinkUuidById(uint32_t requestId,char * uuid)370 int32_t UpdateAuthPreLinkUuidById(uint32_t requestId, char *uuid)
371 {
372 AUTH_CHECK_AND_RETURN_RET_LOGE(uuid != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "uuid is NULL");
373 if (AuthPreLinkLock() != SOFTBUS_OK) {
374 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
375 return SOFTBUS_LOCK_ERR;
376 }
377 AuthPreLinkNode *item = NULL;
378 AuthPreLinkNode *next = NULL;
379 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
380 if (item->requestId == requestId && item->connAddr.type == CONNECTION_ADDR_SESSION_WITH_KEY) {
381 if (memcpy_s(item->uuid, UUID_BUF_LEN, uuid, UUID_BUF_LEN) != EOK) {
382 AUTH_LOGE(AUTH_CONN, "memcpy uuid failed");
383 AuthPreLinkUnlock();
384 return SOFTBUS_MEM_ERR;
385 }
386 AuthPreLinkUnlock();
387 return SOFTBUS_OK;
388 }
389 }
390 AuthPreLinkUnlock();
391 return SOFTBUS_NOT_FIND;
392 }
393
UpdateAuthPreLinkDeviceKeyById(uint32_t requestId,uint8_t * deviceKey,uint32_t keyLen)394 int32_t UpdateAuthPreLinkDeviceKeyById(uint32_t requestId, uint8_t *deviceKey, uint32_t keyLen)
395 {
396 AUTH_CHECK_AND_RETURN_RET_LOGE(deviceKey != NULL, SOFTBUS_INVALID_PARAM, AUTH_CONN, "deviceKey is NULL");
397 if (AuthPreLinkLock() != SOFTBUS_OK) {
398 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
399 return SOFTBUS_LOCK_ERR;
400 }
401 AuthPreLinkNode *item = NULL;
402 AuthPreLinkNode *next = NULL;
403 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
404 if (item->requestId == requestId && item->connAddr.type == CONNECTION_ADDR_SESSION_WITH_KEY) {
405 if (memcpy_s(item->localDeviceKey, SESSION_KEY_LENGTH, deviceKey, SESSION_KEY_LENGTH) != EOK) {
406 AUTH_LOGE(AUTH_CONN, "memcpy device key fail");
407 AuthPreLinkUnlock();
408 return SOFTBUS_MEM_ERR;
409 }
410 item->keyLen = keyLen;
411 AuthPreLinkUnlock();
412 return SOFTBUS_OK;
413 }
414 }
415 AuthPreLinkUnlock();
416 return SOFTBUS_NOT_FIND;
417 }
418
UpdateAuthPreLinkDeviceKeyIdById(uint32_t requestId,bool isRemote,int32_t deviceKeyId)419 int32_t UpdateAuthPreLinkDeviceKeyIdById(uint32_t requestId, bool isRemote, int32_t deviceKeyId)
420 {
421 if (AuthPreLinkLock() != SOFTBUS_OK) {
422 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
423 return SOFTBUS_LOCK_ERR;
424 }
425 AuthPreLinkNode *item = NULL;
426 AuthPreLinkNode *next = NULL;
427 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
428 if (item->requestId == requestId && item->connAddr.type == CONNECTION_ADDR_SESSION_WITH_KEY) {
429 if (isRemote) {
430 item->remoteDeviceKeyId = deviceKeyId;
431 } else {
432 item->localDeviceKeyId = deviceKeyId;
433 }
434 AuthPreLinkUnlock();
435 return SOFTBUS_OK;
436 }
437 }
438 AuthPreLinkUnlock();
439 return SOFTBUS_NOT_FIND;
440 }
441
DelAuthPreLinkById(uint32_t requestId)442 void DelAuthPreLinkById(uint32_t requestId)
443 {
444 if (AuthPreLinkLock() != SOFTBUS_OK) {
445 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
446 return;
447 }
448 AuthPreLinkNode *item = NULL;
449 AuthPreLinkNode *next = NULL;
450 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
451 if (item->requestId == requestId) {
452 ListDelete(&item->node);
453 g_authPreLinkList.cnt--;
454 SoftBusFree(item);
455 AuthPreLinkUnlock();
456 return;
457 }
458 }
459 AuthPreLinkUnlock();
460 }
461
DelAuthPreLinkByUuid(char * uuid)462 void DelAuthPreLinkByUuid(char *uuid)
463 {
464 AUTH_CHECK_AND_RETURN_LOGE(uuid != NULL, AUTH_CONN, "uuid is NULL");
465 if (AuthPreLinkLock() != SOFTBUS_OK) {
466 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
467 return;
468 }
469 AuthPreLinkNode *item = NULL;
470 AuthPreLinkNode *next = NULL;
471 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
472 if (memcmp(item->uuid, uuid, UUID_BUF_LEN) == 0) {
473 ListDelete(&item->node);
474 g_authPreLinkList.cnt--;
475 SoftBusFree(item);
476 AuthPreLinkUnlock();
477 return;
478 }
479 }
480 AuthPreLinkUnlock();
481 }
482
DeinitAuthPreLinkList(void)483 void DeinitAuthPreLinkList(void)
484 {
485 AuthPreLinkNode *item = NULL;
486 AuthPreLinkNode *next = NULL;
487 if (AuthPreLinkLock() != SOFTBUS_OK) {
488 AUTH_LOGE(AUTH_CONN, "auth pre link lock fail");
489 return;
490 }
491 LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_authPreLinkList.list, AuthPreLinkNode, node) {
492 ListDelete(&item->node);
493 g_authPreLinkList.cnt--;
494 SoftBusFree(item);
495 }
496 g_isInitAuthPreLinkList = false;
497 AuthPreLinkUnlock();
498 (void)SoftBusMutexDestroy(&g_authPreLinkList.lock);
499 }