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