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_trusted_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 trusted certificate from a DTLS session.    */
39 /*                                                                        */
40 /*  INPUT                                                                 */
41 /*                                                                        */
42 /*    dtls_session                          DTLS session control block    */
43 /*    common_name                           Certificate common name       */
44 /*    common_name_length                    Length of common name string  */
45 /*    cert_id                               Numeric ID for certificate    */
46 /*                                                                        */
47 /*  OUTPUT                                                                */
48 /*                                                                        */
49 /*    status                                Completion status             */
50 /*                                                                        */
51 /*  CALLS                                                                 */
52 /*                                                                        */
53 /*    _nx_secure_tls_trusted_certificate_remove                           */
54 /*                                          Remove certificate from TLS   */
55 /*    _nx_secure_x509_store_certificate_remove                            */
56 /*                                          Remove certificate from store */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Application Code                                                    */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
67 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*  03-08-2023     Yanwu Cai                Modified comment(s),          */
70 /*                                            fixed compiler errors when  */
71 /*                                            x509 is disabled,           */
72 /*                                            resulting in version 6.2.1  */
73 /*                                                                        */
74 /**************************************************************************/
_nx_secure_dtls_session_trusted_certificate_remove(NX_SECURE_DTLS_SESSION * dtls_session,UCHAR * common_name,UINT common_name_length,UINT cert_id)75 UINT _nx_secure_dtls_session_trusted_certificate_remove(NX_SECURE_DTLS_SESSION *dtls_session,
76                                                         UCHAR *common_name, UINT common_name_length, UINT cert_id)
77 {
78 #if defined(NX_SECURE_ENABLE_DTLS) && !defined(NX_SECURE_DISABLE_X509)
79 UINT status;
80 NX_SECURE_TLS_SESSION *tls_session;
81 
82     /* Get the internal TLS session instance. */
83     tls_session = &(dtls_session -> nx_secure_dtls_tls_session);
84 
85     if(cert_id != 0)
86     {
87         /* Remove certificate using certificate ID. */
88         status = _nx_secure_x509_store_certificate_remove(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store,
89                                                           NX_NULL, NX_SECURE_X509_CERT_LOCATION_TRUSTED, cert_id);
90     }
91     else
92     {
93         /* Remove the trusted certificate with the given common name. */
94         status = _nx_secure_tls_trusted_certificate_remove(tls_session, common_name, common_name_length);
95     }
96 
97     return(status);
98 #else
99     NX_PARAMETER_NOT_USED(dtls_session);
100     NX_PARAMETER_NOT_USED(common_name);
101     NX_PARAMETER_NOT_USED(common_name_length);
102     NX_PARAMETER_NOT_USED(cert_id);
103 
104     return(NX_NOT_SUPPORTED);
105 #endif /* NX_SECURE_ENABLE_DTLS && !NX_SECURE_DISABLE_X509 */
106 }
107 
108