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 16 #ifndef AUTH_PRE_LINK_H 17 #define AUTH_PRE_LINK_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 #include <stdatomic.h> 22 #include "common_list.h" 23 #include "softbus_common.h" 24 #include "auth_attest_interface.h" 25 26 #define AUTH_INVALID_DEVICEKEY_ID 0x0 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 typedef struct { 33 int32_t localDeviceKeyId; 34 int32_t remoteDeviceKeyId; 35 uint8_t localDeviceKey[SESSION_KEY_LENGTH]; 36 uint32_t keyLen; 37 char uuid[UUID_BUF_LEN]; 38 ConnectionAddr connAddr; 39 int32_t fd; 40 uint32_t requestId; 41 ListNode node; 42 } AuthPreLinkNode; 43 44 typedef struct { 45 bool isValid; 46 _Atomic int isParallelGen; 47 int32_t requestId; 48 SoftbusCertChain *softbusCertChain; 49 ListNode node; 50 } AuthGenCertNode; 51 52 int32_t InitAuthPreLinkList(void); 53 bool IsAuthPreLinkNodeExist(uint32_t requestId); 54 int32_t AddToAuthPreLinkList(uint32_t requestId, int32_t fd, int32_t localDeviceKeyId, 55 int32_t remoteDeviceKeyId, ConnectionAddr *connAddr); 56 int32_t FindAuthPreLinkNodeById(uint32_t requestId, AuthPreLinkNode *reuseNode); 57 int32_t FindAuthPreLinkNodeByUuid(const char *uuid, AuthPreLinkNode *reuseNode); 58 int32_t UpdateAuthPreLinkUuidById(uint32_t requestId, char *uuid); 59 int32_t UpdateAuthPreLinkDeviceKeyById(uint32_t requestId, uint8_t *deviceKey, uint32_t keyLen); 60 int32_t UpdateAuthPreLinkDeviceKeyIdById(uint32_t requestId, bool isRemote, int32_t deviceKeyId); 61 void DelAuthPreLinkById(uint32_t requestId); 62 void DelAuthPreLinkByUuid(char *uuid); 63 void DeinitAuthPreLinkList(void); 64 65 int32_t InitAuthGenCertParallelList(void); 66 int32_t AddAuthGenCertParaNode(int32_t requestId); 67 int32_t UpdateAuthGenCertParaNode(int32_t requestId, bool isParallelGen, bool isValid, 68 SoftbusCertChain *softbusCertChain); 69 int32_t FindAndWaitAuthGenCertParaNodeById(int32_t requestId, AuthGenCertNode **genCertParaNode); 70 void DelAuthGenCertParaNodeById(int32_t requestId); 71 void DeinitAuthGenCertParallelList(void); 72 73 #ifdef __cplusplus 74 } 75 #endif 76 #endif /* AUTH_PRE_LINK_H */