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_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 the TLS remote certificate */
46 /* allocate call. */
47 /* */
48 /* INPUT */
49 /* */
50 /* tls_session Pointer to TLS Session */
51 /* certificate Pointer to certificate */
52 /* raw_certificate_buffer Buffer for storing cert */
53 /* buffer_size Size of cert buffer */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* status Completion status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _nx_secure_tls_remote_certificate_allocate */
62 /* Actual remote certificate */
63 /* allocate call */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application Code */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
74 /* 09-30-2020 Timothy Stapko Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* */
77 /**************************************************************************/
_nxe_secure_tls_remote_certificate_allocate(NX_SECURE_TLS_SESSION * tls_session,NX_SECURE_X509_CERT * certificate,UCHAR * raw_certificate_buffer,UINT buffer_size)78 UINT _nxe_secure_tls_remote_certificate_allocate(NX_SECURE_TLS_SESSION *tls_session,
79 NX_SECURE_X509_CERT *certificate,
80 UCHAR *raw_certificate_buffer, UINT buffer_size)
81 {
82 UINT status;
83
84
85
86 /* Remote certificates must be assigned a buffer for parsing. */
87 if ((tls_session == NX_NULL) || (certificate == NX_NULL) || (raw_certificate_buffer == NX_NULL))
88 {
89 return(NX_PTR_ERROR);
90 }
91
92 /* Make sure the session is initialized. */
93 if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID)
94 {
95 return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
96 }
97
98 if (buffer_size == 0)
99 {
100 return(NX_SECURE_TLS_INSUFFICIENT_CERT_SPACE);
101 }
102
103 /* Check for appropriate caller. */
104 NX_THREADS_ONLY_CALLER_CHECKING
105
106 status = _nx_secure_tls_remote_certificate_allocate(tls_session, certificate, (UCHAR *)raw_certificate_buffer, buffer_size);
107
108 /* Return completion status. */
109 return(status);
110 }
111
112