1
10
13
14
20
21
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
101
102
107
108
109
113
119
120
121
123
124
125
126
129
130
131
132
133
134
135
136
137
138
139
140
141
145
146
147
148
149
150
151
157
158
159
167
168
169
170
171
172
174
175
176
177
178
179
180
181
182
184
185
186
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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
242
243
244
245
246
247
248
258
259
263
264
265
266
267
268
269
270
271
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_tls.h"
...
...
UINT _nx_secure_tls_send_certificate(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet,
ULONG wait_option)
{
UINT length;
UINT total_length;
UCHAR length_buffer[3];
UINT status = NX_SECURE_TLS_SUCCESS;
NX_SECURE_X509_CERT *cert;
INT compare_result = 0;
UCHAR *record_start;
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
UINT extensions_length;
#endif
/* ... */
/* ... */
if (tls_session -> nx_secure_tls_credentials.nx_secure_tls_active_certificate != NX_NULL)
{
cert = tls_session -> nx_secure_tls_credentials.nx_secure_tls_active_certificate;
}if (tls_session -> nx_secure_tls_credentials.nx_secure_tls_active_certificate != NX_NULL) { ... }
else
{
status = _nx_secure_x509_local_device_certificate_get(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store,
NX_NULL, &cert);
}else { ... }
#ifndef NX_SECURE_TLS_CLIENT_DISABLED
/* ... */
if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_CLIENT &&
(status == NX_SECURE_X509_CERTIFICATE_NOT_FOUND))
{
/* ... */
cert = NX_NULL;
tls_session -> nx_secure_tls_client_certificate_requested = NX_FALSE;
}if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_CLIENT && (status == NX_SECURE_X509_CERTIFICATE_NOT_FOUND)) { ... }
else
#endif
{
if (status)
{
if (status == NX_SECURE_X509_CERTIFICATE_NOT_FOUND)
{
return(NX_SECURE_TLS_CERTIFICATE_NOT_FOUND);
}if (status == NX_SECURE_X509_CERTIFICATE_NOT_FOUND) { ... }
return(status);
}if (status) { ... }
}else { ... }
if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) < 3u)
{
return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL);
}if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) < 3u) { ... }
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
if(tls_session->nx_secure_tls_1_3)
{
send_packet -> nx_packet_append_ptr[0] = 0;
send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + 1;
send_packet -> nx_packet_length = send_packet -> nx_packet_length + (USHORT)(1);
}if (tls_session->nx_secure_tls_1_3) { ... }
/* ... */#endif
record_start = send_packet -> nx_packet_append_ptr;
/* ... */
send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + 3;
send_packet -> nx_packet_length = send_packet -> nx_packet_length + (USHORT)(3);
total_length = 0;
while (status == NX_SUCCESS)
{
/* ... */
length = cert -> nx_secure_x509_certificate_raw_data_length;
/* ... */
total_length += (length + 3);
length_buffer[0] = (UCHAR)((length & 0xFF0000) >> 16);
length_buffer[1] = (UCHAR)((length & 0xFF00) >> 8);
length_buffer[2] = (UCHAR)(length & 0xFF);
tx_mutex_put(&_nx_secure_tls_protection);
status = nx_packet_data_append(send_packet, length_buffer, 3,
tls_session -> nx_secure_tls_packet_pool, wait_option);
tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER);
if (status != NX_SUCCESS)
{
return(status);
}if (status != NX_SUCCESS) { ... }
tx_mutex_put(&_nx_secure_tls_protection);
status = nx_packet_data_append(send_packet, cert -> nx_secure_x509_certificate_raw_data, length,
tls_session -> nx_secure_tls_packet_pool, wait_option);
tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER);
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
if(tls_session->nx_secure_tls_1_3)
{
extensions_length = 0;
send_packet -> nx_packet_append_ptr[0] = (UCHAR)((extensions_length & 0xFF00) >> 8);
send_packet -> nx_packet_append_ptr[1] = (UCHAR)(extensions_length & 0x00FF);
send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + 2;
send_packet -> nx_packet_length = send_packet -> nx_packet_length + (USHORT)(2);
total_length += 2;
}if (tls_session->nx_secure_tls_1_3) { ... }
/* ... */#endif
if (status != NX_SUCCESS)
{
return(status);
}if (status != NX_SUCCESS) { ... }
status = _nx_secure_x509_local_device_certificate_get(&tls_session -> nx_secure_tls_credentials.nx_secure_tls_certificate_store,
&cert -> nx_secure_x509_issuer, &cert);
if (status == NX_SUCCESS)
{
compare_result = _nx_secure_x509_distinguished_name_compare(&cert -> nx_secure_x509_distinguished_name,
&cert -> nx_secure_x509_issuer, NX_SECURE_X509_NAME_ALL_FIELDS);
if (compare_result == 0)
{
break;
}if (compare_result == 0) { ... }
}if (status == NX_SUCCESS) { ... }
/* ... */
}while (status == NX_SUCCESS) { ... }
record_start[0] = (UCHAR)((total_length & 0xFF0000) >> 16);
record_start[1] = (UCHAR)((total_length & 0xFF00) >> 8);
record_start[2] = (UCHAR)(total_length & 0xFF);
return(NX_SUCCESS);
}{ ... }