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 /* Bring in externs for caller checking code.  */
27 
28 NX_SECURE_CALLER_CHECKING_EXTERNS
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _nxe_secure_tls_session_sni_extension_parse         PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Timothy Stapko, Microsoft Corporation                               */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function checks for errors when parsing a TLS Server Name      */
43 /*    Indication extension.                                               */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    tls_session                           TLS control block             */
48 /*    extensions                            Pointer to received extensions*/
49 /*    num_extensions                        The number of extensions      */
50 /*                                          received                      */
51 /*    dns_name                              Return the name requested by  */
52 /*                                          the client                    */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _nx_secure_tls_session_sni_extension_parse                          */
61 /*                                          Actual parsing function       */
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_sni_extension_parse(NX_SECURE_TLS_SESSION * tls_session,NX_SECURE_TLS_HELLO_EXTENSION * extensions,UINT num_extensions,NX_SECURE_X509_DNS_NAME * dns_name)76 UINT _nxe_secure_tls_session_sni_extension_parse(NX_SECURE_TLS_SESSION *tls_session,
77                                                  NX_SECURE_TLS_HELLO_EXTENSION *extensions,
78                                                  UINT num_extensions, NX_SECURE_X509_DNS_NAME *dns_name)
79 {
80 UINT status;
81 
82 
83     if (tls_session == NX_NULL || extensions == NX_NULL)
84     {
85         return(NX_PTR_ERROR);
86     }
87 
88     /* Make sure the session is initialized. */
89     if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID)
90     {
91         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
92     }
93 
94     /* Check for appropriate caller.  */
95     NX_THREADS_ONLY_CALLER_CHECKING
96 
97     /* Parse the extension and get the list of names. */
98     status = _nx_secure_tls_session_sni_extension_parse(tls_session, extensions, num_extensions, dns_name);
99 
100     return(status);
101 }
102 
103