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 /**    X.509 Digital Certificates                                         */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SECURE_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "nx_secure_x509.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_x509_certificate_initialize             PORTABLE C      */
38 /*                                                           6.1.6        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Timothy Stapko, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the X509 Initialize call.        */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    certificate                           Certificate structure         */
50 /*    certificate_data                      Pointer to certificate data   */
51 /*    length                                Length of certificate data    */
52 /*    raw_data_buffer                       Buffer to hold raw cert data  */
53 /*    buffer_size                           Size of raw data buffer       */
54 /*    private_key                           Pointer to private key data   */
55 /*    priv_len                              Length of private key data    */
56 /*    private_key_type                      Type of private key data      */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                                Completion status             */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _nx_secure_x509_certificate_initialize                              */
65 /*                                          Actual X509 certificate       */
66 /*                                            initialize call             */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
77 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
78 /*                                            resulting in version 6.1    */
79 /*  04-02-2021     Timothy Stapko           Modified comment(s),          */
80 /*                                            removed dependency on TLS,  */
81 /*                                            resulting in version 6.1.6  */
82 /*                                                                        */
83 /**************************************************************************/
_nxe_secure_x509_certificate_initialize(NX_SECURE_X509_CERT * certificate,UCHAR * certificate_data,USHORT length,UCHAR * raw_data_buffer,USHORT buffer_size,const UCHAR * private_key,USHORT priv_len,UINT private_key_type)84 UINT _nxe_secure_x509_certificate_initialize(NX_SECURE_X509_CERT *certificate, UCHAR *certificate_data,
85                                              USHORT length, UCHAR *raw_data_buffer,
86                                              USHORT buffer_size, const UCHAR *private_key,
87                                              USHORT priv_len, UINT private_key_type)
88 {
89 UINT status;
90 
91     if ((certificate == NX_CRYPTO_NULL) || (certificate_data == NX_CRYPTO_NULL) || (length == 0))
92     {
93 #ifdef NX_CRYPTO_STANDALONE_ENABLE
94         return(NX_CRYPTO_PTR_ERROR);
95 #else
96         return(NX_PTR_ERROR);
97 #endif /* NX_CRYPTO_STANDALONE_ENABLE */
98     }
99 
100     /* Check for appropriate caller.  */
101     NX_THREADS_ONLY_CALLER_CHECKING
102 
103     status = _nx_secure_x509_certificate_initialize(certificate, certificate_data, length, raw_data_buffer, buffer_size, private_key, priv_len, private_key_type);
104 
105     /* Return completion status.  */
106     return(status);
107 }
108 
109