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_add PORTABLE C */
32 /* 6.2.1 */
33 /* AUTHOR */
34 /* */
35 /* Timothy Stapko, Microsoft Corporation */
36 /* */
37 /* DESCRIPTION */
38 /* */
39 /* This function adds a local identity certificate to a DTLS session */
40 /* instance. The certificate is used to identify the DTLS session to */
41 /* a remote host. For DTLS Servers, this certificate is required. For */
42 /* DTLS Clients, the certificate is only needed if the remote server */
43 /* requests one. */
44 /* */
45 /* INPUT */
46 /* */
47 /* dtls_session DTLS session control block */
48 /* certificate Pointer to identity cert */
49 /* cert_id Numeric ID for cert */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* status Completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _nx_secure_tls_server_certificate_add */
58 /* Add certificate to TLS */
59 /* session. */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application Code */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
70 /* 09-30-2020 Timothy Stapko Modified comment(s), */
71 /* resulting in version 6.1 */
72 /* 03-08-2023 Yanwu Cai Modified comment(s), */
73 /* fixed compiler errors when */
74 /* x509 is disabled, */
75 /* resulting in version 6.2.1 */
76 /* */
77 /**************************************************************************/
_nx_secure_dtls_session_local_certificate_add(NX_SECURE_DTLS_SESSION * dtls_session,NX_SECURE_X509_CERT * certificate,UINT cert_id)78 UINT _nx_secure_dtls_session_local_certificate_add(NX_SECURE_DTLS_SESSION *dtls_session,
79 NX_SECURE_X509_CERT *certificate, UINT cert_id)
80 {
81 #if defined(NX_SECURE_ENABLE_DTLS) && !defined(NX_SECURE_DISABLE_X509)
82 UINT status;
83 NX_SECURE_TLS_SESSION *tls_session;
84
85 /* Get the internal TLS session instance. */
86 tls_session = &(dtls_session -> nx_secure_dtls_tls_session);
87
88 /* Add the certificate with the provided ID. Note that the TLS API called here allows us to
89 add a local cert with a numeric ID (legacy local certificate add API does not have id). */
90 status = _nx_secure_tls_server_certificate_add(tls_session, certificate, cert_id);
91
92 return(status);
93 #else
94 NX_PARAMETER_NOT_USED(dtls_session);
95 NX_PARAMETER_NOT_USED(certificate);
96 NX_PARAMETER_NOT_USED(cert_id);
97
98 return(NX_NOT_SUPPORTED);
99 #endif /* NX_SECURE_ENABLE_DTLS && !NX_SECURE_DISABLE_X509 */
100 }
101
102