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 #define NX_SECURE_SOURCE_CODE
23
24 #include "nx_secure_tls.h"
25 #include "nx_secure_x509.h"
26
27 /**************************************************************************/
28 /* */
29 /* FUNCTION RELEASE */
30 /* */
31 /* _nx_secure_tls_local_certificate_remove PORTABLE C */
32 /* 6.2.1 */
33 /* AUTHOR */
34 /* */
35 /* Timothy Stapko, Microsoft Corporation */
36 /* */
37 /* DESCRIPTION */
38 /* */
39 /* This function removes an NX_SECURE_TLS_CERTIFICATE instance from */
40 /* the local certificates list, keyed on the Common Name field. */
41 /* */
42 /* INPUT */
43 /* */
44 /* tls_session Pointer to TLS Session */
45 /* common_name String to match "CN" field */
46 /* common_name_length Length of name */
47 /* */
48 /* OUTPUT */
49 /* */
50 /* status Completion status */
51 /* */
52 /* CALLS */
53 /* */
54 /* tx_mutex_get Get protection mutex */
55 /* tx_mutex_put Put protection mutex */
56 /* _nx_secure_x509_store_certificate_remove */
57 /* Remove certificate from the */
58 /* local store */
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 /* 04-02-2021 Timothy Stapko Modified comment(s), */
72 /* updated X.509 return value, */
73 /* resulting in version 6.1.6 */
74 /* 03-08-2023 Yanwu Cai Modified comment(s), */
75 /* fixed compiler errors when */
76 /* x509 is disabled, */
77 /* resulting in version 6.2.1 */
78 /* */
79 /**************************************************************************/
_nx_secure_tls_local_certificate_remove(NX_SECURE_TLS_SESSION * tls_session,UCHAR * common_name,UINT common_name_length)80 UINT _nx_secure_tls_local_certificate_remove(NX_SECURE_TLS_SESSION *tls_session, UCHAR *common_name,
81 UINT common_name_length)
82 {
83 #ifndef NX_SECURE_DISABLE_X509
84 UINT status;
85 NX_SECURE_X509_DISTINGUISHED_NAME name;
86
87 /* Get the protection. */
88 tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER);
89
90 NX_SECURE_MEMSET(&name, 0, sizeof(NX_SECURE_X509_DISTINGUISHED_NAME));
91
92 /* Setup our common name so we can delete from the certificate store. */
93 name.nx_secure_x509_common_name = common_name;
94 name.nx_secure_x509_common_name_length = (USHORT)common_name_length;
95
96 /* Remove the certificate from the local store. */
97 status = _nx_secure_x509_store_certificate_remove(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store,
98 &name, NX_SECURE_X509_CERT_LOCATION_LOCAL, 0);
99 /* Release the protection. */
100 tx_mutex_put(&_nx_secure_tls_protection);
101
102 /* Translate some X.509 return values into TLS return values. */
103 if (status == NX_SECURE_X509_CERTIFICATE_NOT_FOUND)
104 {
105 return(NX_SECURE_TLS_CERTIFICATE_NOT_FOUND);
106 }
107
108 return(status);
109 #else
110 NX_PARAMETER_NOT_USED(tls_session);
111 NX_PARAMETER_NOT_USED(common_name);
112 NX_PARAMETER_NOT_USED(common_name_length);
113
114 return(NX_NOT_SUPPORTED);
115 #endif
116 }
117
118