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_delete                      PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Timothy Stapko, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the TLS session delete call.     */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    tls_session                           Pointer to TLS Session        */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _nx_secure_tls_session_delete         Actual TLS session delete call*/
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 /**************************************************************************/
_nxe_secure_tls_session_delete(NX_SECURE_TLS_SESSION * tls_session)72 UINT  _nxe_secure_tls_session_delete(NX_SECURE_TLS_SESSION *tls_session)
73 {
74 UINT status;
75 NX_SECURE_TLS_SESSION *session_ptr;
76 
77     if (tls_session == NX_NULL)
78     {
79         return(NX_PTR_ERROR);
80     }
81 
82     session_ptr = _nx_secure_tls_created_ptr;
83     for (;;)
84     {
85         if (session_ptr == NX_NULL)
86         {
87 
88             /* No session created. */
89             return(NX_PTR_ERROR);
90         }
91 
92         if (session_ptr == tls_session)
93         {
94 
95             /* Found the session to delete. */
96             break;
97         }
98 
99         session_ptr = session_ptr -> nx_secure_tls_created_next;
100 
101         if (session_ptr == _nx_secure_tls_created_ptr)
102         {
103 
104             /* This session is not created. */
105             return(NX_PTR_ERROR);
106         }
107     }
108 
109     /* Check for appropriate caller.  */
110     NX_THREADS_ONLY_CALLER_CHECKING
111 
112     status =  _nx_secure_tls_session_delete(tls_session);
113 
114     /* Return completion status.  */
115     return(status);
116 }
117 
118