• 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_error.h"
16 #include "tls.h"
17 
CovertRecordAlertToReturnValue(ALERT_Description description)18 int32_t CovertRecordAlertToReturnValue(ALERT_Description description)
19 {
20     switch (description) {
21         case ALERT_PROTOCOL_VERSION:
22             return HITLS_REC_INVALID_PROTOCOL_VERSION;
23         case ALERT_BAD_RECORD_MAC:
24             return HITLS_REC_BAD_RECORD_MAC;
25         case ALERT_DECODE_ERROR:
26             return HITLS_REC_DECODE_ERROR;
27         case ALERT_RECORD_OVERFLOW:
28             return HITLS_REC_RECORD_OVERFLOW;
29         case ALERT_UNEXPECTED_MESSAGE:
30             return HITLS_REC_ERR_RECV_UNEXPECTED_MSG;
31         default:
32             return HITLS_REC_INVLAID_RECORD;
33     }
34 }
35 
RecordSendAlertMsg(TLS_Ctx * ctx,ALERT_Level level,ALERT_Description description)36 int32_t RecordSendAlertMsg(TLS_Ctx *ctx, ALERT_Level level, ALERT_Description description)
37 {
38     /* RFC6347 4.1.2.7.  Handling Invalid Records:
39        We choose to discard invalid dtls record message and do not generate alerts. */
40     if (IS_SUPPORT_DATAGRAM(ctx->config.tlsConfig.originVersionMask)) {
41         return HITLS_REC_NORMAL_RECV_BUF_EMPTY;
42     } else {
43         ctx->method.sendAlert(ctx, level, description);
44         return CovertRecordAlertToReturnValue(description);
45     }
46 }
47