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 /*    _nxe_secure_dtls_session_trusted_certificate_add    PORTABLE C      */
32 /*                                                           6.1          */
33 /*  AUTHOR                                                                */
34 /*                                                                        */
35 /*    Timothy Stapko, Microsoft Corporation                               */
36 /*                                                                        */
37 /*  DESCRIPTION                                                           */
38 /*                                                                        */
39 /*    This function checks for errors when adding a trusted certificate   */
40 /*    to a DTLS session instance.                                         */
41 /*                                                                        */
42 /*  INPUT                                                                 */
43 /*                                                                        */
44 /*    dtls_session                          DTLS session control block    */
45 /*    certificate                           Pointer to identity cert      */
46 /*    cert_id                               Numeric ID for cert           */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    status                                Completion status             */
51 /*                                                                        */
52 /*  CALLS                                                                 */
53 /*                                                                        */
54 /*    _nx_secure_dtls_session_trusted_certificate_add                     */
55 /*                                          Actual function call          */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    Application Code                                                    */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
66 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
67 /*                                            resulting in version 6.1    */
68 /*                                                                        */
69 /**************************************************************************/
_nxe_secure_dtls_session_trusted_certificate_add(NX_SECURE_DTLS_SESSION * dtls_session,NX_SECURE_X509_CERT * certificate,UINT cert_id)70 UINT _nxe_secure_dtls_session_trusted_certificate_add(NX_SECURE_DTLS_SESSION *dtls_session,
71                                                      NX_SECURE_X509_CERT *certificate, UINT cert_id)
72 {
73 #ifdef NX_SECURE_ENABLE_DTLS
74 UINT status;
75 
76     if ((dtls_session == NX_NULL) || (certificate == NX_NULL))
77     {
78         return(NX_PTR_ERROR);
79     }
80 
81     /* Make sure the session is initialized. */
82     if (dtls_session->nx_secure_dtls_tls_session.nx_secure_tls_id != NX_SECURE_TLS_ID)
83     {
84         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
85     }
86 
87     /* We don't want to add certificates without an ID. */
88     if (cert_id == 0)
89     {
90         return(NX_INVALID_PARAMETERS);
91     }
92 
93     /* Add the certificate with the provided ID assigned above.  */
94     status = _nx_secure_dtls_session_trusted_certificate_add(dtls_session, certificate, cert_id);
95 
96     return(status);
97 #else
98     NX_PARAMETER_NOT_USED(dtls_session);
99     NX_PARAMETER_NOT_USED(certificate);
100     NX_PARAMETER_NOT_USED(cert_id);
101 
102     return(NX_NOT_SUPPORTED);
103 #endif /* NX_SECURE_ENABLE_DTLS */
104 }
105