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