1
10
13
14
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
112
113
114
115
116
117
118
122
123
127
128
129
130
131
132
133
134
135
136
137
141
142
146
147
148
149
150
151
152
153
154
155
159
160
164
165
166
167
168
170
171
172
176
177
178
179
180
181
182
183
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
247
248
249
250
251
252
256
260
264
268
269
270
271
272
273
278
279
283
284
285
286
287
288
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_x509.h"
static UINT _nx_secure_x509_extract_name_oid_data(const UCHAR *buffer, UINT oid, ULONG length,
UINT *bytes_processed,
NX_SECURE_X509_DISTINGUISHED_NAME *name);
...
...
UINT _nx_secure_x509_distinguished_name_parse(const UCHAR *buffer, UINT length, UINT *bytes_processed,
NX_SECURE_X509_DISTINGUISHED_NAME *name)
{
USHORT tlv_type;
USHORT tlv_type_class;
ULONG tlv_length;
UINT bytes;
const UCHAR *tlv_data;
ULONG header_length;
UINT status;
UINT current_index;
const UCHAR *sequence_ptr;
ULONG sequence_length;
UINT oid;
/* ... */
current_index = 0;
*bytes_processed = 0;
/* ... */
while (length > 0)
{
status = _nx_secure_x509_asn1_tlv_block_parse(&buffer[current_index], (ULONG *)&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_SET || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
}if (tlv_type != NX_SECURE_ASN_TAG_SET || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
current_index += (header_length + tlv_length);
*bytes_processed += (header_length + tlv_length);
sequence_length = tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, &sequence_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) { ... }
sequence_ptr = tlv_data;
sequence_length = tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(sequence_ptr, &sequence_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_OID || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_UNEXPECTED_ASN1_TAG);
}if (tlv_type != NX_SECURE_ASN_TAG_OID || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
_nx_secure_x509_oid_parse(tlv_data, tlv_length, &oid);
/* ... */
status = _nx_secure_x509_extract_name_oid_data(&tlv_data[tlv_length], oid, sequence_length, &bytes, name);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
}while (length > 0) { ... }
return(NX_SECURE_X509_SUCCESS);
}{ ... }
/* ... */
...
...
static UINT _nx_secure_x509_extract_name_oid_data(const UCHAR *buffer, UINT oid, ULONG length,
UINT *bytes_processed,
NX_SECURE_X509_DISTINGUISHED_NAME *name)
{
USHORT tlv_type;
USHORT tlv_type_class;
ULONG tlv_length;
const UCHAR *tlv_data;
ULONG header_length;
UINT status;
status = _nx_secure_x509_asn1_tlv_block_parse(buffer, &length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
*bytes_processed = (header_length + tlv_length);
switch (oid)
{
case NX_SECURE_TLS_X509_TYPE_COMMON_NAME:
name -> nx_secure_x509_common_name = tlv_data;
name -> nx_secure_x509_common_name_length = (USHORT)tlv_length;
break;case NX_SECURE_TLS_X509_TYPE_COMMON_NAME:
case NX_SECURE_TLS_X509_TYPE_COUNTRY:
name -> nx_secure_x509_country = tlv_data;
name -> nx_secure_x509_country_length = (USHORT)tlv_length;
break;case NX_SECURE_TLS_X509_TYPE_COUNTRY:
case NX_SECURE_TLS_X509_TYPE_STATE:
name -> nx_secure_x509_state = tlv_data;
name -> nx_secure_x509_state_length = (USHORT)tlv_length;
break;case NX_SECURE_TLS_X509_TYPE_STATE:
case NX_SECURE_TLS_X509_TYPE_ORGANIZATION:
name -> nx_secure_x509_organization = tlv_data;
name -> nx_secure_x509_organization_length = (USHORT)tlv_length;
break;case NX_SECURE_TLS_X509_TYPE_ORGANIZATION:
case NX_SECURE_TLS_X509_TYPE_ORG_UNIT:
name -> nx_secure_x509_org_unit = tlv_data;
name -> nx_secure_x509_org_unit_length = (USHORT)tlv_length;
break;
#ifdef NX_SECURE_X509_USE_EXTENDED_DISTINGUISHED_NAMES
case NX_SECURE_TLS_X509_TYPE_LOCALITY:
name -> nx_secure_x509_locality = tlv_data;
name -> nx_secure_x509_locality_length = (USHORT)tlv_length;
break;/* ... */
#endif
default:
/* ... */
break;default
}switch (oid) { ... }
return(NX_SECURE_X509_SUCCESS);
}{ ... }