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