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 #include "nx_secure_x509.h"
25 
26 /* Bring in externs for caller checking code.  */
27 
28 NX_SECURE_CALLER_CHECKING_EXTERNS
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nxe_secure_x509_extension_find                     PORTABLE C      */
36 /*                                                           6.1.6        */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Timothy Stapko, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function checks for errors when attempting to parse through an */
44 /*    X.509 certificate for a specific extension.                         */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    certificate                           Certificate to search         */
49 /*    extension                             Return instruction data       */
50 /*    extension_id                          Extension to search for       */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                                Completion status             */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _nx_secure_x509_extension_find        Actual extensions find call   */
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 /*  04-02-2021     Timothy Stapko           Modified comment(s),          */
72 /*                                            removed dependency on TLS,  */
73 /*                                            resulting in version 6.1.6  */
74 /*                                                                        */
75 /**************************************************************************/
_nxe_secure_x509_extension_find(NX_SECURE_X509_CERT * certificate,NX_SECURE_X509_EXTENSION * extension,USHORT extension_id)76 UINT _nxe_secure_x509_extension_find(NX_SECURE_X509_CERT *certificate,
77                                      NX_SECURE_X509_EXTENSION *extension, USHORT extension_id)
78 {
79 UINT status;
80 
81     if (certificate == NX_CRYPTO_NULL || extension == NX_CRYPTO_NULL)
82     {
83 #ifdef NX_CRYPTO_STANDALONE_ENABLE
84         return(NX_CRYPTO_PTR_ERROR);
85 #else
86         return(NX_PTR_ERROR);
87 #endif /* NX_CRYPTO_STANDALONE_ENABLE */
88     }
89 
90     /* Check for appropriate caller.  */
91     NX_THREADS_ONLY_CALLER_CHECKING
92 
93     status = _nx_secure_x509_extension_find(certificate, extension, extension_id);
94 
95     return(status);
96 }
97 
98