Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_x509.h"
...
...
_nx_secure_x509_distinguished_name_compare(NX_SECURE_X509_DISTINGUISHED_NAME *, NX_SECURE_X509_DISTINGUISHED_NAME *, ULONG)
...
...
_nx_secure_x509_distinguished_name_field_compare(const UCHAR *, const UINT, const UCHAR *, const UINT)
Files
loading...
CodeScopeSTM32 Libraries and Samplesnetxduonx_secure/src/nx_secure_x509_distinguished_name_compare.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Secure Component */ /** */ /** X.509 Digital Certificates */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SECURE_SOURCE_CODE #include "nx_secure_x509.h" static INT _nx_secure_x509_distinguished_name_field_compare(const UCHAR *field1, UINT length1, const UCHAR *field2, UINT length2); ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_x509_distinguished_name_compare PORTABLE C */ /* 6.1.6 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function compares two X509 Distinguished Names to see if they */ /* are equal. Returns 0 on equality, non-zero otherwise. The */ /* compare_fields parameter is a bitmap that indicates which fields to */ /* compare. In general, internal comparisons (as when validating a */ /* certificate chain) will use NX_SECURE_X509_NAME_ALL_FIELDS, which */ /* will do a full name comparison using the enabled fields (strict */ /* name compare and extended name fields change the behavior). For any */ /* calls coming from application/user API will use the bit value */ /* NX_SECURE_X509_NAME_COMMON_NAME so only the Common Name fields are */ /* compared (even if strict name comparison is enabled). Eventually, */ /* the bitfield may be exposed to the user level to allow users to */ /* have more control over X.509 distinguished name comparisons. */ /* */ /* INPUT */ /* */ /* name Pointer to an X509 name */ /* compare_name Name to compare against */ /* compare_fields Bitmap of fields to compare */ /* */ /* OUTPUT */ /* */ /* equality 0 if equal, else non-zero */ /* */ /* CALLS */ /* */ /* _nx_secure_x509_distinguished_name_field_compare */ /* Compare common names */ /* */ /* CALLED BY */ /* */ /* _nx_secure_tls_send_certificate Send DTLS certificate */ /* _nx_secure_x509_certificate_chain_verify */ /* Verify cert against stores */ /* _nx_secure_x509_certificate_list_add Add incoming cert to store */ /* _nx_secure_x509_certificate_list_find Find certificate by name */ /* _nx_secure_x509_certificate_list_remove */ /* Remove certificate from list */ /* _nx_secure_x509_crl_revocation_check Check revocation in crl */ /* _nx_secure_x509_remote_endpoint_certificate_get */ /* Get remote host certificate */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* 04-02-2021 Timothy Stapko Modified comment(s), */ /* removed dependency on TLS, */ /* resulting in version 6.1.6 */ /* */... /**************************************************************************/ INT _nx_secure_x509_distinguished_name_compare(NX_SECURE_X509_DISTINGUISHED_NAME *name, NX_SECURE_X509_DISTINGUISHED_NAME *compare_name, ULONG compare_fields) { INT status = 0; /* NOTE: The status is updated using a binary OR operation - using addition would allow someone to construct a distinguished name that falsely matches another by explioting the memcmp return values (which are signed so if you had one string that returned a positive value you could negate that by using a string that compared with an equal magnitude negative value). *//* ... */ /* Compare common names for equality. */ if (compare_fields & NX_SECURE_X509_NAME_COMMON_NAME) { status = _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_common_name, name -> nx_secure_x509_common_name_length, compare_name -> nx_secure_x509_common_name, compare_name -> nx_secure_x509_common_name_length); }if (compare_fields & NX_SECURE_X509_NAME_COMMON_NAME) { ... } /* If we are doing strict X509 comparisons, compare ALL fields. */ #ifdef NX_SECURE_X509_STRICT_NAME_COMPARE if (compare_fields & NX_SECURE_X509_NAME_COUNTRY) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_country, name -> nx_secure_x509_country_length, compare_name -> nx_secure_x509_country, compare_name -> nx_secure_x509_country_length); }if (compare_fields & NX_SECURE_X509_NAME_COUNTRY) { ... } if (compare_fields & NX_SECURE_X509_NAME_ORGANIZATION) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_organization, name -> nx_secure_x509_organization_length, compare_name -> nx_secure_x509_organization, compare_name -> nx_secure_x509_organization_length); }if (compare_fields & NX_SECURE_X509_NAME_ORGANIZATION) { ... } if (compare_fields & NX_SECURE_X509_NAME_ORG_UNIT) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_org_unit, name -> nx_secure_x509_org_unit_length, compare_name -> nx_secure_x509_org_unit, compare_name -> nx_secure_x509_org_unit_length); }if (compare_fields & NX_SECURE_X509_NAME_ORG_UNIT) { ... } if (compare_fields & NX_SECURE_X509_NAME_QUALIFIER) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_distinguished_name_qualifier, name -> nx_secure_x509_distinguished_name_qualifier_length, compare_name -> nx_secure_x509_distinguished_name_qualifier, compare_name -> nx_secure_x509_distinguished_name_qualifier_length); }if (compare_fields & NX_SECURE_X509_NAME_QUALIFIER) { ... } if (compare_fields & NX_SECURE_X509_NAME_STATE) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_state, name -> nx_secure_x509_state_length, compare_name -> nx_secure_x509_state, compare_name -> nx_secure_x509_state_length); }if (compare_fields & NX_SECURE_X509_NAME_STATE) { ... } if (compare_fields & NX_SECURE_X509_NAME_SERIAL_NUMBER) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_serial_number, name -> nx_secure_x509_serial_number_length, compare_name -> nx_secure_x509_serial_number, compare_name -> nx_secure_x509_serial_number_length); }if (compare_fields & NX_SECURE_X509_NAME_SERIAL_NUMBER) { ... } #ifdef NX_SECURE_X509_USE_EXTENDED_DISTINGUISHED_NAMES if (compare_fields & NX_SECURE_X509_NAME_LOCALITY) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_locality, name -> nx_secure_x509_locality_length, compare_name -> nx_secure_x509_locality, compare_name -> nx_secure_x509_locality_length); }if (compare_fields & NX_SECURE_X509_NAME_LOCALITY) { ... } if (compare_fields & NX_SECURE_X509_NAME_TITLE) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_title, name -> nx_secure_x509_title_length, compare_name -> nx_secure_x509_title, compare_name -> nx_secure_x509_title_length); }if (compare_fields & NX_SECURE_X509_NAME_TITLE) { ... } if (compare_fields & NX_SECURE_X509_NAME_SURNAME) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_surname, name -> nx_secure_x509_surname_length, compare_name -> nx_secure_x509_surname, compare_name -> nx_secure_x509_surname_length); }if (compare_fields & NX_SECURE_X509_NAME_SURNAME) { ... } if (compare_fields & NX_SECURE_X509_NAME_GIVEN_NAME) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_given_name, name -> nx_secure_x509_given_name_length, compare_name -> nx_secure_x509_given_name, compare_name -> nx_secure_x509_given_name_length); }if (compare_fields & NX_SECURE_X509_NAME_GIVEN_NAME) { ... } if (compare_fields & NX_SECURE_X509_NAME_INITIALS) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_initials, name -> nx_secure_x509_initials_length, compare_name -> nx_secure_x509_initials, compare_name -> nx_secure_x509_initials_length); }if (compare_fields & NX_SECURE_X509_NAME_INITIALS) { ... } if (compare_fields & NX_SECURE_X509_NAME_PSEUDONYM) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_pseudonym, name -> nx_secure_x509_pseudonym_length, compare_name -> nx_secure_x509_pseudonym, compare_name -> nx_secure_x509_pseudonym_length); }if (compare_fields & NX_SECURE_X509_NAME_PSEUDONYM) { ... } if (compare_fields & NX_SECURE_X509_NAME_GENERATION_QUALIFIER) { status |= _nx_secure_x509_distinguished_name_field_compare(name -> nx_secure_x509_generation_qualifier, name -> nx_secure_x509_generation_qualifier_length, compare_name -> nx_secure_x509_generation_qualifier, compare_name -> nx_secure_x509_generation_qualifier_length); }if (compare_fields & NX_SECURE_X509_NAME_GENERATION_QUALIFIER) { ... } /* ... */#endif/* ... */ #endif return(status); }{ ... } .../**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_x509_distinguished_name_field_compare PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function compares two X509 Distinguished Name fields given two */ /* separate lengths to see if they are equal. Handles special cases */ /* where lengths are not equal and when both lengths are 0. */ /* Returns 0 on equality or both lengths 0, non-zero otherwise. */ /* */ /* INPUT */ /* */ /* field1 Pointer to an X509 name field */ /* length1 Length of field1 */ /* field2 Pointer to an X509 name field */ /* length2 Length of field2 */ /* */ /* OUTPUT */ /* */ /* equality 0 if equal, else non-zero */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _nx_secure_x509_distinguished_name_compare */ /* Compare distinguished name */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ static INT _nx_secure_x509_distinguished_name_field_compare(const UCHAR *field1, const UINT length1, const UCHAR *field2, const UINT length2) { INT compare_value; if (length1 == length2) { /* If lengths are both 0, return equality. */ if (length1 == 0) { compare_value = 0; }if (length1 == 0) { ... } else { /* Lengths are equal and non-zero, actually compare strings. */ compare_value = NX_SECURE_MEMCMP(field1, field2, length1); }else { ... } }if (length1 == length2) { ... } else { /* Lengths are not equal, return inequality. */ compare_value = 1; }else { ... } return(compare_value); }{ ... }