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 /**************************************************************************/
27 /*                                                                        */
28 /*  FUNCTION                                               RELEASE        */
29 /*                                                                        */
30 /*    _nx_secure_tls_protocol_version_get                 PORTABLE C      */
31 /*                                                           6.1          */
32 /*  AUTHOR                                                                */
33 /*                                                                        */
34 /*    Timothy Stapko, Microsoft Corporation                               */
35 /*                                                                        */
36 /*  DESCRIPTION                                                           */
37 /*                                                                        */
38 /*    Return the protocol version to use for the TLS connection. This may */
39 /*    be a user-supplied version using the API                            */
40 /*    nx_secure_tls_session_protocol_version_override. If no version      */
41 /*    override is supplied, the newest supported and enabled version is   */
42 /*    returned.                                                           */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    session_ptr                           TLS session                   */
47 /*    protocol_version                      Pointer to version variable   */
48 /*    id                                    TLS or DTLS                   */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    None                                                                */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    _nx_secure_dtls_send_clienthello      Send ClientHello              */
61 /*    _nx_secure_tls_process_clienthello    Process ClientHello           */
62 /*    _nx_secure_tls_send_clienthello       Send ClientHello              */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
69 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_nx_secure_tls_protocol_version_get(NX_SECURE_TLS_SESSION * session_ptr,USHORT * protocol_version,UINT id)73 VOID _nx_secure_tls_protocol_version_get(NX_SECURE_TLS_SESSION *session_ptr,
74                                          USHORT *protocol_version, UINT id)
75 {
76 
77     /* First, check for protocol version override and return it if the user has selected to
78        use a specific version of TLS (even if a newer version is enabled). */
79     if (session_ptr -> nx_secure_tls_protocol_version_override != 0)
80     {
81         (*protocol_version) = session_ptr -> nx_secure_tls_protocol_version_override;
82         return;
83     }
84 
85     /* No user protocol version override, return newest supported version. */
86     _nx_secure_tls_newest_supported_version(session_ptr, protocol_version, id);
87 
88     return;
89 }
90 
91