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 #include "nx_secure_x509.h"
26
27 /**************************************************************************/
28 /* */
29 /* FUNCTION RELEASE */
30 /* */
31 /* _nx_secure_x509_store_certificate_remove PORTABLE C */
32 /* 6.1.6 */
33 /* AUTHOR */
34 /* */
35 /* Timothy Stapko, Microsoft Corporation */
36 /* */
37 /* DESCRIPTION */
38 /* */
39 /* This function removes a certificate from an X509 certificate store */
40 /* in a caller-specified position (local device certificates, remote */
41 /* certs, or the trusted store). */
42 /* */
43 /* INPUT */
44 /* */
45 /* store Pointer to certificate store */
46 /* name Name for cert matching */
47 /* location Location of certificate */
48 /* cert_id ID for cert match. */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* status Completion status */
53 /* */
54 /* CALLS */
55 /* */
56 /* _nx_secure_x509_certificate_list_remove */
57 /* Remove certificate from list */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* _nx_secure_tls_local_certificate_remove */
62 /* Remove certificate from TLS */
63 /* local store */
64 /* _nx_secure_tls_remote_certificate_free */
65 /* Free remote certificate */
66 /* _nx_secure_tls_server_certificate_remove */
67 /* Remove certificate from TLS */
68 /* server store */
69 /* _nx_secure_tls_trusted_certificate_remove */
70 /* Remove certificate from TLS */
71 /* trusted store */
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 /**************************************************************************/
_nx_secure_x509_store_certificate_remove(NX_SECURE_X509_CERTIFICATE_STORE * store,NX_SECURE_X509_DISTINGUISHED_NAME * name,UINT location,UINT cert_id)85 UINT _nx_secure_x509_store_certificate_remove(NX_SECURE_X509_CERTIFICATE_STORE *store,
86 NX_SECURE_X509_DISTINGUISHED_NAME *name,
87 UINT location, UINT cert_id)
88 {
89 UINT status;
90 NX_SECURE_X509_CERT **store_ptr = NX_CRYPTO_NULL;
91
92 /* Store must be non-NULL. */
93 if (store == NX_CRYPTO_NULL)
94 {
95 #ifdef NX_CRYPTO_STANDALONE_ENABLE
96 return(NX_CRYPTO_PTR_ERROR);
97 #else
98 return(NX_PTR_ERROR);
99 #endif /* NX_CRYPTO_STANDALONE_ENABLE */
100 }
101
102 status = NX_SECURE_X509_SUCCESS;
103
104 /* Pick our store based on location. */
105 switch (location)
106 {
107 case NX_SECURE_X509_CERT_LOCATION_LOCAL:
108 store_ptr = &store -> nx_secure_x509_local_certificates;
109 break;
110 case NX_SECURE_X509_CERT_LOCATION_REMOTE:
111 store_ptr = &store -> nx_secure_x509_remote_certificates;
112 break;
113 case NX_SECURE_X509_CERT_LOCATION_TRUSTED:
114 store_ptr = &store -> nx_secure_x509_trusted_certificates;
115 break;
116 case NX_SECURE_X509_CERT_LOCATION_EXCEPTIONS:
117 store_ptr = &store -> nx_secure_x509_certificate_exceptions;
118 break;
119 case NX_SECURE_X509_CERT_LOCATION_NONE: /* Deliberate fall-through. */
120 default:
121 #ifdef NX_CRYPTO_STANDALONE_ENABLE
122 status = NX_CRYPTO_INVALID_PARAMETER;
123 #else
124 status = NX_INVALID_PARAMETERS;
125 #endif /* NX_CRYPTO_STANDALONE_ENABLE */
126 break;
127 }
128
129 /* Invalid certificate location or other issue. */
130 if (status)
131 {
132 return(status);
133 }
134
135 /* Remove the certificate from the selected store. */
136 status = _nx_secure_x509_certificate_list_remove(store_ptr, name, cert_id);
137
138 return(status);
139 }
140
141