1
10
13
14
20
21
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
123
124
125
131
132
134
135
136
137
138
139
143
144
145
150
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
173
174
175
176
177
178
179
183
184
186
187
188
189
190
191
192
193
194
195
196
197
201
202
203
204
205
210
211
212
213
214
215
216
217
218
219
222
225
228
231
235
239
240
241
242
243
244
245
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_x509.h"
...
...
UINT _nx_secure_x509_extension_find(NX_SECURE_X509_CERT *certificate,
NX_SECURE_X509_EXTENSION *extension, USHORT extension_id)
{
USHORT tlv_type;
USHORT tlv_type_class;
ULONG tlv_length;
ULONG extensions_sequence_length;
ULONG seq_length;
UINT extension_oid = 0;
USHORT critical_flag;
const UCHAR *tlv_data;
const UCHAR *current_buffer;
ULONG header_length;
UINT status;
UINT found_extension = NX_CRYPTO_FALSE;
/* ... */
current_buffer = certificate -> nx_secure_x509_extensions_data;
extensions_sequence_length = certificate -> nx_secure_x509_extensions_data_length;
while (extensions_sequence_length > 0)
{
status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &extensions_sequence_length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (!(tlv_type_class == NX_SECURE_ASN_TAG_CLASS_UNIVERSAL && tlv_type == NX_SECURE_ASN_TAG_SEQUENCE))
{
/* ... */
return(NX_SECURE_X509_INVALID_EXTENSION_SEQUENCE);
}if (!(tlv_type_class == NX_SECURE_ASN_TAG_CLASS_UNIVERSAL && tlv_type == NX_SECURE_ASN_TAG_SEQUENCE)) { ... }
/* ... */
current_buffer += header_length + tlv_length;
seq_length = tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, &seq_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)
{
_nx_secure_x509_oid_parse(tlv_data, tlv_length, &extension_oid);
}if (tlv_type == NX_SECURE_ASN_TAG_OID) { ... }
else
{
return(NX_SECURE_X509_INVALID_EXTENSION_SEQUENCE);
}else { ... }
if (extension_oid == extension_id)
{
current_buffer = tlv_data + tlv_length;
found_extension = NX_CRYPTO_TRUE;
break;
}if (extension_oid == extension_id) { ... }
}while (extensions_sequence_length > 0) { ... }
if (found_extension != NX_CRYPTO_TRUE)
{
return(NX_SECURE_X509_EXTENSION_NOT_FOUND);
}if (found_extension != NX_CRYPTO_TRUE) { ... }
extension -> nx_secure_x509_extension_id = (USHORT)extension_oid;
status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &seq_length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return status;
}if (status != 0) { ... }
/* ... */
critical_flag = NX_CRYPTO_FALSE;
if (tlv_type == NX_SECURE_ASN_TAG_BOOLEAN)
{
critical_flag = tlv_data[0] != 0;
current_buffer += header_length + tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(current_buffer, &seq_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_BOOLEAN) { ... }
extension -> nx_secure_x509_extension_critical = critical_flag;
if (tlv_type != NX_SECURE_ASN_TAG_OCTET_STRING)
{
return(NX_SECURE_X509_INVALID_EXTENSION_SEQUENCE);
}if (tlv_type != NX_SECURE_ASN_TAG_OCTET_STRING) { ... }
extension -> nx_secure_x509_extension_data = tlv_data;
extension -> nx_secure_x509_extension_data_length = tlv_length;
#if 0
switch (extension_oid)
{
case NX_SECURE_TLS_X509_TYPE_AUTHORITY_KEY_ID:
break;case NX_SECURE_TLS_X509_TYPE_AUTHORITY_KEY_ID:
case NX_SECURE_TLS_X509_TYPE_SUBJECT_KEY_ID:
break;case NX_SECURE_TLS_X509_TYPE_SUBJECT_KEY_ID:
case NX_SECURE_TLS_X509_TYPE_BASIC_CONSTRAINTS:
break;case NX_SECURE_TLS_X509_TYPE_BASIC_CONSTRAINTS:
case NX_SECURE_TLS_X509_TYPE_NETSCAPE_COMMENT:
break;case NX_SECURE_TLS_X509_TYPE_NETSCAPE_COMMENT:
case NX_SECURE_TLS_X509_TYPE_UNKNOWN:
break;case NX_SECURE_TLS_X509_TYPE_UNKNOWN:
default:
break;default
}switch (extension_oid) { ... }
/* ... */#endif
return(NX_SECURE_X509_SUCCESS);
}{ ... }