• 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 #include "hitls_build.h"
16 #ifdef HITLS_TLS_HOST_CLIENT
17 #ifdef HITLS_TLS_PROTO_DTLS12
18 #include "securec.h"
19 #include "bsl_log_internal.h"
20 #include "bsl_log.h"
21 #include "tls_binlog_id.h"
22 #include "bsl_err_internal.h"
23 #include "bsl_sal.h"
24 #include "rec.h"
25 #include "hitls_error.h"
26 #include "tls.h"
27 #include "hs_ctx.h"
28 #include "hs_common.h"
29 
DtlsClientRecvHelloVerifyRequestProcess(TLS_Ctx * ctx,HS_Msg * msg)30 int32_t DtlsClientRecvHelloVerifyRequestProcess(TLS_Ctx *ctx, HS_Msg *msg)
31 {
32     TLS_NegotiatedInfo *negotiatedInfo = &ctx->negotiatedInfo;
33     HelloVerifyRequestMsg *helloVerifyReq = &msg->body.helloVerifyReq;
34 
35     /* release the old cookie first */
36     BSL_SAL_FREE(negotiatedInfo->cookie);
37 
38     /* allow zero-length cookies to be received */
39     if (helloVerifyReq->cookieLen != 0) {
40         negotiatedInfo->cookie = (uint8_t *)BSL_SAL_Dump(helloVerifyReq->cookie, helloVerifyReq->cookieLen);
41         if (negotiatedInfo->cookie == NULL) {
42             BSL_ERR_PUSH_ERROR(HITLS_MEMALLOC_FAIL);
43             BSL_LOG_BINLOG_FIXLEN(BINLOG_ID16080, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN,
44                 "cookie malloc fail when process hello verify request.", 0, 0, 0, 0);
45             return HITLS_MEMALLOC_FAIL;
46         }
47     }
48     negotiatedInfo->cookieSize = helloVerifyReq->cookieLen;
49 #ifdef HITLS_BSL_UIO_UDP
50     /* clear the retransmission queue */
51     REC_RetransmitListClean(ctx->recCtx);
52 #endif /* HITLS_BSL_UIO_UDP */
53     return HS_ChangeState(ctx, TRY_SEND_CLIENT_HELLO);
54 }
55 #endif /* HITLS_TLS_PROTO_DTLS12 */
56 #endif /* HITLS_TLS_HOST_CLIENT */