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 /**************************************************************************/
30 /* */
31 /* FUNCTION RELEASE */
32 /* */
33 /* _nx_secure_tls_server_certificate_add PORTABLE C */
34 /* 6.1 */
35 /* AUTHOR */
36 /* */
37 /* Timothy Stapko, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* This function adds a local certificate specifically for a TLS */
42 /* server with a unique integer identifier for use in TLS extensions */
43 /* that support multiple certificates. */
44 /* */
45 /* INPUT */
46 /* */
47 /* tls_session Pointer to TLS Session */
48 /* certificate Pointer to certificate */
49 /* cert_id Unique ID for certificate */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* status Completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _nx_secure_tls_local_certificate_add Add local certificate to */
58 /* TLS session */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
69 /* 09-30-2020 Timothy Stapko Modified comment(s), */
70 /* resulting in version 6.1 */
71 /* */
72 /**************************************************************************/
_nx_secure_tls_server_certificate_add(NX_SECURE_TLS_SESSION * tls_session,NX_SECURE_X509_CERT * certificate,UINT cert_id)73 UINT _nx_secure_tls_server_certificate_add(NX_SECURE_TLS_SESSION *tls_session,
74 NX_SECURE_X509_CERT *certificate, UINT cert_id)
75 {
76 UINT status;
77
78 /* A cert_id of 0 is reserved for certificates that are keyed by distinguished name. */
79 if (cert_id == 0)
80 {
81 return(NX_SECURE_TLS_CERT_ID_INVALID);
82 }
83
84 /* Set the ID for this certificate. */
85 certificate -> nx_secure_x509_cert_identifier = cert_id;
86
87 /* Add the certificate. */
88 status = _nx_secure_tls_local_certificate_add(tls_session, certificate);
89
90 /* Return completion status. */
91 return(status);
92 }
93
94