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_UK_MANAGER_H 17 #define AUTH_UK_MANAGER_H 18 19 #include <securec.h> 20 #include <stdbool.h> 21 #include <stdint.h> 22 #include "softbus_common.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define ACCOUNT_ID_BUF_LEN 65 29 #define UK_ENCRYPT_INDEX_LEN (ENCRYPT_INDEX_LEN * 2) 30 #define UK_ENCRYPT_OVER_HEAD_LEN (OVERHEAD_LEN + UK_ENCRYPT_INDEX_LEN) 31 32 typedef struct { 33 bool isServer; 34 int32_t sourceUserId; 35 int32_t sinkUserId; 36 int64_t sourceTokenId; 37 int64_t sinkTokenId; 38 char sourceUdid[UDID_BUF_LEN]; 39 char sinkUdid[UDID_BUF_LEN]; 40 char sourceAccountId[ACCOUNT_ID_BUF_LEN]; 41 char sinkAccountId[ACCOUNT_ID_BUF_LEN]; 42 } AuthACLInfo; 43 44 typedef struct { 45 bool isRecvSessionKeyEvent; 46 bool isRecvFinishEvent; 47 bool isRecvCloseAckEvent; 48 } UkNegotiateInfo; 49 50 typedef struct { 51 void (*onGenSuccess)(uint32_t requestId, int32_t ukId); 52 void (*onGenFailed)(uint32_t requestId, int32_t reason); 53 } AuthGenUkCallback; 54 55 int32_t AuthFindUkIdByAclInfo(const AuthACLInfo *acl, int32_t *ukId); 56 int32_t AuthGenUkIdByAclInfo(const AuthACLInfo *acl, uint32_t requestId, const AuthGenUkCallback *genCb); 57 uint32_t AuthGetUkEncryptSize(uint32_t inLen); 58 uint32_t AuthGetUkDecryptSize(uint32_t inLen); 59 int32_t AuthEncryptByUkId(int32_t ukId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 60 int32_t AuthDecryptByUkId(int32_t ukId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen); 61 uint32_t GenUkSeq(void); 62 bool CompareByAllAcl(const AuthACLInfo *oldAcl, const AuthACLInfo *newAcl, bool isSameSide); 63 bool CompareByAclDiffAccount(const AuthACLInfo *oldAcl, const AuthACLInfo *newAcl, bool isSameSide); 64 bool CompareByAclDiffAccountWithUserLevel(const AuthACLInfo *oldAcl, const AuthACLInfo *newAcl, bool isSameSide); 65 bool CompareByAclSameAccount(const AuthACLInfo *oldAcl, const AuthACLInfo *newAcl, bool isSameSide); 66 bool AuthIsUkExpired(uint64_t time); 67 int32_t UkNegotiateInit(void); 68 void UkNegotiateDeinit(void); 69 void UkNegotiateSessionInit(void); 70 void PrintfAuthAclInfo(uint32_t requestId, uint32_t channelId, const AuthACLInfo *info); 71 72 #ifdef __cplusplus 73 } 74 #endif 75 76 #endif // AUTH_UK_MANAGER_H 77 78