API参考
载入中...
搜索中...
未找到
hitls_session.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
21
22#ifndef HITLS_SESSION_H
23#define HITLS_SESSION_H
24
25#include <stdint.h>
26#include <stddef.h>
27#include <stdbool.h>
28#include "hitls_type.h"
29#include "hitls_crypt_type.h"
30#include "bsl_uio.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
40#define HITLS_SESSION_ID_CTX_MAX_SIZE 32u
41
46#define HITLS_SESSION_ID_MAX_SIZE 32u
47
57int32_t HITLS_CFG_SetSessionTicketSupport(HITLS_Config *config, bool support);
58
68int32_t HITLS_CFG_GetSessionTicketSupport(const HITLS_Config *config, bool *isSupport);
69
81int32_t HITLS_CFG_SetTicketNums(HITLS_Config *config, uint32_t ticketNums);
82
91
103int32_t HITLS_SetTicketNums(HITLS_Ctx *ctx, uint32_t ticketNums);
104
113
123typedef int32_t (*HITLS_NewSessionCb) (HITLS_Ctx *ctx, HITLS_Session *session);
124
132typedef void (*HITLS_SessionRemoveCb)(HITLS_Config *config, HITLS_Session *sess);
133
145typedef HITLS_Session *(*HITLS_SessionGetCb) (HITLS_Ctx *ctx, const uint8_t *data, int32_t len, int32_t *copy);
146
157typedef int32_t (*HITLS_SessionTicketExtProcessCb)(HITLS_Ctx *ctx, const uint8_t *data, int32_t len, void *arg);
158
168int32_t HITLS_CFG_SetNewSessionCb(HITLS_Config *config, const HITLS_NewSessionCb newSessionCb);
169
179int32_t HITLS_CFG_SetSessionGetCb(HITLS_Config *config, const HITLS_SessionGetCb sessionGetCb);
180
191
203 void *arg);
204
216int32_t HITLS_SetSessionTicketExtData(HITLS_Ctx *ctx, uint8_t *data, uint32_t dataSize);
217
218#define HITLS_TICKET_KEY_RET_NEED_ALERT (-1) // callback fails. A fatal error occurs.
219 // You need to send an alert
220#define HITLS_TICKET_KEY_RET_FAIL 0 // callback returns a failure, but the error is not a fatal error,
221 // for example, key_name matching fails.
222#define HITLS_TICKET_KEY_RET_SUCCESS 1 // If the callback is successful,
223 // the key can be used for encryption and decryption
224#define HITLS_TICKET_KEY_RET_SUCCESS_RENEW 2 // If the callback is successful, the key can be used for encryption
225 // and decryption. In the decryption scenario,
226 // the ticket needs to be renewed
259typedef int32_t (*HITLS_TicketKeyCb)(uint8_t *keyName, uint32_t keyNameSize, HITLS_CipherParameters *cipher,
260 uint8_t isEncrypt);
261
272
289int32_t HITLS_CFG_GetSessionTicketKey(const HITLS_Config *config, uint8_t *key, uint32_t keySize, uint32_t *outSize);
290
305int32_t HITLS_CFG_SetSessionTicketKey(HITLS_Config *config, const uint8_t *key, uint32_t keySize);
306
318int32_t HITLS_CFG_SetSessionIdCtx(HITLS_Config *config, const uint8_t *sessionIdCtx, uint32_t len);
319
329int32_t HITLS_CFG_SetSessionCacheMode(HITLS_Config *config, uint32_t mode);
330
340int32_t HITLS_CFG_GetSessionCacheMode(HITLS_Config *config, uint32_t *mode);
341
351int32_t HITLS_CFG_SetSessionCacheSize(HITLS_Config *config, uint32_t size);
352
362int32_t HITLS_CFG_GetSessionCacheSize(HITLS_Config *config, uint32_t *size);
363
373int32_t HITLS_CFG_SetSessionTimeout(HITLS_Config *config, uint64_t timeout);
374
384int32_t HITLS_CFG_GetSessionTimeout(const HITLS_Config *config, uint64_t *timeout);
385
394int32_t HITLS_IsSessionReused(HITLS_Ctx *ctx, bool *isReused);
395
407int32_t HITLS_SetSessionIdCtx(HITLS_Ctx *ctx, const uint8_t *sessionIdCtx, uint32_t len);
408
425int32_t HITLS_GetSessionTicketKey(const HITLS_Ctx *ctx, uint8_t *key, uint32_t keySize, uint32_t *outSize);
426
441int32_t HITLS_SetSessionTicketKey(HITLS_Ctx *ctx, const uint8_t *key, uint32_t keySize);
442
452int32_t HITLS_SetSession(HITLS_Ctx *ctx, HITLS_Session *session);
453
462HITLS_Session *HITLS_GetSession(const HITLS_Ctx *ctx);
463
472HITLS_Session *HITLS_GetDupSession(HITLS_Ctx *ctx);
473
481HITLS_Session *HITLS_SESS_New(void);
482
489HITLS_Session *HITLS_SESS_Dup(HITLS_Session *sess);
490
498void HITLS_SESS_Free(HITLS_Session *sess);
499
510int32_t HITLS_SESS_SetMasterKey(HITLS_Session *sess, const uint8_t *masterKey, uint32_t masterKeySize);
511
519uint32_t HITLS_SESS_GetMasterKeyLen(const HITLS_Session *sess);
520
531int32_t HITLS_SESS_GetMasterKey(const HITLS_Session *sess, uint8_t *masterKey, uint32_t *masterKeySize);
532
542int32_t HITLS_SESS_GetProtocolVersion(const HITLS_Session *sess, uint16_t *version);
543
553int32_t HITLS_SESS_SetProtocolVersion(HITLS_Session *sess, uint16_t version);
554
564int32_t HITLS_SESS_SetCipherSuite(HITLS_Session *sess, uint16_t cipherSuite);
565
575int32_t HITLS_SESS_GetCipherSuite(const HITLS_Session *sess, uint16_t *cipherSuite);
576
587int32_t HITLS_SESS_SetSessionIdCtx(HITLS_Session *sess, uint8_t *sessionIdCtx, uint32_t sessionIdCtxSize);
588
599int32_t HITLS_SESS_GetSessionIdCtx(const HITLS_Session *sess, uint8_t *sessionIdCtx, uint32_t *sessionIdCtxSize);
600
611int32_t HITLS_SESS_SetSessionId(HITLS_Session *sess, uint8_t *sessionId, uint32_t sessionIdSize);
612
623int32_t HITLS_SESS_GetSessionId(const HITLS_Session *sess, uint8_t *sessionId, uint32_t *sessionIdSize);
624
634int32_t HITLS_SESS_SetHaveExtMasterSecret(HITLS_Session *sess, uint8_t haveExtMasterSecret);
635
645int32_t HITLS_SESS_GetHaveExtMasterSecret(HITLS_Session *sess, bool *haveExtMasterSecret);
646
656int32_t HITLS_SESS_SetTimeout(HITLS_Session *sess, uint64_t timeout);
657
666uint64_t HITLS_SESS_GetTimeout(HITLS_Session *sess);
667
676bool HITLS_SESS_IsResumable(const HITLS_Session *sess);
677
685bool HITLS_SESS_HasTicket(const HITLS_Session *sess);
686
693
694void *HITLS_SESS_GetUserData(const HITLS_Session *sess);
695
704int32_t HITLS_SESS_SetUserData(HITLS_Session *sess, void *userData);
714int32_t HITLS_CFG_ClearTimeoutSession(HITLS_Config *config, uint64_t nowTime);
715
725int32_t HITLS_CFG_RemoveSession(HITLS_Config *config, HITLS_Session *sess);
726#ifdef __cplusplus
727}
728#endif
729
730#endif /* HITLS_SESSION_H */
uint32_t HITLS_SESS_GetMasterKeyLen(const HITLS_Session *sess)
Obtain the master key length of a session.
int32_t HITLS_CFG_SetSessionIdCtx(HITLS_Config *config, const uint8_t *sessionIdCtx, uint32_t len)
Set the user-specific session ID ctx, only on the server.
int32_t HITLS_SESS_GetProtocolVersion(const HITLS_Session *sess, uint16_t *version)
Obtain the session protocol version.
int32_t HITLS_SetTicketNums(HITLS_Ctx *ctx, uint32_t ticketNums)
Setting TLS1.3, number of new session tickets sent after complete link establishment
int32_t HITLS_CFG_SetSessionCacheMode(HITLS_Config *config, uint32_t mode)
Set the session cache mode.
uint32_t HITLS_GetTicketNums(HITLS_Ctx *ctx)
Obtain TLS1.3, Number of new session tickets sent after complete link establishment.
int32_t(* HITLS_SessionTicketExtProcessCb)(HITLS_Ctx *ctx, const uint8_t *data, int32_t len, void *arg)
Session ticket extension callback.
定义 hitls_session.h:157
int32_t HITLS_SESS_SetTimeout(HITLS_Session *sess, uint64_t timeout)
Set the timeout interval, in seconds.
int32_t HITLS_CFG_GetSessionCacheSize(HITLS_Config *config, uint32_t *size)
Obtain the maximum number of sessions in the session cache.
uint32_t HITLS_CFG_GetTicketNums(HITLS_Config *config)
Obtain TLS1.3, number of new session tickets sent after complete link establishment.
int32_t HITLS_CFG_SetTicketKeyCallback(HITLS_Config *config, HITLS_TicketKeyCb callback)
Set the ticket key callback, which is used only by the server, cb can be NULL.
HITLS_Session * HITLS_GetSession(const HITLS_Ctx *ctx)
Obtain the handle of the session information and directly obtain the pointer.
int32_t HITLS_CFG_SetSessionCacheSize(HITLS_Config *config, uint32_t size)
Set the maximum number of sessions in the session cache.
int32_t HITLS_GetSessionTicketKey(const HITLS_Ctx *ctx, uint8_t *key, uint32_t keySize, uint32_t *outSize)
Obtain the default ticket key of the HiTLS. The key is used to encrypt and decrypt the ticket in the ...
int32_t HITLS_SESS_GetSessionIdCtx(const HITLS_Session *sess, uint8_t *sessionIdCtx, uint32_t *sessionIdCtxSize)
Obtain the session ID ctx.
int32_t HITLS_SESS_GetMasterKey(const HITLS_Session *sess, uint8_t *masterKey, uint32_t *masterKeySize)
Obtain the master key of a session.
int32_t HITLS_SESS_SetMasterKey(HITLS_Session *sess, const uint8_t *masterKey, uint32_t masterKeySize)
Set the master key of a session.
int32_t HITLS_CFG_ClearTimeoutSession(HITLS_Config *config, uint64_t nowTime)
Clear the timeout session.
int32_t HITLS_CFG_SetSessionGetCb(HITLS_Config *config, const HITLS_SessionGetCb sessionGetCb)
Set a callback for obtaining a session based on the session ID.
int32_t HITLS_CFG_SetSessionTimeout(HITLS_Config *config, uint64_t timeout)
Set the session timeout interval.
int32_t(* HITLS_TicketKeyCb)(uint8_t *keyName, uint32_t keyNameSize, HITLS_CipherParameters *cipher, uint8_t isEncrypt)
Obtain and verify ticket_key on the server.
定义 hitls_session.h:259
int32_t HITLS_SetSessionTicketExtData(HITLS_Ctx *ctx, uint8_t *data, uint32_t dataSize)
Set the session ticket extension data.
int32_t HITLS_CFG_SetSessionRemoveCb(HITLS_Config *config, const HITLS_SessionRemoveCb sessionRemoveCb)
Set a callback for removing a session.
void(* HITLS_SessionRemoveCb)(HITLS_Config *config, HITLS_Session *sess)
Remove a session.
定义 hitls_session.h:132
int32_t HITLS_SESS_GetCipherSuite(const HITLS_Session *sess, uint16_t *cipherSuite)
Obtain the session password suite.
int32_t HITLS_CFG_GetSessionTicketSupport(const HITLS_Config *config, bool *isSupport)
Query whether the session ticket function is supported.
int32_t HITLS_IsSessionReused(HITLS_Ctx *ctx, bool *isReused)
Whether the link is multiplexed with a session
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_SESS_SetCipherSuite(HITLS_Session *sess, uint16_t cipherSuite)
Set the session password suite.
int32_t HITLS_SetSession(HITLS_Ctx *ctx, HITLS_Session *session)
Set the handle for the session information about the HiTLS link.
int32_t HITLS_CFG_RemoveSession(HITLS_Config *config, HITLS_Session *sess)
Remove the session.
int32_t HITLS_CFG_GetSessionTicketKey(const HITLS_Config *config, uint8_t *key, uint32_t keySize, uint32_t *outSize)
Obtain the default ticket key of the HiTLS. The key is used to encrypt and decrypt the ticket in the ...
int32_t HITLS_CFG_GetSessionCacheMode(HITLS_Config *config, uint32_t *mode)
Obtain the session cache mode.
int32_t HITLS_SESS_SetHaveExtMasterSecret(HITLS_Session *sess, uint8_t haveExtMasterSecret)
Set whether to contain the master key extension.
int32_t HITLS_SESS_SetProtocolVersion(HITLS_Session *sess, uint16_t version)
Set the session protocol version.
int32_t HITLS_SESS_GetHaveExtMasterSecret(HITLS_Session *sess, bool *haveExtMasterSecret)
Obtain the master key extension.
HITLS_Session * HITLS_SESS_Dup(HITLS_Session *sess)
Duplicate a session, the number of reference times increases by 1.
int32_t HITLS_SetSessionTicketKey(HITLS_Ctx *ctx, const uint8_t *key, uint32_t keySize)
Set the default ticket key of the HiTLS. The key is used to encrypt and decrypt the ticket in the new...
int32_t HITLS_CFG_SetSessionTicketSupport(HITLS_Config *config, bool support)
Set whether to support the session ticket function.
int32_t HITLS_SESS_SetSessionIdCtx(HITLS_Session *sess, uint8_t *sessionIdCtx, uint32_t sessionIdCtxSize)
Set the session ID ctx.
bool HITLS_SESS_IsResumable(const HITLS_Session *sess)
Check whether the session can be recovered. Only simple check is performed, but the validity period i...
int32_t HITLS_SESS_GetSessionId(const HITLS_Session *sess, uint8_t *sessionId, uint32_t *sessionIdSize)
Obtain the session ID.
int32_t HITLS_SESS_SetSessionId(HITLS_Session *sess, uint8_t *sessionId, uint32_t sessionIdSize)
Set the session ID.
int32_t HITLS_SESS_SetUserData(HITLS_Session *sess, void *userData)
Set the user data in the session object.
int32_t HITLS_SetSessionIdCtx(HITLS_Ctx *ctx, const uint8_t *sessionIdCtx, uint32_t len)
Set the user-specific session ID ctx of the HiTLS link, only on the server.
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
int32_t HITLS_CFG_SetNewSessionCb(HITLS_Config *config, const HITLS_NewSessionCb newSessionCb)
Set a callback for negotiating a new session call.
void HITLS_SESS_Free(HITLS_Session *sess)
Release the session information handle.
HITLS_Session * HITLS_SESS_New(void)
Apply for a new session.
void * HITLS_SESS_GetUserData(const HITLS_Session *sess)
Obtain the user data in the session object.
bool HITLS_SESS_HasTicket(const HITLS_Session *sess)
Check whether the session has a ticket.
int32_t HITLS_SetSessionTicketExtProcessCb(HITLS_Ctx *ctx, const HITLS_SessionTicketExtProcessCb sessionTicketExtCb, void *arg)
Set a callback for processing the session ticket extension.
int32_t HITLS_CFG_SetTicketNums(HITLS_Config *config, uint32_t ticketNums)
Setting TLS1.3, number of new session tickets sent after a complete link is established.
int32_t HITLS_CFG_SetSessionTicketKey(HITLS_Config *config, const uint8_t *key, uint32_t keySize)
Set the default ticket key of the HiTLS. The key is used to encrypt and decrypt tickets in the new se...
uint64_t HITLS_SESS_GetTimeout(HITLS_Session *sess)
Get the timeout interval, in seconds.
HITLS_Session * HITLS_GetDupSession(HITLS_Ctx *ctx)
Obtain the handle of the copied session information.
int32_t HITLS_CFG_GetSessionTimeout(const HITLS_Config *config, uint64_t *timeout)
Obtain the timeout interval of a session.
struct TlsCtx HITLS_Ctx
HITLS context
定义 hitls_type.h:35
struct TlsConfig HITLS_Config
config context
定义 hitls_type.h:41
Key parameters
定义 hitls_crypt_type.h:235