API参考
载入中...
搜索中...
未找到
tls_config.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 TLS_CONFIG_H
17#define TLS_CONFIG_H
18
19#include <stdint.h>
20#include <stdbool.h>
21#include "hitls_build.h"
22#include "hitls_cert_type.h"
23#include "hitls_cert.h"
24#include "hitls_debug.h"
25#include "hitls_config.h"
26#include "hitls_session.h"
27#include "hitls_psk.h"
28#include "hitls_security.h"
29#include "hitls_sni.h"
30#include "hitls_cookie.h"
31#include "hitls_alpn.h"
32#include "sal_atomic.h"
33#ifdef HITLS_TLS_FEATURE_PROVIDER
34#include "crypt_eal_provider.h"
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
45typedef struct CertMgrCtxInner CERT_MgrCtx;
46
47typedef struct TlsSessionManager TLS_SessionMgr;
48
53#define HITLS_VERSION_DTLS10 0xfeffu
54
55#define HITLS_TICKET_KEY_NAME_SIZE 16u
56#define HITLS_TICKET_KEY_SIZE 32u
57#define HITLS_TICKET_IV_SIZE 16u
58
59/* the default number of tickets of TLS1.3 server is 2 */
60#define HITLS_TLS13_TICKET_NUM_DEFAULT 2u
61#define HITLS_MAX_EMPTY_RECORDS 32
62#ifdef HITLS_TLS_FEATURE_MAX_SEND_FRAGMENT
63#define HITLS_MAX_SEND_FRAGMENT_DEFAULT 16384
64#endif
65/* max cert list is 100k */
66#define HITLS_MAX_CERT_LIST_DEFAULT (1024 * 100)
67
68#define HITLS_ENDPOINT_UNDEFINED 0
69#define HITLS_ENDPOINT_CLIENT 1
70#define HITLS_ENDPOINT_SERVER 2
71
75typedef struct {
76 char *name; // group name
77 int32_t paraId; // parameter id CRYPT_PKEY_ParaId
78 int32_t algId; // algorithm id CRYPT_PKEY_AlgId
79 int32_t secBits; // security bits
80 uint16_t groupId; // iana group id, HITLS_NamedGroup
81 uint32_t pubkeyLen; // public key length(CH keyshare / SH keyshare)
82 uint32_t sharedkeyLen; // shared key length
83 uint32_t ciphertextLen; // ciphertext length(SH keyshare)
84 uint32_t versionBits; // TLS_VERSION_MASK
85 bool isKem; // true: KEM, false: KEX
87
91typedef struct {
92 char *name;
93 uint16_t signatureScheme; // HITLS_SignHashAlgo, IANA specified
94 int32_t keyType; // HITLS_CERT_KeyType
95 int32_t paraId; // CRYPT_PKEY_ParaId
96 int32_t signHashAlgId; // combined sign hash algorithm id
97 int32_t signAlgId; // CRYPT_PKEY_AlgId
98 int32_t hashAlgId; // CRYPT_MD_AlgId
99 int32_t secBits; // security bits
100 uint32_t certVersionBits; // TLS_VERSION_MASK
101 uint32_t chainVersionBits; // TLS_VERSION_MASK
103
104#ifdef HITLS_TLS_FEATURE_PROVIDER
108typedef struct {
109 HITLS_Config *config;
110 CRYPT_EAL_ProvMgrCtx *provMgrCtx;
111} TLS_CapabilityData;
112#define TLS_CAPABILITY_LIST_MALLOC_SIZE 10
113#endif
114
115typedef struct CustomExtMethods HITLS_CustomExts;
116
120typedef struct TlsConfig {
121 BSL_SAL_RefCount references; /* reference count */
122 HITLS_Lib_Ctx *libCtx; /* library context */
123 const char *attrName; /* attrName */
124#ifdef HITLS_TLS_FEATURE_PROVIDER_DYNAMIC
125 TLS_GroupInfo *groupInfo;
126 uint32_t groupInfolen;
127 uint32_t groupInfoSize;
128 TLS_SigSchemeInfo *sigSchemeInfo;
129 uint32_t sigSchemeInfolen;
130 uint32_t sigSchemeInfoSize;
131#endif
132 uint32_t endpoint; /* client or server */
133 uint32_t version; /* supported proto version */
134 uint32_t originVersionMask; /* the original supported proto version mask */
135 uint16_t minVersion; /* min supported proto version */
136 uint16_t maxVersion; /* max supported proto version */
137 uint32_t modeSupport; /* support mode */
138
139 uint16_t *tls13CipherSuites; /* tls13 cipher suite */
140 uint32_t tls13cipherSuitesSize;
141 uint16_t *cipherSuites; /* cipher suite */
142 uint32_t cipherSuitesSize;
143 uint8_t *pointFormats; /* ec point format */
144 uint32_t pointFormatsSize;
145 /* According to RFC 8446 4.2.7, before TLS 1.3 is ec curves; TLS 1.3: supported groups for the key exchange */
146 uint16_t *groups;
147 uint32_t groupsSize;
148 uint16_t *signAlgorithms; /* signature algorithm */
149 uint32_t signAlgorithmsSize;
150
151 uint8_t *alpnList; /* application layer protocols list */
152 uint32_t alpnListSize; /* bytes of alpn, excluding the tail 0 byte */
153
154 HITLS_SecurityCb securityCb; /* Security callback */
155 void *securityExData; /* Security ex data */
156 int32_t securityLevel; /* Security level */
157
158 uint8_t *serverName; /* server name */
159 uint32_t serverNameSize; /* server name size */
160
161 int32_t readAhead; /* need read more data into user buffer, nonzero indicates yes, otherwise no */
162 uint32_t emptyRecordsNum; /* the max number of empty records can be received */
163
164 /* TLS1.2 psk */
165 uint8_t *pskIdentityHint; /* psk identity hint */
166 uint32_t hintSize;
167 HITLS_PskClientCb pskClientCb; /* psk client callback */
168 HITLS_PskServerCb pskServerCb; /* psk server callback */
169
170 /* TLS1.3 psk */
171 HITLS_PskFindSessionCb pskFindSessionCb; /* TLS1.3 PSK server callback */
172 HITLS_PskUseSessionCb pskUseSessionCb; /* TLS1.3 PSK client callback */
173
174 HITLS_DtlsTimerCb dtlsTimerCb; /* DTLS get the timeout callback */
175 uint32_t dtlsPostHsTimeoutVal; /* DTLS over UDP completed handshake timeout */
176
177 HITLS_CRYPT_Key *dhTmp; /* Temporary DH key set by the user */
178 HITLS_DhTmpCb dhTmpCb; /* the callback for generating the DH key */
179
180 HITLS_InfoCb infoCb; /* information indicator callback */
181 HITLS_MsgCb msgCb; /* message callback function cb for observing all SSL/TLS protocol messages */
182 void *msgArg; /* set argument arg to the callback function */
183
184 HITLS_RecordPaddingCb recordPaddingCb; /* the callback to specify the padding for TLS 1.3 records */
185 void *recordPaddingArg; /* assign a value arg that is passed to the callback */
186
187 uint32_t keyExchMode; /* TLS1.3 psk exchange mode */
188
189 uint32_t maxCertList; /* the maximum size allowed for the peer's certificate chain */
190
191 HITLS_TrustedCAList *caList; /* the list of CAs sent to the peer */
192 CERT_MgrCtx *certMgrCtx; /* certificate management context */
193
194 uint32_t sessionIdCtxSize; /* the size of sessionId context */
195 uint8_t sessionIdCtx[HITLS_SESSION_ID_CTX_MAX_SIZE]; /* the sessionId context */
196
197 uint32_t ticketNums; /* TLS1.3 ticket number */
198 uint16_t maxSendFragment; /* max send fragment to restrict the amount of plaintext bytes in any record */
199 uint32_t recInbufferSize; /* Rec inbuffer inital size */
200 TLS_SessionMgr *sessMgr; /* session management */
201
202 void *userData; /* user data */
203 HITLS_ConfigUserDataFreeCb userDataFreeCb;
204
205 uint16_t recordSizeLimit; /* record size limit RFC 8449 */
206
207 bool needCheckKeyUsage; /* whether to check keyusage, default on */
208 bool needCheckPmsVersion; /* whether to verify the version in premastersecret */
209 bool isSupportRenegotiation; /* support renegotiation */
210 bool allowClientRenegotiate; /* allow a renegotiation initiated by the client */
211 bool allowLegacyRenegotiate; /* whether to abort handshake when server doesn't support SecRenegotiation */
212 bool isResumptionOnRenego; /* supports session resume during renegotiation */
213 bool isSupportDhAuto; /* the DH parameter to be automatically selected */
214
215 /* Certificate Verification Mode */
216 bool isSupportClientVerify; /* Enable dual-ended authentication. only for server */
217 bool isSupportNoClientCert; /* Authentication Passed When Client Sends Empty Certificate. only for server */
218 bool isSupportPostHandshakeAuth; /* TLS1.3 support post handshake auth. for server and client */
219 bool isSupportVerifyNone; /* The handshake will be continued regardless of the verification result.
220 for server and client */
221 bool isSupportClientOnceVerify; /* only request a client certificate once during the connection.
222 only for server */
223
224 bool isQuietShutdown; /* is support the quiet shutdown mode */
225 bool isEncryptThenMac; /* is EncryptThenMac on */
226 /* DTLS */
227 bool isSupportDtlsCookieExchange; /* is dtls support cookie exchange */
228 bool isFlightTransmitEnable; /* sending of handshake information in one flighttransmit */
229
230 int32_t emsMode; /* extended master secret mode */
231 bool isSupportSessionTicket; /* is support session ticket */
232 bool isSupportServerPreference; /* server cipher suites can be preferentially selected */
233
234 /*
235 * Configurations in the HITLS_Ctx are classified into private configuration and global configuration.
236 * The following parameters directly reference the global configuration in tls.
237 * Private configuration: ctx->config.tlsConfig
238 * The global configuration: ctx->globalConfig
239 * Modifying the globalConfig will affects all associated HITLS_Ctx
240 */
241 HITLS_AlpnSelectCb alpnSelectCb; /* alpn callback */
242 void *alpnUserData; /* the user data for alpn callback */
243 void *sniArg; /* the args for servername callback */
244 HITLS_SniDealCb sniDealCb; /* server name callback function */
245 HITLS_AppVerifyCookieCb appVerifyCookieCb; /* the callback to verify the cookie */
246 HITLS_AppGenCookieCb appGenCookieCb; /* the callback to generate the cookie */
247 HITLS_ClientHelloCb clientHelloCb; /* ClientHello callback */
248 void *clientHelloCbArg; /* the args for ClientHello callback */
249 HITLS_NewSessionCb newSessionCb; /* negotiates to generate a session */
250 HITLS_SessionRemoveCb sessionRemoveCb; /* session removal callback */
251 HITLS_SessionGetCb sessionGetCb; /* obtains a session based on the session ID */
252 uint8_t *sessionTicketExt;
253 uint32_t sessionTicketExtSize;
254 HITLS_SessionTicketExtProcessCb sessionTicketExtCb;
255 void *sessionTicketExtCbArg;
256 HITLS_KeyLogCb keyLogCb; /* the key log callback */
257 bool isKeepPeerCert; /* whether to save the peer certificate */
258 bool isMiddleBoxCompat; /* whether to support middlebox compatibility */
259
260 HITLS_CustomExts *customExts;
261} TLS_Config;
262
263#define LIBCTX_FROM_CONFIG(config) (((config) == NULL) ? NULL : (config)->libCtx)
264#define ATTRIBUTE_FROM_CONFIG(config) (((config) == NULL) ? NULL : (config)->attrName)
265
266#ifdef __cplusplus
267}
268#endif
269
270#endif // TLS_CONFIG_H
int32_t(* HITLS_AlpnSelectCb)(HITLS_Ctx *ctx, uint8_t **selectedProto, uint8_t *selectedProtoSize, uint8_t *clientAlpnList, uint32_t clientAlpnListSize, void *userData)
Callback prototype for selecting the ALPN protocol on the server, which is used to select the applica...
定义 hitls_alpn.h:57
struct BslList HITLS_TrustedCAList
Describes the list of trusted CAs
定义 hitls_cert_type.h:67
void(* HITLS_KeyLogCb)(HITLS_Ctx *ctx, const char *line)
Key logging callback
定义 hitls_cert.h:964
HITLS_CRYPT_Key *(* HITLS_DhTmpCb)(HITLS_Ctx *ctx, int32_t isExport, uint32_t keyLen)
Generate temporary DH key.
定义 hitls_config.h:1522
uint64_t(* HITLS_RecordPaddingCb)(HITLS_Ctx *ctx, int32_t type, uint64_t length, void *arg)
Callback function for handling TLS record padding.
定义 hitls_config.h:1545
void(* HITLS_ConfigUserDataFreeCb)(void *)
UserData free callback
定义 hitls_config.h:1331
int32_t(* HITLS_ClientHelloCb)(HITLS_Ctx *ctx, int32_t *alert, void *arg)
ClientHello callback prototype for the server to process the callback.
定义 hitls_config.h:973
uint32_t(* HITLS_DtlsTimerCb)(HITLS_Ctx *ctx, uint32_t us)
DTLS callback prototype for obtaining the timeout interval
定义 hitls_config.h:993
int32_t(* HITLS_PskUseSessionCb)(HITLS_Ctx *ctx, uint32_t hashAlgo, const uint8_t **id, uint32_t *idLen, HITLS_Session **session)
TLS1.3 client PSK negotiation callback
定义 hitls_psk.h:97
uint32_t(* HITLS_PskServerCb)(HITLS_Ctx *ctx, const uint8_t *identity, uint8_t *psk, uint32_t maxPskLen)
Obtain the PSK prototype on the server.
定义 hitls_psk.h:69
uint32_t(* HITLS_PskClientCb)(HITLS_Ctx *ctx, const uint8_t *hint, uint8_t *identity, uint32_t maxIdentityLen, uint8_t *psk, uint32_t maxPskLen)
Obtain the PSK prototype on the client.
定义 hitls_psk.h:56
int32_t(* HITLS_PskFindSessionCb)(HITLS_Ctx *ctx, const uint8_t *identity, uint32_t identityLen, HITLS_Session **session)
TLS1.3 server PSK negotiation callback
定义 hitls_psk.h:82
int32_t(* HITLS_SecurityCb)(const HITLS_Ctx *ctx, const HITLS_Config *config, int32_t option, int32_t bits, int32_t id, void *other, void *exData)
Secure Callback Function Prototype
定义 hitls_security.h:139
int32_t(* HITLS_SessionTicketExtProcessCb)(HITLS_Ctx *ctx, const uint8_t *data, int32_t len, void *arg)
Session ticket extension callback.
定义 hitls_session.h:157
void(* HITLS_SessionRemoveCb)(HITLS_Config *config, HITLS_Session *sess)
Remove a session.
定义 hitls_session.h:132
HITLS_Session *(* HITLS_SessionGetCb)(HITLS_Ctx *ctx, const uint8_t *data, int32_t len, int32_t *copy)
Get a session based on the session ID.
定义 hitls_session.h:145
int32_t(* HITLS_NewSessionCb)(HITLS_Ctx *ctx, HITLS_Session *session)
This callback is called when a new session is negotiated. Users can use sessions.
定义 hitls_session.h:123
#define HITLS_SESSION_ID_CTX_MAX_SIZE
Session id Maximum size of the CTX.
定义 hitls_session.h:40
int32_t(* HITLS_SniDealCb)(HITLS_Ctx *ctx, int *alert, void *arg)
Set the extension prototype for the server to process Client Hello server_name.
定义 hitls_sni.h:102
struct TlsConfig HITLS_Config
config context
定义 hitls_type.h:41
定义 sal_atomic.h:88
定义 cert_mgr.h:43
定义 custom_extensions.h:35
Group information
定义 tls_config.h:75
Signature scheme information
定义 tls_config.h:91
TLS Global Configuration
定义 tls_config.h:120
定义 session_type.h:31