1 /*
2  * Copyright (c) 2024 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_ATTEST_INTERFACE_H
17 #define AUTH_ATTEST_INTERFACE_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #include "lnn_node_info.h"
23 #include "auth_interface.h"
24 #include "auth_session_fsm.h"
25 
26 #ifdef __cplusplus
27 #if __cplusplus
28 extern "C" {
29 #endif
30 #endif
31 
32 #define SOFTBUS_CERTIFICATE_SIZE 8192
33 #define SOFTBUS_CERTS_COUNT 4
34 #define ATTEST_CERTS_INDEX 0
35 #define DEVICE_CERTS_INDEX 1
36 #define MANUFACTURE_CERTS_INDEX 2
37 #define ROOT_CERTS_INDEX 3
38 
39 typedef struct {
40     uint32_t size;
41     uint8_t *data;
42 } SoftbusBlob;
43 
44 typedef struct {
45     SoftbusBlob cert[SOFTBUS_CERTS_COUNT];
46     uint32_t certCount;
47 } SoftbusCertChain;
48 
49 bool IsSupportUDIDAbatement(void);
50 bool IsNeedUDIDAbatement(const AuthSessionInfo *info);
51 bool CalcHKDF(const uint8_t *ikm, uint32_t ikmLen, uint8_t *out, uint32_t outLen);
52 int32_t GenerateCertificate(SoftbusCertChain *softbusCertChain, const AuthSessionInfo *info);
53 int32_t VerifyCertificate(SoftbusCertChain *softbusCertChain, const NodeInfo *nodeInfo, const AuthSessionInfo *info);
54 int32_t InitSoftbusChain(SoftbusCertChain *softbusCertChain);
55 void FreeSoftbusChain(SoftbusCertChain *softbusCertChain);
56 bool IsCertAvailable(void);
57 
58 #ifdef __cplusplus
59 #if __cplusplus
60 }
61 #endif
62 #endif
63 #endif /* AUTH_ATTEST_INTERFACE_H */