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_dns_name_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 DNS name init call.     */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    dns_name                              Name structure                */
50 /*    name_string                           DNS name string               */
51 /*    length                                Length of name string         */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    status                                Completion status             */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _nx_secure_x509_dns_name_initialize                                 */
60 /*                                          Actual DNS name init call     */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
71 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*  04-02-2021     Timothy Stapko           Modified comment(s),          */
74 /*                                            removed dependency on TLS,  */
75 /*                                            resulting in version 6.1.6  */
76 /*                                                                        */
77 /**************************************************************************/
_nxe_secure_x509_dns_name_initialize(NX_SECURE_X509_DNS_NAME * dns_name,const UCHAR * name_string,USHORT length)78 UINT _nxe_secure_x509_dns_name_initialize(NX_SECURE_X509_DNS_NAME *dns_name,
79                                           const UCHAR *name_string, USHORT length)
80 {
81 UINT status;
82 
83     if (dns_name == NX_CRYPTO_NULL)
84     {
85 #ifdef NX_CRYPTO_STANDALONE_ENABLE
86         return(NX_CRYPTO_PTR_ERROR);
87 #else
88         return(NX_PTR_ERROR);
89 #endif /* NX_CRYPTO_STANDALONE_ENABLE */
90     }
91 
92     if (length > NX_SECURE_X509_DNS_NAME_MAX)
93     {
94         return(NX_SECURE_X509_NAME_STRING_TOO_LONG);
95     }
96 
97     /* Check for appropriate caller.  */
98     NX_THREADS_ONLY_CALLER_CHECKING
99 
100     /* Actual function call. */
101     status = _nx_secure_x509_dns_name_initialize(dns_name, name_string, length);
102 
103     /* Return completion status.  */
104     return(status);
105 }
106 
107