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 
25 /* Include necessary system files.  */
26 
27 #include "nx_secure_tls.h"
28 
29 /* Bring in externs for caller checking code.  */
30 
31 NX_SECURE_CALLER_CHECKING_EXTERNS
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _nxe_secure_tls_session_send                        PORTABLE C      */
38 /*                                                           6.3.0        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Timothy Stapko, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the TLS session send call.       */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    tls_session                           TLS control block             */
50 /*    packet_ptr                            Pointer to packet data        */
51 /*    wait_option                           Indicates behavior if TCP     */
52 /*                                          socket cannot send packet     */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _nx_secure_tls_session_send           Actual TLS session send call. */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
71 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*  10-31-2023     Yanwu Cai                Modified comment(s), added    */
74 /*                                            record length checking,     */
75 /*                                            resulting in version 6.3.0  */
76 /*                                                                        */
77 /**************************************************************************/
_nxe_secure_tls_session_send(NX_SECURE_TLS_SESSION * tls_session,NX_PACKET * packet_ptr,ULONG wait_option)78 UINT  _nxe_secure_tls_session_send(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *packet_ptr,
79                                    ULONG wait_option)
80 {
81 UINT status;
82 
83     if (tls_session == NX_NULL)
84     {
85         return(NX_PTR_ERROR);
86     }
87 
88     if (packet_ptr == NX_NULL)
89     {
90         return(NX_PTR_ERROR);
91     }
92 
93     if (tls_session -> nx_secure_tls_tcp_socket == NX_NULL)
94     {
95         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
96     }
97 
98     /* Make sure the session is initialized. */
99     if (tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID)
100     {
101         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
102     }
103 
104     /* Check the plaintext length as the fragmentation is not supported currently. */
105     if (packet_ptr -> nx_packet_length > NX_SECURE_TLS_MAX_PLAINTEXT_LENGTH)
106     {
107         return(NX_SECURE_TLS_RECORD_OVERFLOW);
108     }
109 
110     /* Check for appropriate caller.  */
111     NX_THREADS_ONLY_CALLER_CHECKING
112 
113     status =  _nx_secure_tls_session_send(tls_session, packet_ptr, wait_option);
114 
115     /* Return completion status.  */
116     return(status);
117 }
118 
119