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_server_psk_add PORTABLE C */
31 /* 6.1 */
32 /* AUTHOR */
33 /* */
34 /* Timothy Stapko, Microsoft Corporation */
35 /* */
36 /* DESCRIPTION */
37 /* */
38 /* This function adds a Pre-Shared Key (PSK) to a DTLS server instance.*/
39 /* The PSK added is shared by all DTLS sessions. */
40 /* */
41 /* INPUT */
42 /* */
43 /* server_ptr DTLS server control block */
44 /* pre_shared_key Pointer to PSK data */
45 /* psk_length Length of PSK data */
46 /* psk_identity PSK id data */
47 /* identity_length Length of PSK id data */
48 /* hint PSK hint data */
49 /* hint_length Length of PSK hint data */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* status Completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _nx_secure_dtls_psk_add Add PSK to DTLS session */
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 /* */
71 /**************************************************************************/
72 #if defined(NX_SECURE_ENABLE_PSK_CIPHERSUITES) || defined(NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE)
_nx_secure_dtls_server_psk_add(NX_SECURE_DTLS_SERVER * server_ptr,UCHAR * pre_shared_key,UINT psk_length,UCHAR * psk_identity,UINT identity_length,UCHAR * hint,UINT hint_length)73 UINT _nx_secure_dtls_server_psk_add(NX_SECURE_DTLS_SERVER *server_ptr, UCHAR *pre_shared_key,
74 UINT psk_length, UCHAR *psk_identity, UINT identity_length, UCHAR *hint,
75 UINT hint_length)
76 {
77 #ifdef NX_SECURE_ENABLE_DTLS
78 UINT status;
79 UINT i;
80 NX_SECURE_DTLS_SESSION *current_session;
81 UINT num_sessions;
82
83 /* Figure out number of sessions. */
84 num_sessions = server_ptr->nx_dtls_server_sessions_count;
85
86 /* Add certificate to all sessions. */
87 for(i = 0; i < num_sessions; ++i)
88 {
89 /* Get the current session. */
90 current_session = &(server_ptr->nx_dtls_server_sessions[i]);
91
92 /* Add the PSK with its ID and hint. */
93 status = _nx_secure_dtls_psk_add(current_session, pre_shared_key, psk_length, psk_identity, identity_length, hint, hint_length);
94
95 if(status != NX_SUCCESS)
96 {
97 return(status);
98 }
99 }
100
101 return(NX_SUCCESS);
102 #else
103 NX_PARAMETER_NOT_USED(server_ptr);
104 NX_PARAMETER_NOT_USED(pre_shared_key);
105 NX_PARAMETER_NOT_USED(psk_length);
106 NX_PARAMETER_NOT_USED(psk_identity);
107 NX_PARAMETER_NOT_USED(identity_length);
108 NX_PARAMETER_NOT_USED(hint);
109 NX_PARAMETER_NOT_USED(hint_length);
110
111 return(NX_NOT_SUPPORTED);
112 #endif /* NX_SECURE_ENABLE_DTLS */
113 }
114 #endif
115