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 /** 17 * @defgroup hitls_sni 18 * @ingroup hitls 19 * @brief TLS SNI correlation type 20 */ 21 22 #ifndef HITLS_SNI_H 23 #define HITLS_SNI_H 24 25 #include <stdint.h> 26 #include "hitls_type.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /* Currently, the SNI supports only the host name type. */ 33 34 /** 35 * @ingroup hitls_sni 36 * @brief Currently, the SNI supports only the host name type. 37 */ 38 typedef enum { 39 HITLS_SNI_HOSTNAME_TYPE, 40 HITLS_SNI_BUTT = 255 /* Maximum enumerated value */ 41 } SNI_Type; 42 43 #define HITLS_ACCEPT_SNI_ERR_OK 0 /* Accepts the request and continues handshake. */ 44 #define HITLS_ACCEPT_SNI_ERR_ALERT_FATAL 2 /* Do not accept the request and aborts the handshake. */ 45 #define HITLS_ACCEPT_SNI_ERR_NOACK 3 /* Do not accept the request but continues the handshake. */ 46 47 /** 48 * @ingroup hitls_sni 49 * @brief Obtain the value of server_name before, during, or after the handshake on the client or server. 50 * 51 * @param ctx [IN] TLS connection handle 52 * @param type [IN] serverName type 53 * @retval The value of server_name, if successful. 54 * NULL, if failure. 55 */ 56 const char *HITLS_GetServerName(const HITLS_Ctx *ctx, const int type); 57 58 /** 59 * @ingroup hitls_sni 60 * @brief Obtain the server_name type before, during, or after the handshake on the client or server. 61 * 62 * @param ctx [IN] TLS connection handle 63 * @retval HITLS_SNI_HOSTNAME_TYPE, if successful. 64 * -1: if failure. 65 */ 66 int32_t HITLS_GetServernameType(const HITLS_Ctx *ctx); 67 68 /** 69 * @ingroup hitls_sni 70 * @brief Set server_name. 71 * 72 * @param config [OUT] config Context 73 * @param serverName [IN] serverName 74 * @param serverNameStrlen [IN] serverName length 75 * @retval HITLS_SUCCESS, if successful. 76 * For details about other error codes, see hitls_error.h. 77 */ 78 int32_t HITLS_CFG_SetServerName(HITLS_Config *config, uint8_t *serverName, uint32_t serverNameStrlen); 79 80 /** 81 * @ingroup hitls_sni 82 * @brief Obtain the value of server_name configured on the client. 83 * 84 * @param config [IN] config Context 85 * @param serverName [OUT] serverName 86 * @param serverNameStrlen [OUT] serverName length 87 * @retval HITLS_SUCCESS, if successful. 88 * For details about other error codes, see hitls_error.h. 89 */ 90 int32_t HITLS_CFG_GetServerName(HITLS_Config *config, uint8_t **serverName, uint32_t *serverNameStrlen); 91 92 /** 93 * @ingroup hitls_sni 94 * @brief Set the extension prototype for the server to process Client Hello server_name. 95 * 96 * @param ctx [IN] ctx context. 97 * @param alert [IN] Warning information. 98 * @param arg [IN] The server supports the input parameters related to server_name. 99 * @retval The user return value contains: 100 * HITLS_ACCEPT_SNI_ERR_OK 0 (received, server_name null extension) 101 * HITLS_ACCEPT_SNI_ERR_ALERT_FATAL 2 (Do not accept, abort handshake) 102 * HITLS_ACCEPT_SNI_ERR_NOACK 3 (not accepted, but continue handshake, not sending server_name null extension) 103 */ 104 typedef int32_t (*HITLS_SniDealCb)(HITLS_Ctx *ctx, int *alert, void *arg); 105 106 /** 107 * @ingroup hitls_sni 108 * @brief Set the server_name callback function on the server, which is used for SNI negotiation, cb can be NULL. 109 * 110 * @param config [OUT] Config Context 111 * @param callback [IN] Server callback implemented by the user 112 * @retval HITLS_SUCCESS, if successful. 113 * For details about other error codes, see hitls_error.h. 114 */ 115 int32_t HITLS_CFG_SetServerNameCb(HITLS_Config *config, HITLS_SniDealCb callback); 116 117 /** 118 * @ingroup hitls_sni 119 * @brief Set the server_name parameters required during SNI negotiation on the server. 120 * 121 * @param config [OUT] Config context 122 * @param arg [IN] Set parameters related to server_name. 123 * @retval HITLS_SUCCESS, if successful. 124 * For details about other error codes, see hitls_error.h. 125 */ 126 int32_t HITLS_CFG_SetServerNameArg(HITLS_Config *config, void *arg); 127 128 /** 129 * @ingroup hitls_sni 130 * @brief Obtain the server_name callback settings on the server. 131 * 132 * @param config [IN] config Context 133 * @param callback [IN] [OUT] Server callback implemented by the user 134 * @retval HITLS_SUCCESS, if successful. 135 * For details about other error codes, see hitls_error.h. 136 */ 137 int32_t HITLS_CFG_GetServerNameCb(HITLS_Config *config, HITLS_SniDealCb *callback); 138 139 /** 140 * @ingroup hitls_sni 141 * @brief Obtain the server_name required during SNI negotiation on the server, related Parameter arg. 142 * 143 * @param config [IN] Config context 144 * @param arg [IN] [OUT] Set parameters related to server_name.arg 145 * @retval HITLS_SUCCESS, if successful. 146 * For details about other error codes, see hitls_error.h. 147 */ 148 int32_t HITLS_CFG_GetServerNameArg(HITLS_Config *config, void **arg); 149 150 #ifdef __cplusplus 151 } 152 #endif 153 154 #endif