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 #include "hitls_build.h"
16 #include "securec.h"
17 #include "tls_binlog_id.h"
18 #include "bsl_log_internal.h"
19 #include "bsl_log.h"
20 #include "bsl_sal.h"
21 #include "bsl_err_internal.h"
22 #include "hitls_error.h"
23 #include "hs_msg.h"
24 #include "parse_msg.h"
25 #include "parse_common.h"
26
ParseFinished(TLS_Ctx * ctx,const uint8_t * buf,uint32_t bufLen,HS_Msg * hsMsg)27 int32_t ParseFinished(TLS_Ctx *ctx, const uint8_t *buf, uint32_t bufLen, HS_Msg *hsMsg)
28 {
29 /* if the cache length is 0, return an error code */
30 if (bufLen == 0u) {
31 return ParseErrorProcess(ctx, HITLS_PARSE_INVALID_MSG_LEN, BINLOG_ID15830,
32 BINGLOG_STR("parse 0 length finish"), ALERT_DECODE_ERROR);
33 }
34
35 FinishedMsg *msg = &hsMsg->body.finished;
36
37 /* get the data of verify */
38 BSL_SAL_FREE(msg->verifyData);
39 msg->verifyData = BSL_SAL_Malloc(bufLen);
40 if (msg->verifyData == NULL) {
41 return ParseErrorProcess(ctx, HITLS_MEMALLOC_FAIL, BINLOG_ID15831,
42 BINGLOG_STR("verifyData malloc fail"), ALERT_UNKNOWN);
43 }
44 (void)memcpy_s(msg->verifyData, bufLen, buf, bufLen);
45 msg->verifyDataSize = bufLen;
46
47 return HITLS_SUCCESS;
48 }
49
CleanFinished(FinishedMsg * msg)50 void CleanFinished(FinishedMsg *msg)
51 {
52 if (msg != NULL) {
53 BSL_SAL_FREE(msg->verifyData);
54 }
55 return;
56 }
57