• 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 #ifndef FRAME_MSG_H
17 #define FRAME_MSG_H
18 
19 #include <stdint.h>
20 #include "hs_msg.h"
21 #include "rec.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Used to determine the field status during packing */
28 typedef enum {
29     /* field is missing. If this state is set, the field will not be packed into the buffer during packing */
30     MISSING_FIELD = 0,
31     /* field initial status. The field status in the parsed msg structure is filled with the value. */
32     INITIAL_FIELD,
33     /* Specifies the value of the field. If the field content is modified, set the status to the value. */
34     ASSIGNED_FIELD,
35     /* Repeat the field. During the packing, the field will be packed again */
36     DUPLICATE_FIELD,
37     /* Only one byte length is packed and used to construct abnormal messages.
38     It is used for two or more bytes of fields (such as the cipher suite length). */
39     SET_LEN_TO_ONE_BYTE,
40 } FieldState;
41 
42 // uint64_t data with status
43 typedef struct {
44     FieldState state; /* Field state */
45     uint64_t data;    /* Content */
46 } FRAME_Integer;
47 
48 // uint8_t data with status
49 typedef struct {
50     FieldState state; /* Field state */
51     uint32_t size;    /* Number of data records */
52     uint8_t *data;    /* Content */
53 } FRAME_Array8;
54 
55 // uint16_t data with status
56 typedef struct {
57     FieldState state; /* Field state */
58     uint32_t size;    /* Number of data records */
59     uint16_t *data;   /* Content */
60 } FRAME_Array16;
61 
62 typedef struct {
63     FieldState exState;        /* extension Field state */
64     FRAME_Integer exType;      /* extension type */
65     FRAME_Integer exLen;       /* Full length of extension */
66     FRAME_Integer exDataLen;   /* Length of extension content */
67     FRAME_Array8 exData;       /* extension content */
68 } FRAME_HsExtArray8;
69 
70 // The handshake extension with state carries a variable-length array with uint16_t
71 // such as the signature algorithm extension
72 typedef struct {
73     FieldState exState;         /* extension Field state */
74     FRAME_Integer exType;       /* extension type */
75     FRAME_Integer exLen;        /* Full length of extension */
76     FRAME_Integer exDataLen;    /* Length of extension content */
77     FRAME_Array16 exData;       /* extension content */
78 } FRAME_HsExtArray16;
79 
80 typedef struct {
81     FieldState state;             /* Field state */
82     FRAME_Integer group;          /* group */
83     FRAME_Integer keyExchangeLen; /* key exchange size */
84     FRAME_Array8 keyExchange;
85 } FRAME_HsKeyShareEntry;
86 
87 typedef struct {
88     FieldState state;            /* Field state */
89     uint32_t size;               /* Number of entries */
90     FRAME_HsKeyShareEntry *data; /* key shareContent */
91 } FRAME_HsArrayKeyShare;
92 
93 typedef struct {
94     FieldState exState;                /* extension Field state */
95     FRAME_Integer exType;              /* extension type */
96     FRAME_Integer exLen;               /* Full length of extension */
97     FRAME_Integer exKeyShareLen;       /* keyshare Array length */
98     FRAME_HsArrayKeyShare exKeyShares; /* keyshare array content */
99 } FRAME_HsExtKeyShare;
100 
101 typedef struct {
102     FieldState state; /* Field state */
103     FRAME_Integer identityLen;
104     FRAME_Array8 identity;
105     FRAME_Integer obfuscatedTicketAge;
106 } FRAME_HsPskIdentity;
107 
108 typedef struct {
109     FieldState state;          /* Field state */
110     uint32_t size;             /* Number of identities */
111     FRAME_HsPskIdentity *data; /* identity Content */
112 } FRAME_HsArrayPskIdentity;
113 
114 typedef struct {
115     FieldState state; /* Field state */
116     FRAME_Integer binderLen;
117     FRAME_Array8 binder;
118 } FRAME_HsPskBinder;
119 
120 typedef struct {
121     FieldState state;          /* Field state */
122     uint32_t size;             /* Number of identities */
123     FRAME_HsPskBinder *data; /* identity Content */
124 } FRAME_HsArrayPskBinder;
125 
126 typedef struct {
127     FieldState exState;   /* extension Field state */
128     FRAME_Integer exType; /* extension type */
129     FRAME_Integer exLen;  /* Full length of extension */
130     FRAME_Integer identitySize;
131     FRAME_HsArrayPskIdentity identities;
132     FRAME_Integer binderSize;
133     FRAME_HsArrayPskBinder binders;
134 } FRAME_HsExtOfferedPsks;
135 
136 typedef struct {
137     FieldState exState;   /* extension Field state */
138     FRAME_Integer exType; /* extension type */
139     FRAME_Integer exLen;  /* Full length of extension */
140     FRAME_Array8 list;  /* CA list */
141     FRAME_Integer listSize; /* CA list length */
142 } FRAME_HsExtCaList;
143 
144 typedef struct {
145     FRAME_Integer version;               /* Version number */
146     FRAME_Array8 randomValue;            /* Random number */
147     FRAME_Integer sessionIdSize;         /* session ID length */
148     FRAME_Array8 sessionId;              /* session ID */
149     FRAME_Integer cookiedLen;            /* Cookie length (for DTLS) */
150     FRAME_Array8 cookie;                 /* cookie(for DTLS) */
151     FRAME_Integer cipherSuitesSize;      /* cipher suite length */
152     FRAME_Array16 cipherSuites;          /* cipher suite */
153     FRAME_Integer compressionMethodsLen; /* compression method length */
154     FRAME_Array8 compressionMethods;     /* compression method */
155 
156     FieldState extensionState;              /* Indicates whether the extension is packed */
157     FRAME_Integer extensionLen;             /* Total length of the extension */
158     FRAME_HsExtArray8 pointFormats;
159     FRAME_HsExtArray16 supportedGroups;
160     FRAME_HsExtArray16 signatureAlgorithms;
161     FRAME_HsExtArray8 encryptThenMac;
162     FRAME_HsExtArray8 extendedMasterSecret;
163     FRAME_HsExtArray8 secRenego;            /* security renegotiation */
164     FRAME_HsExtArray8 sessionTicket;
165     FRAME_HsExtArray8 serverName;           /* sni */
166     FRAME_HsExtArray8 alpn;                 /* alpn */
167     FRAME_HsExtArray8 tls13Cookie;           /* tls1.3 cookie */
168     FRAME_HsExtKeyShare keyshares;          /* tls1.3 key share */
169     FRAME_HsExtArray8 pskModes;             /* tls1.3 psk exchange mode */
170     FRAME_HsExtArray16 supportedVersion;     /* tls1.3 support version */
171     FRAME_HsExtOfferedPsks psks;            /* tls1.3 psk */
172     FRAME_HsExtCaList caList;
173 } FRAME_ClientHelloMsg;
174 
175 typedef struct {
176     FieldState exState;         /* extension Field state */
177     FRAME_Integer exType;       /* extension type */
178     FRAME_Integer exLen;        /* Full length of extension */
179     FRAME_Integer data;         /* extension content */
180 } FRAME_HsExtUint16;
181 
182 typedef struct {
183     FieldState exState;         /* extension Field state */
184     FRAME_Integer exType;       /* extension type */
185     FRAME_Integer exLen;        /* Full length of extension */
186     FRAME_HsKeyShareEntry data; /* extension content */
187 } FRAME_HsExtServerKeyShare;
188 
189 typedef struct {
190     FRAME_Integer version;                  /* Version number */
191     FRAME_Array8 randomValue;               /* Random number */
192     FRAME_Integer sessionIdSize;            /* session ID length */
193     FRAME_Array8 sessionId;                 /* session ID */
194     FRAME_Integer cipherSuite;
195     FRAME_Integer compressionMethod;
196     FRAME_Integer extensionLen;             /* Full length of the extended field */
197     FRAME_HsExtArray8 pointFormats;
198     FRAME_HsExtArray8 extendedMasterSecret;
199     FRAME_HsExtArray8 secRenego;            /* security renegotiation */
200     FRAME_HsExtArray8 sessionTicket;        /* sessionTicket */
201     FRAME_HsExtArray8 serverName;           /* sni */
202     FRAME_HsExtArray8 alpn;                 /* alpn */
203     FRAME_HsExtUint16 supportedVersion;     /* tls1.3 supported version */
204     FRAME_HsExtServerKeyShare keyShare;     /* tls1.3 key share */
205     FRAME_HsExtUint16 pskSelectedIdentity;  /* tls1.3 psk extension */
206     FRAME_HsExtArray8 tls13Cookie;          /* tls1.3 cookie */
207     FRAME_HsExtArray8 encryptThenMac;
208 } FRAME_ServerHelloMsg;
209 
210 typedef struct {
211     FRAME_Array8 extra; /* server hello done is a null message. This field is used to construct abnormal messages */
212 } FRAME_ServerHelloDoneMsg;
213 
214 typedef struct FrameCertItem_ {
215     FieldState state;        /* Certificate Field state */
216     FRAME_Integer certLen;   /* Certificate length */
217     FRAME_Array8 cert;       /* Certificate Content */
218     FRAME_Integer extensionLen;   /* Certificate extension length. only for tls1.3 */
219     FRAME_Array8 extension;       /* Certificate extension Content. only for tls1.3 */
220     struct FrameCertItem_ *next;
221 } FrameCertItem;
222 
223 typedef struct {
224     FRAME_Integer certsLen;   /* Certificate total length */
225     FrameCertItem *certItem;  /* Certificate */
226     FRAME_Array8 certificateReqCtx;        /* For TLS 1.3 */
227     FRAME_Integer certificateReqCtxSize;   /* For TLS 1.3 */
228 } FRAME_CertificateMsg;
229 
230 typedef struct {
231     FRAME_Integer curveType;     /* Curve type */
232     FRAME_Integer namedcurve;    /* Named curve */
233     FRAME_Integer pubKeySize;    /* ecdh public key size */
234     FRAME_Array8 pubKey;         /* ecdh public key content */
235     FRAME_Integer signAlgorithm; /* Signature hash algorithm, for TLS1.2 and DTLS1.2 */
236     FRAME_Integer signSize;      /* Signature length */
237     FRAME_Array8 signData;       /* Signature Content */
238 } FRAME_ServerEcdh;
239 
240 typedef struct {
241     FRAME_Integer plen;
242     FRAME_Array8 p;
243     FRAME_Integer glen;
244     FRAME_Array8 g;
245     FRAME_Integer pubKeyLen;     /* dh public key */
246     FRAME_Array8 pubKey;         /* dH public key content */
247     FRAME_Integer signAlgorithm; /* Signature hash algorithm, for TLS1.2 and DTLS1.2 */
248     FRAME_Integer signSize;      /* Signature length */
249     FRAME_Array8 signData;       /* Signature content */
250 } FRAME_ServerDh;
251 
252 typedef struct {
253     union {
254         FRAME_ServerEcdh ecdh;
255         FRAME_ServerDh dh;
256     } keyEx;
257 } FRAME_ServerKeyExchangeMsg;
258 
259 typedef struct {
260     FRAME_Integer pubKeySize;     /* Key exchange data length */
261     FRAME_Array8 pubKey;          /* Key exchange data */
262 } FRAME_ClientKeyExchangeMsg;
263 
264 typedef struct {
265     FieldState state;                        /* Field state */
266     FRAME_Integer certTypesSize;             /* certificate type length */
267     FRAME_Array8 certTypes;                  /* Certificate type list */
268     FRAME_Integer signatureAlgorithmsSize;   /* signature algorithm length */
269     FRAME_Array16 signatureAlgorithms;       /* signature algorithm list */
270     FRAME_Integer reserved;                  /* Four-byte alignment */
271     FRAME_Integer distinguishedNamesSize;    /* DN length */
272     FRAME_Array8 distinguishedNames;         /* DN */
273     FRAME_Array8 certificateReqCtx;         /* For TLS 1.3 */
274     FRAME_Integer certificateReqCtxSize;    /* For TLS 1.3 */
275     FRAME_Integer exMsgLen;
276 } FRAME_CertificateRequestMsg;
277 
278 /* Used to transmit certificate verification packets. */
279 typedef struct {
280     FRAME_Integer signHashAlg; /* Signature hash algorithm, used for TLS1.2 and DTLS1.2 */
281     FRAME_Integer signSize;    /* Length of the signature data */
282     FRAME_Array8 sign;         /* Signature data */
283 } FRAME_CertificateVerifyMsg;
284 
285 typedef struct {
286     FRAME_Integer ticketLifetime;
287     FRAME_Integer ticketAgeAdd;
288     FRAME_Integer ticketNonceSize;
289     FRAME_Array8 ticketNonce;
290     FRAME_Integer ticketSize;
291     FRAME_Array8 ticket;
292     FRAME_Integer extensionLen;             /* Total length of the extension */
293 } FRAME_NewSessionTicketMsg;
294 
295 /* Transmit the Finish message */
296 typedef struct {
297     FRAME_Array8 verifyData;       /* verify data Content */
298 } FRAME_FinishedMsg;
299 
300 typedef struct {
301     FRAME_Integer type;             /* Handshake type */
302     FRAME_Integer length;           /* Length of the handshake message */
303     /* Sequence number of DTLS handshake messages. Increases by 1 each time a new handshake message is sent.
304      *Does not increase for retransmission */
305     FRAME_Integer sequence;
306     FRAME_Integer fragmentOffset;   /* Fragment offset of DTLS handshake message */
307     FRAME_Integer fragmentLength;   /* DTLS Handshake message Fragment Length */
308     union {
309         FRAME_ClientHelloMsg clientHello;
310         FRAME_ServerHelloMsg serverHello;
311         FRAME_CertificateMsg certificate;
312         FRAME_ServerKeyExchangeMsg serverKeyExchange;
313         FRAME_CertificateRequestMsg certificateReq;
314         FRAME_ServerHelloDoneMsg serverHelloDone;
315         FRAME_ClientKeyExchangeMsg clientKeyExchange;
316         FRAME_CertificateVerifyMsg certificateVerify;
317         FRAME_NewSessionTicketMsg newSessionTicket;
318         FRAME_FinishedMsg finished;
319     } body;
320 } FRAME_HsMsg;
321 
322 typedef struct {
323     uint8_t level;                   /* To be deleted. The member is not processed because some code uses it */
324     uint8_t description;             /* To be deleted. The member is not processed because some code uses it */
325     FRAME_Integer alertLevel;        /* Alert level: See ALERT_Level */
326     FRAME_Integer alertDescription;  /* Alert description: See ALERT_Description */
327     FRAME_Array8 extra;              /* This field is used to construct abnormal messages */
328 } FRAME_AlertMsg;
329 
330 typedef struct {
331     uint8_t type;            /* To be deleted. The member is not processed because some code uses it */
332     FRAME_Integer ccsType;   /* ccs type */
333     FRAME_Array8 extra;      /* This field is used to construct abnormal messages */
334 } FRAME_CcsMsg;
335 
336 typedef struct {
337     char *buffer;           /* To be deleted. The member is not processed because some code uses it */
338     uint32_t len;           /* To be deleted. The member is not processed because some code uses it */
339     FRAME_Array8 appData;   /* app data */
340 } FRAME_AppMsg;
341 
342 typedef struct {
343     uint8_t type;       /* To be deleted. The member is not processed because some code uses it */
344     uint8_t reverse;    /* To be deleted. The member is not processed because some code uses it */
345     uint16_t version;   /* To be deleted. The member is not processed because some code uses it */
346     uint16_t bodyLen;   /* To be deleted. The member is not processed because some code uses it */
347     BSL_UIO_TransportType transportType;
348     uint64_t epochSeq;  /* To be deleted. The member is not processed because some code uses it */
349 
350     FRAME_Integer recType;        /* record the message type */
351     FRAME_Integer recVersion;     /* record version */
352     FRAME_Integer epoch;          /* Counter value that increases each time the password status changes.
353                                     This counter is used by DTLS */
354     FRAME_Integer sequence;       /* Record message sequence number, for DTLS */
355     FRAME_Integer length;         /* Length of the record message */
356     union {
357         HS_Msg handshakeMsg; /* To be deleted. The member is not processed because some code uses it */
358         FRAME_HsMsg hsMsg;
359         FRAME_AlertMsg alertMsg;
360         FRAME_CcsMsg ccsMsg;
361         FRAME_AppMsg appMsg;
362     } body;
363 
364     uint8_t *buffer; /* To be deleted. The member is not processed because some code uses it */
365     uint32_t len;    /* To be deleted. The member is not processed because some code uses it */
366 } FRAME_Msg;
367 
368 /* Used to transfer the message type. The framework packs and parses the corresponding message based on the field value
369  * of this structure */
370 typedef struct {
371     uint16_t versionType;
372     /* To ensure that the memory can be released normally, a value is assigned to the member during parsing */
373     REC_Type recordType;
374     /* To ensure that the memory can be released normally, a value is assigned to the member during parsing */
375     HS_MsgType handshakeType;
376     HITLS_KeyExchAlgo keyExType;
377     BSL_UIO_TransportType transportType;
378 } FRAME_Type;
379 
380 /**
381  * @brief    Generate a TLS record byte stream based on the specified parameter of frameType
382  * and the field content of the msg structure and save the stream to the buffer
383 
384  * @param   frameType [IN] Specified packing parameters
385  * @param   msg [IN] Message structure
386  * @param   buf [OUT] Returned handshake message
387  * @param   bufLen [IN] Input buffer size
388  * @param   usedLen [OUT] Returned message length
389  *
390  * @retval  HITLS_SUCCESS
391  * @retval  For other error codes, see hitls_error.h
392  */
393 int32_t FRAME_PackMsg(FRAME_Type *frameType, const FRAME_Msg *msg, uint8_t *buffer, uint32_t bufLen, uint32_t *usedLen);
394 
395 /**
396  * @brief    Generate tls13 handshake message according to type
397 
398  * @param   type [IN] Specified packing parameters
399  * @param   buf [OUT] Returned handshake message
400  * @param   bufLen [IN] Input buffer size
401  * @param   usedLen [OUT] Returned message length
402  *
403  * @retval  HITLS_SUCCESS
404  * @retval  For other error codes, see hitls_error.h
405  */
406 int32_t FRAME_GetTls13DisorderHsMsg(HS_MsgType type, uint8_t *buffer, uint32_t bufLen, uint32_t *usedLen);
407 
408 /**
409  * @brief   Generate a TLS record body byte stream based on the specified parameter of frameType
410  * and the field content of the msg structure and save the byte stream to the buffer.
411  *
412  * @param   frameType [IN] Specified packing parameters
413  * @param   msg [IN] Message structure
414  * @param   buffer [OUT] Returned handshake message
415  * @param   bufLen [IN] Input buffer size
416  * @param   usedLen [OUT] Returned message length
417  *
418  * @retval  HITLS_SUCCESS
419  * @retval  For other error codes, see hitls_error.h
420  */
421 int32_t FRAME_PackRecordBody(FRAME_Type *frameType, const FRAME_Msg *msg,
422     uint8_t *buffer, uint32_t bufLen, uint32_t *usedLen);
423 
424 /**
425  * @brief   Parse the MSG structure based on the specified parameter of frameType and the TLS record byte stream.
426  *          Only the record message header is parsed
427  *
428  * @param   frameType [IN] Specified parsing parameter, mainly versionType
429  * @param   buffer [IN] TLS record byte stream
430  * @param   bufLen [IN] Input buffer size
431  * @param   msg [OUT] Parsed Message structure
432  * @param   parseLen [OUT] Length of the parsed message
433  *
434  * @retval  HITLS_SUCCESS
435  * @retval  For other error codes, see hitls_error.h
436  */
437 int32_t FRAME_ParseMsgHeader(FRAME_Type *frameType, const uint8_t *buffer, uint32_t bufLen,
438     FRAME_Msg *msg, uint32_t *parseLen);
439 
440 /**
441  * @brief   parse TLS record header
442  *
443  * @param   buffer [IN] TLS record byte stream
444  * @param   bufferLen [IN] Input buffer size
445  * @param   msg [OUT] Parsed Message structure
446  * @param   headerLen [OUT] Length of the parsed message
447  *
448  * @retval  HITLS_SUCCESS
449  * @retval  For other error codes, see hitls_error.h
450  */
451 int32_t FRAME_ParseTLSRecordHeader(const uint8_t *buffer, uint32_t bufferLen,
452     FRAME_Msg *msg, uint32_t *parseLen);
453 
454 /**
455  * @brief   Parse the body of the TLS non-handshake record
456  *
457  * @param   buffer [IN] TLS record byte stream
458  * @param   bufferLen [IN] Input buffer size
459  * @param   msg [OUT] Parsed Message structure
460  * @param   headerLen [OUT] Length of the parsed message
461  *
462  * @retval  HITLS_SUCCESS
463  * @retval  For other error codes, see hitls_error.h
464  */
465 int32_t FRAME_ParseTLSNonHsRecordBody(const uint8_t *buffer, uint32_t bufferLen,
466     FRAME_Msg *msg, uint32_t *parseLen);
467 
468 /**
469  * @brief   Parse the TLS non-handshake record
470  *
471  * @param   buffer [IN] TLS record byte stream
472  * @param   bufferLen [IN] Input buffer size
473  * @param   msg [OUT] Parsed Message structure
474  * @param   headerLen [OUT] Length of the parsed message
475  *
476  * @retval  HITLS_SUCCESS
477  * @retval  For other error codes, see hitls_error.h
478  */
479 int32_t FRAME_ParseTLSNonHsRecord(const uint8_t *buffer, uint32_t bufferLen,
480     FRAME_Msg *msg, uint32_t *parseLen);
481 
482 /**
483  * @brief   Parse the record of the handshake type
484  *
485  * @param   buffer [IN] TLS record byte stream
486  * @param   bufferLen [IN] Input buffer size
487  * @param   msg [OUT] Parsed Message structure
488  * @param   headerLen [OUT] Length of the parsed message
489  *
490  * @retval  HITLS_SUCCESS
491  * @retval  For other error codes, see hitls_error.h
492  */
493 int32_t FRAME_ParseHsRecord(FRAME_Type *frameType, const uint8_t *buffer, uint32_t bufferLen,
494     FRAME_Msg *msg, uint32_t *parseLen);
495 
496 /**
497  * @brief    Parse the MSG structure based on the specified parameter of frameType and the TLS record byte stream.
498  *           Only the record message body is parsed
499  *
500  * @attention Invoke the Frame_ParseMsgHeader interface to parse the message header
501  *
502  * @param   frameType [IN] Specified parsing parameters, mainly versionType and keyExType
503  * @param   buffer [IN] TLS record byte stream
504  * @param   bufLen [IN] Input buffer size
505  * @param   msg [OUT] Parsed Message structure
506  * @param   parseLen [OUT] Length of the parsed message
507  *
508  * @retval  HITLS_SUCCESS
509  * @retval  For other error codes, see hitls_error.h
510  */
511 int32_t FRAME_ParseMsgBody(FRAME_Type *frameType, const uint8_t *buffer, uint32_t bufLen,
512     FRAME_Msg *msg, uint32_t *parseLen);
513 
514 /**
515  * @brief   Parse the message into the msg structure based on the specified parameter of frameType and
516  * the TLS record byte stream
517  *
518  * @param   frameType [IN] Specified parsing parameters, mainly versionType and keyExType
519  * @param   buffer [IN] TLS record byte stream
520  * @param   bufLen [IN] Input buffer size
521  * @param   msg [OUT] Parsed Message structure
522  * @param   parseLen [OUT] Length of the parsed message
523  *
524  * @retval  HITLS_SUCCESS
525  * @retval  For other error codes, see hitls_error.h
526  */
527 int32_t FRAME_ParseMsg(FRAME_Type *frameType, const uint8_t *buffer, uint32_t bufLen,
528     FRAME_Msg *msg, uint32_t *parseLen);
529 
530 /**
531  * @brief   Clear the memory allocated during parsing
532  *
533  * @param   frameType [IN] Specified parsing parameters, mainly versionType and keyExType
534  * @param   msg [IN] Message structure
535  */
536 void FRAME_CleanMsg(FRAME_Type *frameType, FRAME_Msg *msg);
537 
538 /**
539  * @brief   Clear the memory allocated during parsing
540  *
541  * @param   recType [IN] Specified record type
542  * @param   msg [IN] Message structure
543  */
544 void FRAME_CleanNonHsRecord(REC_Type recType, FRAME_Msg *msg);
545 
546 /**
547  * @brief  Obtain a structure of a specified message type
548  *
549  * @attention This interface does not set the callback function. User need to set the callback interface first
550  *            This interface obtains only the HANDSHAKE,Change_CIPHER_SPEC, and ALERT messages
551  *            The existing framework does not support parsing of encrypted finished messages.
552  *            Therefore, the finished messages cannot be obtained.
553  *
554  * @param   frameType [IN] Specified message parameters
555  * @param   msg [OUT] Returned Message structure
556  *
557  * @retval  HITLS_SUCCESS
558  * @retval  For other error codes, see hitls_error.h
559  */
560 int32_t FRAME_GetDefaultMsg(FRAME_Type *frameType, FRAME_Msg *msg);
561 
562 /**
563  * @brief   Modify a message field
564  *          This method is used to modify the contents of integer fields in a message, such as the message type,
565  *          version number, and field length
566  *
567  * @param   data [IN] Data content
568  * @param   frameInteger [IN/OUT] IN original field; OUT New field
569  *
570  * @retval  HITLS_SUCCESS
571  * @retval  For other error codes, see hitls_error.h
572  */
573 int32_t FRAME_ModifyMsgInteger(const uint64_t data, FRAME_Integer *frameInteger);
574 
575 /**
576  * @brief   Modify the message field content. User can increase or decrease the length of the message field and modify
577  *          the field content.
578  *          (This implementation performs deep copy of the data content.)
579  *          This method is used to modify the content of the uint8_t array field in a message, such as the session ID,
580  *          cookie, and signature data
581  *
582  * @param   data [IN] Data content
583  * @param   dataLen [IN] Number of data records
584  * @param   frameArray [IN/OUT] IN original field; OUT New field
585  * @param   frameArrayLen [IN/OUT] IN Original field length; Length of the new field in the OUT field. This parameter
586  *          can be none
587  *
588  * @retval  HITLS_SUCCESS
589  * @retval  For other error codes, see hitls_error.h
590  */
591 int32_t FRAME_ModifyMsgArray8(const uint8_t *data, uint32_t dataLen,
592     FRAME_Array8 *frameArray, FRAME_Integer *frameArrayLen);
593 
594 /**
595  * @brief   Retain the original handshake message field content and add a string of data data to the end of the data.
596  *          (This implementation performs deep copy of the data content.)
597  *          This method is used to modify the content of the uint8_t array field in a message, such as the session ID,
598  *          cookie, and signature data.
599  *
600  * @param   data [IN] Data content
601  * @param   dataLen [IN] Number of data records
602  * @param   frameArray [IN/OUT] IN original field; OUT New field
603  * @param   frameArrayLen [IN/OUT] IN Original field length; Length of the new field in the OUT field. This parameter
604  *          can be none
605  *
606  * @retval  HITLS_SUCCESS
607  * @retval  For other error codes, see hitls_error.h
608  */
609 int32_t FRAME_AppendMsgArray8(const uint8_t *data, uint32_t dataLen,
610     FRAME_Array8 *frameArray, FRAME_Integer *frameArrayLen);
611 
612 /**
613  * @brief   Modify the message field content. User can increase or decrease the length of the message field and modify
614  *          the field content.
615  *          (This implementation performs deep copy of the data content.)
616  *          This method is used to modify the uint16_t array field in a message, for example, cipher suite and support
617  *          group extension
618  *
619  * @param   data [IN] Data content
620  * @param   dataLen [IN] Number of data records
621  * @param   frameArray [IN/OUT] IN original field; OUT New field
622  * @param   frameArrayLen [IN/OUT] IN Original field length; Length of the new field in the OUT field. This parameter
623  *          can be none
624  *
625  * @retval  HITLS_SUCCESS
626  * @retval  For other error codes, see hitls_error.h
627  */
628 int32_t FRAME_ModifyMsgArray16(const uint16_t *data, uint32_t dataLen,
629     FRAME_Array16 *frameArray, FRAME_Integer *frameArrayLen);
630 
631 /**
632  * @brief   Retain the original handshake message field content and add a string of data data to the end of the data.
633  *          (This implementation performs deep copy of the data content.)
634  *          This method is used to modify the uint16_t array field in a message, for example, the cipher suite and
635  *          support group extension
636  *
637  * @param   data [IN] Data content
638  * @param   dataLen [IN] Number of data records
639  * @param   frameArray [IN/OUT] IN original field; OUT New field
640  * @param   frameArrayLen [IN/OUT] IN Original field length; Length of the new field in the OUT field. This parameter
641  *          can be none
642  *
643  * @retval  HITLS_SUCCESS
644  * @retval  For other error codes, see hitls_error.h
645  */
646 int32_t FRAME_AppendMsgArray16(const uint16_t *data, uint32_t dataLen,
647     FRAME_Array16 *frameArray, FRAME_Integer *frameArrayLen);
648 
649 #ifdef __cplusplus
650 }
651 #endif
652 
653 #endif // FRAME_MSG_H