1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Secure Component                                                 */
16 /**                                                                       */
17 /**    Transport Layer Security (TLS)                                     */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SECURE_SOURCE_CODE
23 
24 #include "nx_secure_tls.h"
25 
26 #if (NX_SECURE_TLS_TLS_1_3_ENABLED)
27 /**************************************************************************/
28 /*                                                                        */
29 /*  FUNCTION                                               RELEASE        */
30 /*                                                                        */
31 /*    _nx_secure_tls_send_encrypted_extensions            PORTABLE C      */
32 /*                                                           6.1          */
33 /*  AUTHOR                                                                */
34 /*                                                                        */
35 /*    Timothy Stapko, Microsoft Corporation                               */
36 /*                                                                        */
37 /*  DESCRIPTION                                                           */
38 /*                                                                        */
39 /*    This function sends the encrypted extensions delivered after a      */
40 /*    ServerHello message in a TLS 1.3 encrypted handshake.               */
41 /*                                                                        */
42 /*  INPUT                                                                 */
43 /*                                                                        */
44 /*    tls_session                           TLS control block             */
45 /*    packet_buffer                         Pointer to message data       */
46 /*    message_length                        Length of message data (bytes)*/
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    status                                Completion status             */
51 /*                                                                        */
52 /*  CALLS                                                                 */
53 /*                                                                        */
54 /*    _nx_secure_tls_ciphersuite_lookup     Lookup current ciphersuite    */
55 /*                                                                        */
56 /*  CALLED BY                                                             */
57 /*                                                                        */
58 /*    _nx_secure_tls_server_handshake       Process extensions            */
59 /*                                                                        */
60 /*  RELEASE HISTORY                                                       */
61 /*                                                                        */
62 /*    DATE              NAME                      DESCRIPTION             */
63 /*                                                                        */
64 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
65 /*  09-30-2020     Timothy Stapko           Modified comment(s), update   */
66 /*                                           ciphersuite lookup method.   */
67 /*                                           resulting in version 6.1     */
68 /*                                                                        */
69 /**************************************************************************/
_nx_secure_tls_send_encrypted_extensions(NX_SECURE_TLS_SESSION * tls_session,NX_PACKET * send_packet)70 UINT _nx_secure_tls_send_encrypted_extensions(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet)
71 {
72 UINT status;
73 
74     status = NX_SUCCESS;
75 
76     /* Populate encrypted extensions here. */
77     NX_PARAMETER_NOT_USED(tls_session);
78 
79     /* Sending 0-length encrypted extensions - still requires the length field (16 bits). */
80     if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) < 2u)
81     {
82 
83         /* Packet buffer too small. */
84         return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL);
85     }
86 
87     send_packet -> nx_packet_append_ptr[0] = 0x0;
88     send_packet -> nx_packet_append_ptr[1] = 0x0;
89     send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + 2;
90     send_packet -> nx_packet_length = 2;
91 
92 
93 
94     return(status);
95 }
96 #endif
97 
98