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 /**************************************************************************/
27 /* */
28 /* FUNCTION RELEASE */
29 /* */
30 /* _nx_secure_tls_session_send PORTABLE C */
31 /* 6.1 */
32 /* AUTHOR */
33 /* */
34 /* Timothy Stapko, Microsoft Corporation */
35 /* */
36 /* DESCRIPTION */
37 /* */
38 /* This function sends data using an active TLS session, handling */
39 /* all encryption and hashing before sending data over the established */
40 /* TCP socket connection. . */
41 /* */
42 /* INPUT */
43 /* */
44 /* tls_session TLS control block */
45 /* packet_ptr Pointer to packet data */
46 /* wait_option Indicates behavior if TCP */
47 /* socket cannot send packet */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* status Completion status */
52 /* */
53 /* CALLS */
54 /* */
55 /* _nx_secure_tls_send_record Send TLS encrypted record */
56 /* tx_mutex_get Get protection mutex */
57 /* tx_mutex_put Put protection mutex */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* Application Code */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
68 /* 09-30-2020 Timothy Stapko Modified comment(s), */
69 /* resulting in version 6.1 */
70 /* */
71 /**************************************************************************/
_nx_secure_tls_session_send(NX_SECURE_TLS_SESSION * tls_session,NX_PACKET * packet_ptr,ULONG wait_option)72 UINT _nx_secure_tls_session_send(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *packet_ptr,
73 ULONG wait_option)
74 {
75 UINT status;
76
77
78 /* Get the protection. */
79 tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER);
80
81 status = _nx_secure_tls_send_record(tls_session, packet_ptr, NX_SECURE_TLS_APPLICATION_DATA, wait_option);
82
83 if(status != NX_SUCCESS)
84 {
85 /* Make sure we clear keys on errors. */
86 _nx_secure_tls_session_reset(tls_session);
87 }
88
89 /* Release the protection. */
90 tx_mutex_put(&_nx_secure_tls_protection);
91
92 return(status);
93 }
94
95