API参考
载入中...
搜索中...
未找到
app_tls_common.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#ifndef HITLS_APP_TLS_COMMON_H
17#define HITLS_APP_TLS_COMMON_H
18
19#include <stdint.h>
20#include <stdbool.h>
21#include "bsl_types.h"
22#include "bsl_uio.h"
23#include "hitls_config.h"
24#include "hitls_pki_cert.h"
25#include "hitls.h"
26#include "hitls_cert.h"
27#include "crypt_eal_pkey.h"
28#include "app_provider.h"
29#include "app_sm.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#define APP_HEARTBEAT_LEN 17
36#define DEFAULT_DTLCP_PORT 54000
37#define HTTP_BUF_MAXLEN (18 * 1024) /* 18KB */
38
39/* Protocol types */
40typedef enum {
41 APP_PROTOCOL_TLS, // International standard TLS protocol (default)
42 APP_PROTOCOL_TLCP,
43 APP_PROTOCOL_DTLCP,
44} APP_ProtocolType;
45
46/* Network address structure */
47typedef struct {
48 char *host;
49 int port;
51
52/* Certificate configuration structure */
53typedef struct {
54 char *keyPass;
55 char *caFile;
56 char *caChain;
57 BSL_ParseFormat certFormat;
58 BSL_ParseFormat keyFormat;
59
60 /* TLCP specific certificates */
61 char *tlcpEncCert;
62 char *tlcpEncKey;
63 char *tlcpSignCert;
64 char *tlcpSignKey;
65 AppProvider *provider;
66#ifdef HITLS_APP_SM_MODE
67 HITLS_APP_SM_Param *smParam;
68#endif
70
76APP_ProtocolType ParseProtocolType(const char *protocolStr);
77
83HITLS_Config *CreateProtocolConfig(APP_ProtocolType protocol, AppProvider *provider);
84
92int ConfigureCipherSuites(HITLS_Config *config, const char *cipherStr, APP_ProtocolType protocol);
93
101HITLS_X509_Cert *LoadCertFromFile(const char *certFile, BSL_ParseFormat format, AppProvider *provider);
102
112int ConfCertVerification(HITLS_Config *config, APP_CertConfig *certConfig,
113 bool verifyPeer, int verifyDepth);
114
122int ConfigureTLCPCertificates(HITLS_Config *config, APP_CertConfig *certConfig);
123
130int CreateTCPSocket(APP_NetworkAddr *addr, int timeout);
131
138int CreateUDPSocket(APP_NetworkAddr *addr, int timeout);
139
146int CreateTCPListenSocket(APP_NetworkAddr *addr, int backlog);
147
153int CreateUDPListenSocket(APP_NetworkAddr *addr, int timeout);
154
160int AcceptTCPConnection(int listenFd);
161
167void PrintConnectionInfo(HITLS_Ctx *ctx, bool showState);
168
173void PrintCertificateChain(HITLS_Ctx *ctx);
174
179void PrintHandshakeState(HITLS_Ctx *ctx);
180
187int ParseConnectString(const char *connectStr, APP_NetworkAddr *addr);
188
189int32_t GetHeartBeat(uint8_t *buffer, uint32_t *len);
190
191int32_t ParseHeartBeat(uint8_t *buffer, uint32_t len);
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif /* HITLS_APP_TLS_COMMON_H */
struct TlsCtx HITLS_Ctx
HITLS context
定义 hitls_type.h:35
struct TlsConfig HITLS_Config
config context
定义 hitls_type.h:41
定义 app_tls_common.h:53
定义 app_tls_common.h:47
定义 app_provider.h:25