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 /**************************************************************************/
30 /*                                                                        */
31 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*    _nx_secure_tls_active_certificate_set               PORTABLE C      */
34 /*                                                           6.2.1        */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Timothy Stapko, Microsoft Corporation                               */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    This function sets the active local certificate, overriding any     */
42 /*    previously added local certificates. Normally, a single certificate */
43 /*    is used for a TLS instance, but in some cases the server or client  */
44 /*    may need to choose a specific certificate during the handshake. By  */
45 /*    calling this function in the TLS server or client callback, an      */
46 /*    application can choose the active local certificate at runtime      */
47 /*    after a ClientHello or ServerHello is received.                     */
48 /*                                                                        */
49 /*    NOTE: The certificate MUST be in the local store before calling     */
50 /*    this function (using nx_secure_tls_local_certificate_add) or the    */
51 /*    proper certificate chain may not be sent to the remote host!        */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    tls_session                           Pointer to TLS Session        */
56 /*    certificate                           Pointer to certificate        */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    None                                                                */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Application Code                                                    */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
75 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*  03-08-2023     Yanwu Cai                Modified comment(s),          */
78 /*                                            fixed compiler errors when  */
79 /*                                            x509 is disabled,           */
80 /*                                            resulting in version 6.2.1  */
81 /*                                                                        */
82 /**************************************************************************/
_nx_secure_tls_active_certificate_set(NX_SECURE_TLS_SESSION * tls_session,NX_SECURE_X509_CERT * certificate)83 UINT _nx_secure_tls_active_certificate_set(NX_SECURE_TLS_SESSION *tls_session,
84                                            NX_SECURE_X509_CERT *certificate)
85 {
86 #ifdef NX_SECURE_DISABLE_X509
87     NX_PARAMETER_NOT_USED(tls_session);
88     NX_PARAMETER_NOT_USED(certificate);
89 
90     return(NX_NOT_SUPPORTED);
91 #else
92     /* Set the active certificate (should be in the store). */
93     tls_session -> nx_secure_tls_credentials.nx_secure_tls_active_certificate = certificate;
94 
95     /* Return completion status.  */
96     return(NX_SUCCESS);
97 #endif
98 }
99 
100