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_remote_certificate_buffer_allocate PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Timothy Stapko, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function checks for errors in allocating buffer space for */
46 /* incoming certificates from the remote host. */
47 /* */
48 /* INPUT */
49 /* */
50 /* tls_session Pointer to TLS Session */
51 /* certs_number Number of client certs */
52 /* certificate_buffer Buffer allocated for certs */
53 /* buffer_size Buffer size in bytes */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* status Completion status */
58 /* */
59 /* CALLS */
60 /* */
61 /* None */
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_remote_certificate_buffer_allocate(NX_SECURE_TLS_SESSION * tls_session,UINT certs_number,VOID * certificate_buffer,ULONG buffer_size)76 UINT _nxe_secure_tls_remote_certificate_buffer_allocate(NX_SECURE_TLS_SESSION *tls_session, UINT certs_number, VOID *certificate_buffer, ULONG buffer_size)
77 {
78 UINT status;
79
80 /* Check for NULL pointers. */
81 if(tls_session == NX_NULL || certificate_buffer == NX_NULL)
82 {
83 return(NX_PTR_ERROR);
84 }
85
86 if(certs_number == 0 || buffer_size == 0)
87 {
88 return(NX_INVALID_PARAMETERS);
89 }
90
91 /* Make sure the session is initialized. */
92 if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID)
93 {
94 return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
95 }
96
97 /* Check for appropriate caller. */
98 NX_THREADS_ONLY_CALLER_CHECKING
99
100 /* Call actual function. */
101 status = _nx_secure_tls_remote_certificate_buffer_allocate(tls_session, certs_number, certificate_buffer, buffer_size);
102
103 /* Return completion status. */
104 return(status);
105 }
106
107