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