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 #include "nx_secure_tls.h"
26 
27 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
28 /**************************************************************************/
29 /*                                                                        */
30 /*  FUNCTION                                               RELEASE        */
31 /*                                                                        */
32 /*    _nx_secure_tls_send_encrypted_extensions            PORTABLE C      */
33 /*                                                           6.1          */
34 /*  AUTHOR                                                                */
35 /*                                                                        */
36 /*    Timothy Stapko, Microsoft Corporation                               */
37 /*                                                                        */
38 /*  DESCRIPTION                                                           */
39 /*                                                                        */
40 /*    This function sends the encrypted extensions delivered after a      */
41 /*    ServerHello message in a TLS 1.3 encrypted handshake.               */
42 /*                                                                        */
43 /*  INPUT                                                                 */
44 /*                                                                        */
45 /*    tls_session                           TLS control block             */
46 /*    packet_buffer                         Pointer to message data       */
47 /*    message_length                        Length of message data (bytes)*/
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    status                                Completion status             */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _nx_secure_tls_ciphersuite_lookup     Lookup current ciphersuite    */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    _nx_secure_tls_server_handshake       Process extensions            */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
66 /*  09-30-2020     Timothy Stapko           Modified comment(s), update   */
67 /*                                           ciphersuite lookup method.   */
68 /*                                           resulting in version 6.1     */
69 /*                                                                        */
70 /**************************************************************************/
_nx_secure_tls_send_encrypted_extensions(NX_SECURE_TLS_SESSION * tls_session,NX_PACKET * send_packet)71 UINT _nx_secure_tls_send_encrypted_extensions(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet)
72 {
73 UINT status;
74 
75     status = NX_SUCCESS;
76 
77     /* Populate encrypted extensions here. */
78     NX_PARAMETER_NOT_USED(tls_session);
79 
80     /* Sending 0-length encrypted extensions - still requires the length field (16 bits). */
81     if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) < 2u)
82     {
83 
84         /* Packet buffer too small. */
85         return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL);
86     }
87 
88     send_packet -> nx_packet_append_ptr[0] = 0x0;
89     send_packet -> nx_packet_append_ptr[1] = 0x0;
90     send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + 2;
91     send_packet -> nx_packet_length = 2;
92 
93 
94 
95     return(status);
96 }
97 #endif
98 
99