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 /* _nxe_secure_dtls_session_local_certificate_add PORTABLE C */ 32 /* 6.1 */ 33 /* AUTHOR */ 34 /* */ 35 /* Timothy Stapko, Microsoft Corporation */ 36 /* */ 37 /* DESCRIPTION */ 38 /* */ 39 /* This function checks for errors when adding a local identity */ 40 /* certificate to a DTLS session instance. */ 41 /* requests one. */ 42 /* */ 43 /* INPUT */ 44 /* */ 45 /* dtls_session DTLS session control block */ 46 /* certificate Pointer to identity cert */ 47 /* cert_id Numeric ID for cert */ 48 /* */ 49 /* OUTPUT */ 50 /* */ 51 /* status Completion status */ 52 /* */ 53 /* CALLS */ 54 /* */ 55 /* _nx_secure_dtls_session_local_certificate_add */ 56 /* Actual function call */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* Application Code */ 61 /* */ 62 /* RELEASE HISTORY */ 63 /* */ 64 /* DATE NAME DESCRIPTION */ 65 /* */ 66 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ 67 /* 09-30-2020 Timothy Stapko Modified comment(s), */ 68 /* resulting in version 6.1 */ 69 /* */ 70 /**************************************************************************/ _nxe_secure_dtls_session_local_certificate_add(NX_SECURE_DTLS_SESSION * dtls_session,NX_SECURE_X509_CERT * certificate,UINT cert_id)71UINT _nxe_secure_dtls_session_local_certificate_add(NX_SECURE_DTLS_SESSION *dtls_session, 72 NX_SECURE_X509_CERT *certificate, UINT cert_id) 73 { 74 #ifdef NX_SECURE_ENABLE_DTLS 75 UINT status; 76 77 if ((dtls_session == NX_NULL) || (certificate == NX_NULL)) 78 { 79 return(NX_PTR_ERROR); 80 } 81 82 /* Make sure the session is initialized. */ 83 if (dtls_session->nx_secure_dtls_tls_session.nx_secure_tls_id != NX_SECURE_TLS_ID) 84 { 85 return(NX_SECURE_TLS_SESSION_UNINITIALIZED); 86 } 87 88 /* We don't want to add server identity certificates without an ID. */ 89 if (cert_id == 0) 90 { 91 return(NX_INVALID_PARAMETERS); 92 } 93 94 /* Add the certificate with the provided ID. Note that the TLS API called here allows us to 95 add a local cert with a numeric ID (legacy local certificate add API does not have id). */ 96 status = _nx_secure_dtls_session_local_certificate_add(dtls_session, certificate, cert_id); 97 98 return(status); 99 #else 100 NX_PARAMETER_NOT_USED(dtls_session); 101 NX_PARAMETER_NOT_USED(certificate); 102 NX_PARAMETER_NOT_USED(cert_id); 103 104 return(NX_NOT_SUPPORTED); 105 #endif /* NX_SECURE_ENABLE_DTLS */ 106 } 107 108