1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** NetX Secure Component */ 17 /** */ 18 /** Transport Layer Security (TLS) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define NX_SECURE_SOURCE_CODE 24 25 26 #include "nx_secure_tls.h" 27 28 /**************************************************************************/ 29 /* */ 30 /* FUNCTION RELEASE */ 31 /* */ 32 /* _nx_secure_tls_send_alert PORTABLE C */ 33 /* 6.1 */ 34 /* AUTHOR */ 35 /* */ 36 /* Timothy Stapko, Microsoft Corporation */ 37 /* */ 38 /* DESCRIPTION */ 39 /* */ 40 /* This function populates an NX_PACKET with a TLS Alert message, */ 41 /* which indicates an error (and possible security breach) has been */ 42 /* detected. The alert notifies the remote host of the error. */ 43 /* */ 44 /* INPUT */ 45 /* */ 46 /* tls_session TLS control block */ 47 /* send_packet Packet to be filled */ 48 /* alert_number TLS alert number */ 49 /* alert_level TLS alert severity */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* None */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* None */ 58 /* */ 59 /* CALLED BY */ 60 /* */ 61 /* _nx_secure_dtls_client_handshake DTLS client state machine */ 62 /* _nx_secure_dtls_server_handshake DTLS server state machine */ 63 /* _nx_secure_dtls_session_end End of a session */ 64 /* _nx_secure_dtls_session_receive Receive DTLS data */ 65 /* _nx_secure_tls_client_handshake TLS client state machine */ 66 /* _nx_secure_tls_server_handshake TLS server state machine */ 67 /* _nx_secure_tls_session_end End of a session */ 68 /* _nx_secure_tls_session_receive_records */ 69 /* Receive TLS records */ 70 /* */ 71 /* RELEASE HISTORY */ 72 /* */ 73 /* DATE NAME DESCRIPTION */ 74 /* */ 75 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ 76 /* 09-30-2020 Timothy Stapko Modified comment(s), */ 77 /* resulting in version 6.1 */ 78 /* */ 79 /**************************************************************************/ _nx_secure_tls_send_alert(NX_SECURE_TLS_SESSION * tls_session,NX_PACKET * send_packet,UCHAR alert_number,UCHAR alert_level)80VOID _nx_secure_tls_send_alert(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet, 81 UCHAR alert_number, UCHAR alert_level) 82 { 83 84 #ifndef NX_SECURE_TLS_CLIENT_DISABLED 85 if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_CLIENT) 86 { 87 tls_session -> nx_secure_tls_client_state = NX_SECURE_TLS_CLIENT_STATE_ALERT_SENT; 88 } 89 #endif 90 91 #ifndef NX_SECURE_TLS_SERVER_DISABLED 92 if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER) 93 { 94 tls_session -> nx_secure_tls_server_state = NX_SECURE_TLS_SERVER_STATE_ALERT_SENT; 95 } 96 #endif 97 /* Populate the buffer with the alert level and alert number to send to the remote host. */ 98 send_packet -> nx_packet_append_ptr[0] = alert_level; 99 send_packet -> nx_packet_append_ptr[1] = alert_number; 100 101 /* Make sure the caller has the right length of data to send. */ 102 send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + 2; 103 send_packet -> nx_packet_length = 2; 104 } 105 106