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_add PORTABLE C */
31 /* 6.2.1 */
32 /* AUTHOR */
33 /* */
34 /* Timothy Stapko, Microsoft Corporation */
35 /* */
36 /* DESCRIPTION */
37 /* */
38 /* This function adds a trusted certificate to a DTLS session instance.*/
39 /* The certificate is used to verify incoming certificates from remote */
40 /* hosts. For DTLS Clients, at least one certificate is required. For */
41 /* DTLS Servers, the certificate is only needed if the server is */
42 /* configured for X.509 Client verification. */
43 /* */
44 /* INPUT */
45 /* */
46 /* dtls_session DTLS session control block */
47 /* certificate Pointer to identity cert */
48 /* cert_id Numeric ID for cert */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* status Completion status */
53 /* */
54 /* CALLS */
55 /* */
56 /* _nx_secure_tls_trusted_certificate_add */
57 /* Add certificate to TLS */
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_trusted_certificate_add(NX_SECURE_DTLS_SESSION * dtls_session,NX_SECURE_X509_CERT * certificate,UINT cert_id)76 UINT _nx_secure_dtls_session_trusted_certificate_add(NX_SECURE_DTLS_SESSION *dtls_session,
77 NX_SECURE_X509_CERT *certificate, 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 /* Set the certificate ID. */
87 certificate->nx_secure_x509_cert_identifier = cert_id;
88
89 /* Add the certificate with the provided ID assigned above. */
90 status = _nx_secure_tls_trusted_certificate_add(tls_session, certificate);
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