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 HS_H 17 #define HS_H 18 19 #include "tls.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /** 26 * @brief Initialize the handshake context 27 * 28 * @param ctx [IN] TLS object 29 * 30 * @retval HITLS_SUCCESS succeeded 31 */ 32 int32_t HS_Init(TLS_Ctx *ctx); 33 34 /** 35 * @brief Release the handshake context 36 * 37 * @param ctx [IN] TLS object 38 */ 39 void HS_DeInit(TLS_Ctx *ctx); 40 41 /** 42 * @brief Establish a TLS connection 43 * 44 * @param ctx [IN] TLS object 45 * 46 * @retval HITLS_SUCCESS The connection is successfully established. 47 * @retval For details about other error codes, see hitls_error.h 48 */ 49 int32_t HS_DoHandshake(TLS_Ctx *ctx); 50 51 52 /** 53 * @brief Generate the session key 54 * 55 * @param ctx [IN] TLS context 56 * @param isClient [IN] Client or Not 57 * 58 * @retval HITLS_SUCCESS succeeded 59 * @retval For details about other error codes, see hitls_error.h 60 */ 61 int32_t HS_KeyEstablish(TLS_Ctx *ctx, bool isClient); 62 63 /** 64 * @brief Session recovery Generate a session key. 65 * 66 * @param ctx [IN] TLS context 67 * 68 * @retval HITLS_SUCCESS succeeded 69 * @retval For details about other error codes, see hitls_error.h 70 */ 71 int32_t HS_ResumeKeyEstablish(TLS_Ctx *ctx); 72 73 /** 74 * @brief Obtain the current handshake status 75 * 76 * @param ctx [IN] TLS context 77 * 78 * @retval Current handshake status 79 */ 80 uint32_t HS_GetState(const TLS_Ctx *ctx); 81 82 /** 83 * @brief Obtain the version number. If the version number is not negotiated, the latest version 84 * supported by the local is returned. 85 * 86 * @param ctx [IN] TLS context 87 * 88 * @return Return the version number. 89 */ 90 uint32_t HS_GetVersion(const TLS_Ctx *ctx); 91 92 /** 93 * @brief Obtain the handshake status character string. 94 * 95 * @param state [IN] Handshake status 96 * 97 * @return Character string corresponding to the handshake status 98 */ 99 const char *HS_GetStateStr(uint32_t state); 100 101 /** 102 * @brief Check whether the conditions for sending keyupdate are met 103 * 104 * @param ctx [IN] TLS context 105 * @param updateType [IN] keyupdate type 106 * 107 * @retval HITLS_SUCCESS succeeded. 108 * @retval For details about other error codes, see hitls_error.h 109 */ 110 int32_t HS_CheckKeyUpdateState(TLS_Ctx *ctx, uint32_t updateType); 111 112 113 /** 114 * @brief Obtain the server_name in the handshake TLS context. 115 * 116 * @param ctx [IN] TLS context 117 * 118 * @return string of server_name in the TLS context during the handshake 119 */ 120 const char *HS_GetServerName(const TLS_Ctx *ctx); 121 122 /** 123 * @brief Determine and handle the 2MSL timeout 124 * 125 * @param ctx [IN] TLS context 126 * 127 * @return string of server_name in the TLS context during the handshake 128 */ 129 #ifdef HITLS_TLS_PROTO_DTLS12 130 int32_t HS_CheckAndProcess2MslTimeout(TLS_Ctx *ctx); 131 #endif 132 133 int32_t HS_CheckPostHandshakeAuth(TLS_Ctx *ctx); 134 135 #define TLS_IS_FIRST_HANDSHAKE(ctx) ((ctx)->negotiatedInfo.clientVerifyDataSize == 0 \ 136 || (ctx)->negotiatedInfo.serverVerifyDataSize == 0) 137 138 #ifdef __cplusplus 139 } 140 #endif 141 #endif /* HS_H */