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 /**    Transport Layer Security (TLS)                                     */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SECURE_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "nx_secure_tls.h"
28 
29 /* Bring in externs for caller checking code.  */
30 
31 NX_SECURE_CALLER_CHECKING_EXTERNS
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _nxe_secure_tls_client_psk_set                      PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Timothy Stapko, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the TLS client psk set call.     */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    tls_session                           Pointer to TLS Session        */
50 /*    pre_shared_key                        The Preshared Key             */
51 /*    psk_length                            Length of preshared key       */
52 /*    psk_identity                          Identity string               */
53 /*    identity_length                       Length of the identity string */
54 /*    hint                                  Hint string                   */
55 /*    hint_length                           Length of the hint string     */
56 /*                                                                        */
57 /*  OUTPUT                                                                */
58 /*                                                                        */
59 /*    status                                Completion status             */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    _nx_secure_tls_client_psk_set         Actual TLS client PSK set     */
64 /*                                            call                        */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Application Code                                                    */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
75 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
79 #ifdef NX_SECURE_ENABLE_PSK_CIPHERSUITES
_nxe_secure_tls_client_psk_set(NX_SECURE_TLS_SESSION * tls_session,UCHAR * pre_shared_key,UINT psk_length,UCHAR * psk_identity,UINT identity_length,UCHAR * hint,UINT hint_length)80 UINT _nxe_secure_tls_client_psk_set(NX_SECURE_TLS_SESSION *tls_session, UCHAR *pre_shared_key, UINT psk_length,
81                                     UCHAR *psk_identity, UINT identity_length, UCHAR *hint, UINT hint_length)
82 {
83 UINT status;
84 
85     if ((tls_session == NX_NULL) || (pre_shared_key == NX_NULL) || (psk_length == 0))
86     {
87         return(NX_PTR_ERROR);
88     }
89 
90     /* Make sure the session is initialized. */
91     if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID)
92     {
93         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
94     }
95 
96     /* Check for appropriate caller.  */
97     NX_THREADS_ONLY_CALLER_CHECKING
98 
99     status =  _nx_secure_tls_client_psk_set(tls_session, pre_shared_key, psk_length, psk_identity, identity_length, hint, hint_length);
100 
101     /* Return completion status.  */
102     return(status);
103 }
104 
105 #endif
106 
107