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_FEATURE_RENEGOTIATION
17 #include "tls_binlog_id.h"
18 #include "bsl_log_internal.h"
19 #include "bsl_log.h"
20 #include "bsl_err_internal.h"
21 #include "hitls_error.h"
22 #include "tls.h"
23 #include "hs_ctx.h"
24 #include "hs_verify.h"
25 #include "hs_common.h"
26 #include "pack.h"
27 #include "send_process.h"
28
29
ServerSendHelloRequestProcess(TLS_Ctx * ctx)30 int32_t ServerSendHelloRequestProcess(TLS_Ctx *ctx)
31 {
32 int32_t ret;
33 /* get the server infomation */
34 HS_Ctx *hsCtx = (HS_Ctx *)ctx->hsCtx;
35
36 /* determine whether to assemble a message */
37 if (hsCtx->msgLen == 0) {
38 /* assemble message */
39 ret = HS_PackMsg(ctx, HELLO_REQUEST, hsCtx->msgBuf, hsCtx->bufferLen, &hsCtx->msgLen);
40 if (ret != HITLS_SUCCESS) {
41 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID15906, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN,
42 "server pack hello request msg fail.", 0, 0, 0, 0);
43 return ret;
44 }
45 }
46
47 /* writing handshake message */
48 ret = HS_SendMsg(ctx);
49 if (ret != HITLS_SUCCESS) {
50 return ret;
51 }
52
53 /* hash calculation is not required for HelloRequest messages */
54 ret = VERIFY_Init(hsCtx);
55 if (ret != HITLS_SUCCESS) {
56 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID17150, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN,
57 "VERIFY_Init fail", 0, 0, 0, 0);
58 return ret;
59 }
60
61 /* The server does not enter the renegotiation state when sending a HelloRequest message.
62 The server enters the renegotiation state only when receiving a ClientHello message. */
63 ctx->negotiatedInfo.isRenegotiation = false;
64
65 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID15907, BSL_LOG_LEVEL_INFO, BSL_LOG_BINLOG_TYPE_RUN,
66 "server send hello request msg success.", 0, 0, 0, 0);
67
68 return HS_ChangeState(ctx, TLS_CONNECTED);
69 }
70 #endif /* HITLS_TLS_FEATURE_RENEGOTIATION */