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 "nx_secure_tls.h"
26 
27 /* Bring in externs for caller checking code.  */
28 
29 NX_SECURE_CALLER_CHECKING_EXTERNS
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nxe_secure_tls_session_certificate_callback_set    PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Timothy Stapko, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function checks for errors when setting the TLS certificate    */
44 /*    verification callback function.                                     */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    tls_session                           TLS control block             */
49 /*    func_ptr                              Pointer to callback function  */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _nx_secure_tls_session_certificate_callback_set                     */
58 /*                                          Actual callback function set  */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    Application Code                                                    */
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 /**************************************************************************/
_nxe_secure_tls_session_certificate_callback_set(NX_SECURE_TLS_SESSION * tls_session,ULONG (* func_ptr)(NX_SECURE_TLS_SESSION * session,NX_SECURE_X509_CERT * certificate))73 UINT _nxe_secure_tls_session_certificate_callback_set(NX_SECURE_TLS_SESSION *tls_session,
74                                                       ULONG (*func_ptr)(NX_SECURE_TLS_SESSION *session,
75                                                                         NX_SECURE_X509_CERT *certificate))
76 {
77 UINT status;
78 
79 
80     if (tls_session == NX_NULL || func_ptr == NX_NULL)
81     {
82         return(NX_PTR_ERROR);
83     }
84 
85     /* Make sure the session is initialized. */
86     if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID)
87     {
88         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
89     }
90 
91     /* Check for appropriate caller.  */
92     NX_THREADS_ONLY_CALLER_CHECKING
93 
94     /* Call the actual function. */
95     status = _nx_secure_tls_session_certificate_callback_set(tls_session, func_ptr);
96 
97     return(status);
98 }
99 
100