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 /** Datagram Transport Layer Security (DTLS) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SECURE_SOURCE_CODE
23
24 #include "nx_secure_dtls.h"
25
26 /**************************************************************************/
27 /* */
28 /* FUNCTION RELEASE */
29 /* */
30 /* _nx_secure_dtls_session_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 a local identity certificate from a DTLS */
39 /* session. */
40 /* */
41 /* INPUT */
42 /* */
43 /* dtls_session DTLS session control block */
44 /* common_name Certificate common name */
45 /* common_name_length Length of common name string */
46 /* cert_id Numeric ID for certificate */
47 /* */
48 /* OUTPUT */
49 /* */
50 /* status Completion status */
51 /* */
52 /* CALLS */
53 /* */
54 /* _nx_secure_tls_local_certificate_remove */
55 /* Remove certificate from TLS */
56 /* _nx_secure_x509_store_certificate_remove */
57 /* Remove certificate from 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 /* 03-08-2023 Yanwu Cai Modified comment(s), */
71 /* fixed compiler errors when */
72 /* x509 is disabled, */
73 /* resulting in version 6.2.1 */
74 /* */
75 /**************************************************************************/
_nx_secure_dtls_session_local_certificate_remove(NX_SECURE_DTLS_SESSION * dtls_session,UCHAR * common_name,UINT common_name_length,UINT cert_id)76 UINT _nx_secure_dtls_session_local_certificate_remove(NX_SECURE_DTLS_SESSION *dtls_session,
77 UCHAR *common_name, UINT common_name_length, UINT cert_id)
78 {
79 #if defined(NX_SECURE_ENABLE_DTLS) && !defined(NX_SECURE_DISABLE_X509)
80 UINT status;
81 NX_SECURE_TLS_SESSION *tls_session;
82
83 /* Get the internal TLS session instance. */
84 tls_session = &(dtls_session -> nx_secure_dtls_tls_session);
85
86 if(cert_id != 0)
87 {
88 /* Remove certificate using certificate ID. */
89 status = _nx_secure_x509_store_certificate_remove(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store,
90 NX_NULL, NX_SECURE_X509_CERT_LOCATION_LOCAL, cert_id);
91 }
92 else
93 {
94 /* Remove the local certificate with the given common name. */
95 status = _nx_secure_tls_local_certificate_remove(tls_session, common_name, common_name_length);
96 }
97
98 return(status);
99 #else
100 NX_PARAMETER_NOT_USED(dtls_session);
101 NX_PARAMETER_NOT_USED(common_name);
102 NX_PARAMETER_NOT_USED(common_name_length);
103 NX_PARAMETER_NOT_USED(cert_id);
104
105 return(NX_NOT_SUPPORTED);
106 #endif /* NX_SECURE_ENABLE_DTLS && !NX_SECURE_DISABLE_X509 */
107 }
108
109