1 /*
2  * Copyright (c) 2023 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 NET_SSL_C_TYPE_H
17 #define NET_SSL_C_TYPE_H
18 
19 /**
20  * @addtogroup netstack
21  * @{
22  *
23  * @brief Provides C APIs for the SSL/TLS certificate chain verification module.
24  *
25  * @since 11
26  * @version 1.0
27  */
28 
29 /**
30  * @file net_ssl_c_type.h
31  * @brief Defines the data structures for the C APIs of the SSL/TLS certificate chain verification module.
32  *
33  * @library libnet_ssl.so
34  * @syscap SystemCapability.Communication.NetStack
35  * @since 11
36  * @version 1.0
37  */
38 
39 #include <stdint.h>
40 #include <cstddef>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Enumerates certificate types.
48  *
49  * @since 11
50  * @version 1.0
51  */
52 enum NetStack_CertType {
53     /** PEM certificate */
54     NETSTACK_CERT_TYPE_PEM = 0,
55     /** DER certificate */
56     NETSTACK_CERT_TYPE_DER = 1,
57     /** Invalid certificate */
58     NETSTACK_CERT_TYPE_INVALID
59 };
60 
61 /**
62  * @brief Defines the certificate data structure.
63  *
64  * @since 11
65  * @version 1.0
66  */
67 struct NetStack_CertBlob {
68     /** Certificate type */
69     enum NetStack_CertType type;
70     /** Certificate content length */
71     uint32_t size;
72     /** Certificate content */
73     uint8_t *data;
74 };
75 
76 typedef enum NetStack_CertificatePinningKind {
77     PUBLIC_KEY,
78 } NetStack_CertificatePinningKind;
79 
80 typedef enum NetStack_HashAlgorithm {
81     SHA_256,
82 } NetStack_HashAlgorithm;
83 
84 typedef struct NetStack_CertificatePinning {
85     NetStack_CertificatePinningKind kind;
86     NetStack_HashAlgorithm hashAlgorithm;
87     union {
88         char *publicKeyHash;
89     };
90 } NetStack_CertificatePinning;
91 
92 typedef struct NetStack_Certificates {
93     char **content;
94     size_t length;
95 } NetStack_Certificates;
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif // NET_SSL_C_TYPE_H
102