1
10
13
14
20
21
22
23
24
25
26
27
28
29
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
124
125
126
127
128
133
134
135
136
137
138
139
143
144
145
146
147
151
152
153
154
155
159
160
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
185
186
187
191
192
193
194
195
196
197
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
296
297
301
302
303
304
305
306
307
308
309
310
314
315
316
320
321
322
323
324
325
326
327
328
329
330
331
332
336
337
341
342
343
344
345
346
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_x509.h"
#ifndef NX_SECURE_X509_DISABLE_CRL
static UINT _nx_secure_x509_crl_parse_entry(const UCHAR *buffer, ULONG length, UINT *bytes_processed,
const UCHAR **serial_number, UINT *serial_number_length);/* ... */
#endif
...
...
UINT _nx_secure_x509_crl_revocation_check(const UCHAR *crl_data, UINT crl_length,
NX_SECURE_X509_CERTIFICATE_STORE *store,
NX_SECURE_X509_CERT *certificate)
{
#ifndef NX_SECURE_X509_DISABLE_CRL
NX_SECURE_X509_CRL crl;
UINT status;
UINT crl_bytes;
INT compare_value;
UINT bytes_processed;
UINT length;
const UCHAR *current_buffer;
NX_SECURE_X509_CERT *issuer_certificate;
UINT issuer_location;
const UCHAR *serial_number = NX_NULL;
UINT serial_number_length;
NX_SECURE_MEMSET(&crl, 0, sizeof(NX_SECURE_X509_CRL));
status = _nx_secure_x509_certificate_revocation_list_parse(crl_data, crl_length, &crl_bytes, &crl);
if (status != NX_SECURE_X509_SUCCESS)
{
return(status);
}if (status != NX_SECURE_X509_SUCCESS) { ... }
compare_value = _nx_secure_x509_distinguished_name_compare(&crl.nx_secure_x509_crl_issuer, &certificate -> nx_secure_x509_issuer, NX_SECURE_X509_NAME_ALL_FIELDS);
if (compare_value)
{
return(NX_SECURE_X509_CRL_ISSUER_MISMATCH);
}if (compare_value) { ... }
status = _nx_secure_x509_store_certificate_find(store, &crl.nx_secure_x509_crl_issuer, 0, &issuer_certificate, &issuer_location);
if (status != NX_SECURE_X509_SUCCESS)
{
return(status);
}if (status != NX_SECURE_X509_SUCCESS) { ... }
status = _nx_secure_x509_certificate_chain_verify(store, issuer_certificate);
if (status != NX_SECURE_X509_SUCCESS)
{
return(status);
}if (status != NX_SECURE_X509_SUCCESS) { ... }
status = _nx_secure_x509_crl_verify(certificate, &crl, store, issuer_certificate);
if (status != NX_SECURE_X509_SUCCESS)
{
return(status);
}if (status != NX_SECURE_X509_SUCCESS) { ... }
/* ... */
/* ... */
current_buffer = crl.nx_secure_x509_crl_revoked_certs;
length = crl.nx_secure_x509_crl_revoked_certs_length;
while (length > 0)
{
status = _nx_secure_x509_crl_parse_entry(current_buffer, length, &bytes_processed, &serial_number, &serial_number_length);
if (status != NX_SECURE_X509_SUCCESS)
{
return(status);
}if (status != NX_SECURE_X509_SUCCESS) { ... }
if (length < bytes_processed)
{
return(NX_SECURE_X509_ASN1_LENGTH_TOO_LONG);
}if (length < bytes_processed) { ... }
compare_value = NX_SECURE_MEMCMP(serial_number, certificate -> nx_secure_x509_serial_number,
certificate -> nx_secure_x509_serial_number_length);
if (compare_value == 0)
{
return(NX_SECURE_X509_CRL_CERTIFICATE_REVOKED);
}if (compare_value == 0) { ... }
length -= bytes_processed;
current_buffer = current_buffer + bytes_processed;
}while (length > 0) { ... }
return(NX_SECURE_X509_SUCCESS);/* ... */
#else
NX_CRYPTO_PARAMETER_NOT_USED(crl_data);
NX_CRYPTO_PARAMETER_NOT_USED(crl_length);
NX_CRYPTO_PARAMETER_NOT_USED(store);
NX_CRYPTO_PARAMETER_NOT_USED(certificate);
#ifdef NX_CRYPTO_STANDALONE_ENABLE
return(NX_CRYPTO_FORMAT_NOT_SUPPORTED);
#else
return(NX_NOT_SUPPORTED);
#endif /* ... */
#endif
}{ ... }
#ifndef NX_SECURE_X509_DISABLE_CRL
...
static UINT _nx_secure_x509_crl_parse_entry(const UCHAR *buffer, ULONG length, UINT *bytes_processed,
const UCHAR **serial_number, UINT *serial_number_length)
{
USHORT tlv_type;
USHORT tlv_type_class;
ULONG tlv_length;
const UCHAR *tlv_data;
const UCHAR *current_buffer;
ULONG header_length;
UINT status;
*bytes_processed = 0;
current_buffer = buffer;
status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
}if (tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
*bytes_processed += header_length + tlv_length;
current_buffer = current_buffer + header_length;
length = tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (tlv_type != NX_SECURE_ASN_TAG_INTEGER || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
}if (tlv_type != NX_SECURE_ASN_TAG_INTEGER || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
*serial_number = tlv_data;
*serial_number_length = (USHORT)tlv_length;
current_buffer = current_buffer + (tlv_length + header_length);
status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if ((tlv_type != NX_SECURE_ASN_TAG_UTC_TIME && tlv_type != NX_SECURE_ASN_TAG_GENERALIZED_TIME) || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
}if ((tlv_type != NX_SECURE_ASN_TAG_UTC_TIME && tlv_type != NX_SECURE_ASN_TAG_GENERALIZED_TIME) || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
return(NX_SECURE_X509_SUCCESS);
}{ ... }
#endif... /* ... */