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_create 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 create call. */
46 /* */
47 /* INPUT */
48 /* */
49 /* session_ptr TLS session control block */
50 /* crypto_table crypto method table */
51 /* metadata_buffer Encryption metadata area */
52 /* metadata_size Encryption metadata size */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* status Completion status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _nx_secure_tls_session_create Actual TLS session create */
61 /* call */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application Code */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
72 /* 09-30-2020 Timothy Stapko Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* */
75 /**************************************************************************/
_nxe_secure_tls_session_create(NX_SECURE_TLS_SESSION * session_ptr,const NX_SECURE_TLS_CRYPTO * cipher_table,VOID * metadata_area,ULONG metadata_size)76 UINT _nxe_secure_tls_session_create(NX_SECURE_TLS_SESSION *session_ptr,
77 const NX_SECURE_TLS_CRYPTO *cipher_table,
78 VOID *metadata_area,
79 ULONG metadata_size)
80 {
81 UINT status;
82 NX_SECURE_TLS_SESSION *created_tls_session;
83 ULONG created_count;
84
85 if ((session_ptr == NX_NULL) || (cipher_table == NX_NULL) || (metadata_area == NX_NULL))
86 {
87 return(NX_PTR_ERROR);
88 }
89
90 /* Loop to check for the IP instance already created. */
91 created_tls_session = _nx_secure_tls_created_ptr;
92 created_count = _nx_secure_tls_created_count;
93 while (created_count--)
94 {
95
96 /* Is the new ip already created? */
97 if (session_ptr == created_tls_session)
98 {
99
100 /* Duplicate tls session created, return an error! */
101 return(NX_PTR_ERROR);
102 }
103
104 /* Move to next entry. */
105 created_tls_session = created_tls_session -> nx_secure_tls_created_next;
106 }
107
108 /* Check for appropriate caller. */
109 NX_THREADS_ONLY_CALLER_CHECKING
110
111 status = _nx_secure_tls_session_create(session_ptr, cipher_table, metadata_area, metadata_size);
112
113 /* Return completion status. */
114 return(status);
115 }
116
117