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_server_certificate_find              PORTABLE C      */
34 /*                                                           6.2.1        */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Timothy Stapko, Microsoft Corporation                               */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    This function finds a local server certificate based upon its       */
42 /*    unique identifier assigned when the certificate was added with      */
43 /*    nx_secure_tls_server_certificate_add.                               */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    tls_session                           Pointer to TLS Session        */
48 /*    certificate                           Return certificate pointer    */
49 /*    cert_id                               Certificate identifier        */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _nx_secure_x509_local_certificate_find                              */
58 /*                                          Find certificate in local     */
59 /*                                            store                       */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
70 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  04-02-2021     Timothy Stapko           Modified comment(s),          */
73 /*                                            updated X.509 return value, */
74 /*                                            resulting in version 6.1.6  */
75 /*  03-08-2023     Yanwu Cai                Modified comment(s),          */
76 /*                                            fixed compiler errors when  */
77 /*                                            x509 is disabled,           */
78 /*                                            resulting in version 6.2.1  */
79 /*                                                                        */
80 /**************************************************************************/
_nx_secure_tls_server_certificate_find(NX_SECURE_TLS_SESSION * tls_session,NX_SECURE_X509_CERT ** certificate,UINT cert_id)81 UINT  _nx_secure_tls_server_certificate_find(NX_SECURE_TLS_SESSION *tls_session,
82                                              NX_SECURE_X509_CERT **certificate, UINT cert_id)
83 {
84 #ifndef NX_SECURE_DISABLE_X509
85 UINT status;
86 
87     /* Find and return the certificate based on its ID. */
88     status =  _nx_secure_x509_local_certificate_find(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store, certificate, cert_id);
89 
90     /* Translate some X.509 return values into TLS return values. */
91     if (status == NX_SECURE_X509_CERTIFICATE_NOT_FOUND)
92     {
93         return(NX_SECURE_TLS_CERTIFICATE_NOT_FOUND);
94     }
95 
96     /* Return completion status.  */
97     return(status);
98 #else
99     NX_PARAMETER_NOT_USED(tls_session);
100     NX_PARAMETER_NOT_USED(certificate);
101     NX_PARAMETER_NOT_USED(cert_id);
102 
103     return(NX_NOT_SUPPORTED);
104 #endif
105 }
106 
107