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_remove            PORTABLE C      */
35 /*                                                           6.2.1        */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Timothy Stapko, Microsoft Corporation                               */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function removes a server certificate from a TLS session X.509 */
43 /*    certificate store based on the unique ID assigned when the          */
44 /*    certificate was added to the store with                             */
45 /*    nx_secure_tls_server_certificate_add.                               */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    tls_session                           Pointer to TLS Session        */
50 /*    cert_id                               Certificate identifier        */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                                Completion status             */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _nx_secure_x509_store_certificate_remove                            */
59 /*                                          Remove server certificate     */
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_remove(NX_SECURE_TLS_SESSION * tls_session,UINT cert_id)81 UINT  _nx_secure_tls_server_certificate_remove(NX_SECURE_TLS_SESSION *tls_session, UINT cert_id)
82 {
83 #ifndef NX_SECURE_DISABLE_X509
84 UINT status;
85 
86     /* Remove the certificate from the local store. */
87     status = _nx_secure_x509_store_certificate_remove(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store,
88                                                       NX_NULL, NX_SECURE_X509_CERT_LOCATION_LOCAL, 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(cert_id);
101 
102     return(NX_NOT_SUPPORTED);
103 #endif
104 }
105 
106