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