• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_alpn
18  * @ingroup  hitls
19  * @brief    TLS ALPN related type
20  */
21 
22 #ifndef HITLS_ALPN_H
23 #define HITLS_ALPN_H
24 
25 #include <stdint.h>
26 #include "hitls_type.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #define HITLS_ALPN_ERR_OK 0                 /* Correct execution. */
33 #define HITLS_ALPN_ERR_ALERT_WARNING 1      /* Execution error, sent warning alert. */
34 #define HITLS_ALPN_ERR_ALERT_FATAL 2        /* Execution error, sent fatal alert. */
35 #define HITLS_ALPN_ERR_NOACK 3              /* Execution exception, ignore processing. */
36 
37 /**
38  * @ingroup hitls_alpn
39  * @brief   Callback prototype for selecting the ALPN protocol on the server, which is used to select
40  * the application layer protocol during ALPN negotiation.
41  *
42  * @param   ctx  [IN] Ctx context.
43  * @param   selectedProto   [OUT] Indicates the initial IP address of the protocol that is being matched.
44  * @param   selectedProtoLen  [OUT] Matching protocol length.
45  * @param   clientAlpnList   [IN] Client ALPN List.
46  * @param   clientAlpnListSize  [IN] Client ALPN List length.
47  * @param   userData   [IN] Context transferred by the user.
48  * @retval  HITLS_ALPN_ERR_OK 0, indicates success.
49             HITLS_ALPN_ERR_ALERT_WARNING 1, indicates send warning alert.
50             HITLS_ALPN_ERR_ALERT_FATAL 2, indicates send fatal alert.
51             HITLS_ALPN_ERR_NOACK 3, indicates no processing.
52  */
53 typedef int32_t (*HITLS_AlpnSelectCb)(HITLS_Ctx *ctx, uint8_t **selectedProto, uint8_t *selectedProtoSize,
54     uint8_t *clientAlpnList, uint32_t clientAlpnListSize, void *userData);
55 
56 /**
57  * @ingroup hitls_alpn
58  * @brief   Sets the ALPN list on the client, which is used to negotiate the application layer protocol
59  * with the server in the handshake phase.
60  *
61  * @param   config  [OUT] Config context.
62  * @param   alpnProtos    [IN] Application layer protocol list.
63  * @param   alpnProtosLen    [IN] Length of the application layer protocol list.
64  * @retval  If success, return HITLS_SUCCESS.
65  *          For details about other error codes, see hitls_error.h.
66  */
67 int32_t HITLS_CFG_SetAlpnProtos(HITLS_Config *config, const uint8_t *alpnProtos, uint32_t alpnProtosLen);
68 
69 /**
70  * @ingroup hitls_alpn
71  * @brief   Sets the ALPN selection callback on the server.
72  *
73  * The callback is used to select the application layer protocol in the handshake phase, cb can be NULL.
74  *
75  * @param   config  [OUT] Config context.
76  * @param   callback    [IN] Server callback implemented by the user.
77  * @param   userData    [IN] Product context.
78  * @retval  If success, return HITLS_SUCCESS.
79  *          For details about other error codes, see hitls_error.h.
80  */
81 int32_t HITLS_CFG_SetAlpnProtosSelectCb(HITLS_Config *config, HITLS_AlpnSelectCb callback, void *userData);
82 
83 /**
84  * @ingroup hitls_alpn
85  * @brief   Sets the client ALPN list, which is used to negotiate the application layer protocol
86  * with the server in the handshake phase.
87  *
88  * @param   ctx  [OUT] TLS connection Handle.
89  * @param   protos    [IN] Application layer protocol list.
90  * @param   protosLen    [IN] Length of the application layer protocol list.
91  * @retval  If success, return HITLS_SUCCESS.
92  *          For details about other error codes, see hitls_error.h.
93  */
94 int32_t HITLS_SetAlpnProtos(HITLS_Ctx *ctx, const uint8_t *protos, uint32_t protosLen);
95 
96 /**
97  * @ingroup hitls_alpn
98  * @brief   Obtaining the ALPN Negotiation Result
99  *
100  * @param   ctx  [IN] Ctx context.
101  * @param   proto    [OUT] Header address of the outgoing selected protocol.
102  * @param   protoLen    [OUT] Length of the outgoing selected protocol.
103  * @retval  If success, return HITLS_SUCCESS.
104  *          For details about other error codes, see hitls_error.h.
105  */
106 int32_t HITLS_GetSelectedAlpnProto(HITLS_Ctx *ctx, uint8_t **proto, uint32_t *protoLen);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif // HITLS_ALPN_H