1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** NetX Secure Component */
17 /** */
18 /** Transport Layer Security (TLS) */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define NX_SECURE_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "nx_secure_tls.h"
29
30 /**************************************************************************/
31 /* */
32 /* FUNCTION RELEASE */
33 /* */
34 /* _nx_secure_tls_server_certificate_find PORTABLE C */
35 /* 6.2.1 */
36 /* AUTHOR */
37 /* */
38 /* Timothy Stapko, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* This function finds a local server certificate based upon its */
43 /* unique identifier assigned when the certificate was added with */
44 /* nx_secure_tls_server_certificate_add. */
45 /* */
46 /* INPUT */
47 /* */
48 /* tls_session Pointer to TLS Session */
49 /* certificate Return certificate pointer */
50 /* cert_id Certificate identifier */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* status Completion status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _nx_secure_x509_local_certificate_find */
59 /* Find certificate in local */
60 /* store */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Application Code */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
71 /* 09-30-2020 Timothy Stapko Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* 04-02-2021 Timothy Stapko Modified comment(s), */
74 /* updated X.509 return value, */
75 /* resulting in version 6.1.6 */
76 /* 03-08-2023 Yanwu Cai Modified comment(s), */
77 /* fixed compiler errors when */
78 /* x509 is disabled, */
79 /* resulting in version 6.2.1 */
80 /* */
81 /**************************************************************************/
_nx_secure_tls_server_certificate_find(NX_SECURE_TLS_SESSION * tls_session,NX_SECURE_X509_CERT ** certificate,UINT cert_id)82 UINT _nx_secure_tls_server_certificate_find(NX_SECURE_TLS_SESSION *tls_session,
83 NX_SECURE_X509_CERT **certificate, UINT cert_id)
84 {
85 #ifndef NX_SECURE_DISABLE_X509
86 UINT status;
87
88 /* Find and return the certificate based on its ID. */
89 status = _nx_secure_x509_local_certificate_find(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store, certificate, cert_id);
90
91 /* Translate some X.509 return values into TLS return values. */
92 if (status == NX_SECURE_X509_CERTIFICATE_NOT_FOUND)
93 {
94 return(NX_SECURE_TLS_CERTIFICATE_NOT_FOUND);
95 }
96
97 /* Return completion status. */
98 return(status);
99 #else
100 NX_PARAMETER_NOT_USED(tls_session);
101 NX_PARAMETER_NOT_USED(certificate);
102 NX_PARAMETER_NOT_USED(cert_id);
103
104 return(NX_NOT_SUPPORTED);
105 #endif
106 }
107
108