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 CONN_COMMON_H
17 #define CONN_COMMON_H
18
19 #include <stdint.h>
20 #include "hitls_build.h"
21 #include "tls.h"
22 #include "hitls_type.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #define MAX_ALERT_COUNT 5u
29 #define GET_GROUPS_CNT (-1)
30
31 typedef int32_t (*ManageEventProcess)(HITLS_Ctx *ctx);
32
33 typedef int32_t (*WriteEventProcess)(HITLS_Ctx *ctx, const uint8_t *data, uint32_t dataLen, uint32_t *writeLen);
34
35 typedef int32_t (*ReadEventProcess)(HITLS_Ctx *ctx, uint8_t *data, uint32_t bufSize, uint32_t *readLen);
36
GetConnState(const HITLS_Ctx * ctx)37 static inline CM_State GetConnState(const HITLS_Ctx *ctx)
38 {
39 return ctx->state;
40 }
41 #ifdef HITLS_TLS_FEATURE_PHA
42 int32_t CommonCheckPostHandshakeAuth(TLS_Ctx *ctx);
43 #endif
44 /**
45 * @ingroup hitls
46 * @brief General processing of all events in alerting state
47 */
48 int32_t CommonEventInAlertingState(HITLS_Ctx *ctx);
49
50 /**
51 * @ingroup hitls
52 * @brief Processe of common events in hanshaking state, attempt to establish a connection
53 */
54 int32_t CommonEventInHandshakingState(HITLS_Ctx *ctx);
55
56 /**
57 * @ingroup hitls
58 * @brief If the local end generates an Alert message when sending or receiving messages or processing handshake
59 * messages, or receives an Alert message from the peer end, the AlertEventProcess needs to be invoked to
60 * process the Alert status.
61 */
62 int32_t AlertEventProcess(HITLS_Ctx *ctx);
63
64 void ChangeConnState(HITLS_Ctx *ctx, CM_State state);
65
66 #ifdef HITLS_TLS_FEATURE_RENEGOTIATION
67 /**
68 * @ingroup hitls
69 * @brief In the renegotiation state, process the renegotiation event and attempt to establish a connection
70 *
71 * @param ctx [IN] TLS connection handle
72 *
73 * @retval HITLS_SUCCESS succeeded
74 * @retval For other error codes, see hitls_error.h
75 */
76 int32_t CommonEventInRenegotiationState(HITLS_Ctx *ctx);
77
78 /**
79 * @ingroup hitls
80 * @brief In the renegotiation state, process no_renegotiation alert.
81 * Send a handshake_failure alert if no_renegotiation alert is received.
82 *
83 * @param ctx [IN] TLS connection handle
84 *
85 */
86 void InnerRenegotiationProcess(HITLS_Ctx *ctx);
87 #endif
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif
94