1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
34
35
36
37
46
47
48
49
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
138
139
140
141
148
149
150
151
152
153
154
155
156
157
158
160
164
165
166
167
168
169
170
171
172
173
174
175
183
184
185
186
187
188
198
206
207
208
209
210
211
212
213
214
215
216
217
218
222
223
231
232
233
234
235
236
237
238
239
243
244
245
247
248
249
253
254
255
256
257
261
262
263
264
265
266
281
282
285
286
287
288
289
290
291
293
294
295
296
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
318
319
320
321
325
326
327
328
329
330
331
332
333
334
341
342
343
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
451
452
453
454
455
459
460
461
462
463
464
468
469
470
471
472
473
474
482
483
484
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
553
554
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
686
687
688
689
690
691
695
696
697
698
699
700
705
706
710
711
712
714
719
720
721
722
723
728
729
730
731
732
733
738
739
740
741
742
743
744
745
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
834
835
836
837
838
839
840
841
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
865
866
867
868
869
875
876
877
878
879
883
884
885
886
890
891
892
894
895
896
901
902
903
904
905
906
907
908
912
913
914
915
916
920
921
922
923
924
925
926
927
928
929
930
931
935
936
937
938
939
940
941
942
943
944
945
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
988
989
990
991
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1065
1066
1069
1070
1071
1072
1073
1074
1075
1076
1080
1081
1082
1083
1087
1088
1089
1090
1091
1092
1093
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_tls.h"
#ifndef NX_SECURE_TLS_CLIENT_DISABLED
#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION
static UINT _nx_secure_tls_proc_serverhello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length);/* ... */
#endif
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
static UINT _nx_secure_tls_proc_serverhello_keyshare_extension(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length);/* ... */
#endif
static UINT _nx_secure_tls_proc_serverhello_supported_versions_extension(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *supported_version,
USHORT *extension_length, UINT message_length);/* ... */
#endif
#ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
static UINT _nx_secure_tls_proc_serverhello_ecc_point_formats(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length);
static UINT _nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length);/* ... */
#endif
/* ... */
#endif
...
...
UINT _nx_secure_tls_process_serverhello_extensions(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer, UINT message_length,
NX_SECURE_TLS_HELLO_EXTENSION *extensions,
UINT *num_extensions)
{
#ifndef NX_SECURE_TLS_CLIENT_DISABLED
UINT status;
#ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
USHORT ec_point_formats_match, zkp_verified;
#endif
UINT offset;
USHORT extension_id;
USHORT extension_length;
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
USHORT supported_version = tls_session -> nx_secure_tls_protocol_version;
#endif
#ifdef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION
#ifndef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
NX_PARAMETER_NOT_USED(tls_session);
#endif/* ... */
#endif
#ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL)
{
return(NX_SECURE_TLS_UNKNOWN_CIPHERSUITE);
}if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL) { ... }
ec_point_formats_match = NX_FALSE;
zkp_verified = NX_FALSE;/* ... */
#endif
offset = 0;
status = NX_SUCCESS;
*num_extensions = 0;
while (offset < message_length)
{
/* ... */
if (offset + 4 > message_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (offset + 4 > message_length) { ... }
extension_id = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset += 2;
switch (extension_id)
{
#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION
case NX_SECURE_TLS_EXTENSION_SECURE_RENEGOTIATION:
status = _nx_secure_tls_proc_serverhello_sec_reneg_extension(tls_session, &packet_buffer[offset], &extension_length, message_length - offset);
if (status)
{
return(status);
}if (status) { ... }
break;/* ... */
#endif
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
case NX_SECURE_TLS_EXTENSION_KEY_SHARE:
if(tls_session->nx_secure_tls_1_3)
{
status = _nx_secure_tls_proc_serverhello_keyshare_extension(tls_session, &packet_buffer[offset], &extension_length, message_length - offset);
if (status)
{
return(status);
}if (status) { ... }
}if (tls_session->nx_secure_tls_1_3) { ... }
else
{
extension_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
if (extension_length + offset + 2 > message_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (extension_length + offset + 2 > message_length) { ... }
}else { ... }
offset += 2;
break;/* ... */
#endifcase NX_SECURE_TLS_EXTENSION_KEY_SHARE:
case NX_SECURE_TLS_EXTENSION_SUPPORTED_VERSIONS:
if(tls_session->nx_secure_tls_1_3)
{
status = _nx_secure_tls_proc_serverhello_supported_versions_extension(tls_session, &packet_buffer[offset], &supported_version, &extension_length, message_length - offset);
if (status)
{
return(status);
}if (status) { ... }
}if (tls_session->nx_secure_tls_1_3) { ... }
else
{
extension_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
if (extension_length + offset + 2 > message_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (extension_length + offset + 2 > message_length) { ... }
}else { ... }
offset += 2;
break;case NX_SECURE_TLS_EXTENSION_SUPPORTED_VERSIONS:
case NX_SECURE_TLS_EXTENSION_COOKIE:
extension_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset += 2;
if (extension_length + offset > message_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (extension_length + offset > message_length) { ... }
/* ... */
if (tls_session -> nx_secure_tls_1_3)
{
if (extension_length < 2)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (extension_length < 2) { ... }
tls_session -> nx_secure_tls_cookie_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
tls_session -> nx_secure_tls_cookie = &packet_buffer[offset + 2];
if (tls_session -> nx_secure_tls_cookie_length + 2 > extension_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (tls_session -> nx_secure_tls_cookie_length + 2 > extension_length) { ... }
}if (tls_session -> nx_secure_tls_1_3) { ... }
break;/* ... */
#endif
#ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
case NX_SECURE_TLS_EXTENSION_EC_POINT_FORMATS:
status = _nx_secure_tls_proc_serverhello_ecc_point_formats(tls_session, &packet_buffer[offset], &extension_length, message_length - offset);
if (status == NX_SUCCESS)
{
ec_point_formats_match = NX_TRUE;
}if (status == NX_SUCCESS) { ... }
break;case NX_SECURE_TLS_EXTENSION_EC_POINT_FORMATS:
case NX_SECURE_TLS_EXTENSION_ECJPAKE_KEY_KP_PAIR:
status = _nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair(tls_session, &packet_buffer[offset], &extension_length, message_length - offset);
if (status == NX_SUCCESS)
{
zkp_verified = NX_TRUE;
}if (status == NX_SUCCESS) { ... }
break;/* ... */
#else
case NX_SECURE_TLS_EXTENSION_EC_GROUPS:
case NX_SECURE_TLS_EXTENSION_EC_POINT_FORMATS:
case NX_SECURE_TLS_EXTENSION_ECJPAKE_KEY_KP_PAIR:/* ... */
#endif
case NX_SECURE_TLS_EXTENSION_SERVER_NAME_INDICATION:
case NX_SECURE_TLS_EXTENSION_MAX_FRAGMENT_LENGTH:
case NX_SECURE_TLS_EXTENSION_CLIENT_CERTIFICATE_URL:
case NX_SECURE_TLS_EXTENSION_TRUSTED_CA_INDICATION:
case NX_SECURE_TLS_EXTENSION_CERTIFICATE_STATUS_REQUEST:
/* ... */
extension_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset += 2;
if (extension_length + offset > message_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (extension_length + offset > message_length) { ... }
if (*num_extensions < NX_SECURE_TLS_HELLO_EXTENSIONS_MAX)
{
extensions[*num_extensions].nx_secure_tls_extension_id = extension_id;
extensions[*num_extensions].nx_secure_tls_extension_data = &packet_buffer[offset];
extensions[*num_extensions].nx_secure_tls_extension_data_length = extension_length;
*num_extensions = *num_extensions + 1;
}if (*num_extensions < NX_SECURE_TLS_HELLO_EXTENSIONS_MAX) { ... }
break;case NX_SECURE_TLS_EXTENSION_CERTIFICATE_STATUS_REQUEST:
case NX_SECURE_TLS_EXTENSION_SIGNATURE_ALGORITHMS:
case NX_SECURE_TLS_EXTENSION_TRUNCATED_HMAC:
default:
/* ... */
extension_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset += 2;
if (extension_length + offset > message_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (extension_length + offset > message_length) { ... }
break;default
}switch (extension_id) { ... }
offset += extension_length;
}while (offset < message_length) { ... }
#ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
if ((tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECJPAKE) &&
(ec_point_formats_match == 0 || zkp_verified == 0))
{
return(NX_SECURE_TLS_UNSUPPORTED_ECC_FORMAT);
}if ((tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECJPAKE) && (ec_point_formats_match == 0 || zkp_verified == 0)) { ... }
/* ... */#endif
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
if(tls_session->nx_secure_tls_1_3)
{
if (supported_version != NX_SECURE_TLS_VERSION_TLS_1_3)
{
if (tls_session -> nx_secure_tls_protocol_version_override == 0)
{
tls_session -> nx_secure_tls_1_3 = NX_FALSE;
#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION
tls_session -> nx_secure_tls_renegotation_enabled = NX_TRUE;
#endif
}if (tls_session -> nx_secure_tls_protocol_version_override == 0) { ... }
else
{
return(NX_SECURE_TLS_UNSUPPORTED_TLS_VERSION);
}else { ... }
}if (supported_version != NX_SECURE_TLS_VERSION_TLS_1_3) { ... }
else
{
if (tls_session -> nx_secure_tls_protocol_version != NX_SECURE_TLS_VERSION_TLS_1_2)
{
return(NX_SECURE_TLS_UNKNOWN_TLS_VERSION);
}if (tls_session -> nx_secure_tls_protocol_version != NX_SECURE_TLS_VERSION_TLS_1_2) { ... }
}else { ... }
}if (tls_session->nx_secure_tls_1_3) { ... }
/* ... */#endif
return(status);/* ... */
#else
NX_PARAMETER_NOT_USED(tls_session);
NX_PARAMETER_NOT_USED(packet_buffer);
NX_PARAMETER_NOT_USED(message_length);
NX_PARAMETER_NOT_USED(extensions);
NX_PARAMETER_NOT_USED(num_extensions);
return(NX_SECURE_TLS_UNEXPECTED_MESSAGE);/* ... */
#endif
}{ ... }
#ifndef NX_SECURE_TLS_CLIENT_DISABLED
...
#ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
static UINT _nx_secure_tls_proc_serverhello_ecc_point_formats(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length)
{
UINT status;
UINT i;
UCHAR ec_point_formats_length;
UINT offset;
*extension_length = (USHORT)((*packet_buffer << 8) + packet_buffer[1] + 2);
if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL)
{
return(NX_SECURE_TLS_UNKNOWN_CIPHERSUITE);
}if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL) { ... }
offset = 2;
if (*extension_length > message_length || *extension_length < 3)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (*extension_length > message_length || *extension_length < 3) { ... }
ec_point_formats_length = packet_buffer[offset];
offset += 1;
if (offset + ec_point_formats_length != *extension_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (offset + ec_point_formats_length != *extension_length) { ... }
if (tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECJPAKE)
{
status = NX_SECURE_TLS_UNSUPPORTED_CIPHER;
for (i = 0; i < ec_point_formats_length; ++i)
{
if (packet_buffer[offset + i] == 0x0)
{
status = NX_SUCCESS;
break;
}if (packet_buffer[offset + i] == 0x0) { ... }
}for (i = 0; i < ec_point_formats_length; ++i) { ... }
if (status != NX_SUCCESS)
{
return(status);
}if (status != NX_SUCCESS) { ... }
}if (tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECJPAKE) { ... }
return(NX_SUCCESS);
}_nx_secure_tls_proc_serverhello_ecc_point_formats (NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, USHORT *extension_length, UINT message_length) { ... }
/* ... */#endif
...
...
#ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE
static UINT _nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length)
{
UINT status;
NX_CRYPTO_METHOD *crypto_method;
*extension_length = (USHORT)((*packet_buffer << 8) + packet_buffer[1] + 2);
if (*extension_length > message_length || *extension_length <= 2)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (*extension_length > message_length || *extension_length <= 2) { ... }
if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL)
{
return(NX_SECURE_TLS_UNKNOWN_CIPHERSUITE);
}if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL) { ... }
if (tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECJPAKE)
{
crypto_method = (NX_CRYPTO_METHOD*)tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth;
status = crypto_method -> nx_crypto_operation(NX_CRYPTO_ECJPAKE_SERVER_HELLO_PROCESS,
tls_session -> nx_secure_public_auth_handler,
crypto_method,
NX_NULL, 0,
&packet_buffer[2],
(ULONG)(*extension_length - 2),
NX_NULL, NX_NULL, 0,
tls_session -> nx_secure_public_auth_metadata_area,
tls_session -> nx_secure_public_auth_metadata_size,
NX_NULL, NX_NULL);
if (status)
{
return(status);
}if (status) { ... }
}if (tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECJPAKE) { ... }
return(NX_SUCCESS);
}_nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair (NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, USHORT *extension_length, UINT message_length) { ... }
/* ... */#endif
...
...
#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION
static UINT _nx_secure_tls_proc_serverhello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length)
{
ULONG offset;
UCHAR renegotiated_connection_length;
USHORT parsed_length;
INT compare_value;
/* ... */
/* ... */
parsed_length = (USHORT)((packet_buffer[0] << 8) + packet_buffer[1]);
*extension_length = (USHORT)(2 + parsed_length);
offset = 2;
if (*extension_length > message_length || *extension_length < 3)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (*extension_length > message_length || *extension_length < 3) { ... }
renegotiated_connection_length = packet_buffer[offset];
offset++;
if (offset + renegotiated_connection_length > *extension_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (offset + renegotiated_connection_length > *extension_length) { ... }
if (renegotiated_connection_length)
{
if (!tls_session -> nx_secure_tls_local_session_active || !tls_session -> nx_secure_tls_remote_session_active)
{
return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR);
}if (!tls_session -> nx_secure_tls_local_session_active || !tls_session -> nx_secure_tls_remote_session_active) { ... }
if(!tls_session -> nx_secure_tls_secure_renegotiation)
{
return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR);
}if (!tls_session -> nx_secure_tls_secure_renegotiation) { ... }
/* ... */
if (renegotiated_connection_length != (2 * NX_SECURE_TLS_FINISHED_HASH_SIZE))
{
return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR);
}if (renegotiated_connection_length != (2 * NX_SECURE_TLS_FINISHED_HASH_SIZE)) { ... }
compare_value = NX_SECURE_MEMCMP(&packet_buffer[offset], tls_session -> nx_secure_tls_local_verify_data, NX_SECURE_TLS_FINISHED_HASH_SIZE);
if (compare_value)
{
return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR);
}if (compare_value) { ... }
offset += NX_SECURE_TLS_FINISHED_HASH_SIZE;
compare_value = NX_SECURE_MEMCMP(&packet_buffer[offset], tls_session -> nx_secure_tls_remote_verify_data, NX_SECURE_TLS_FINISHED_HASH_SIZE);
if (compare_value)
{
return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR);
}if (compare_value) { ... }
tls_session -> nx_secure_tls_secure_renegotiation_verified = NX_TRUE;
}if (renegotiated_connection_length) { ... }
else
{
if ((parsed_length != 1) || (tls_session -> nx_secure_tls_local_session_active))
{
return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR);
}if ((parsed_length != 1) || (tls_session -> nx_secure_tls_local_session_active)) { ... }
tls_session -> nx_secure_tls_secure_renegotiation = NX_TRUE;
}else { ... }
return(NX_SUCCESS);
}{ ... }
/* ... */#endif
...
...
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
extern NX_CRYPTO_METHOD crypto_method_ecdhe;
static UINT _nx_secure_tls_proc_serverhello_keyshare_extension(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *extension_length, UINT message_length)
{
UINT status;
UINT i;
ULONG offset;
USHORT key_group;
USHORT key_length;
UCHAR legacy_form;
NX_SECURE_TLS_ECDHE_HANDSHAKE_DATA *ecc_key_data;
UCHAR *pubkey;
UCHAR *private_key;
UINT private_key_length;
NX_CRYPTO_EXTENDED_OUTPUT extended_output;
NX_CRYPTO_METHOD *ecdhe_method;
const NX_CRYPTO_METHOD *curve_method;
VOID *handler = NX_NULL;
NX_SECURE_TLS_ECC *ecc_info;
/* ... */
offset = 0;
*extension_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset = (USHORT)(offset + 2);
if (offset + *extension_length > message_length || *extension_length < 2)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (offset + *extension_length > message_length || *extension_length < 2) { ... }
key_group = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset = (USHORT)(offset + 2);
ecc_info = &(tls_session -> nx_secure_tls_ecc);
key_group = (USHORT)((ULONG)key_group | NX_CRYPTO_EC_MASK);
for (i = 0; i < ecc_info -> nx_secure_tls_ecc_supported_groups_count; i++)
{
if(key_group != tls_session->nx_secure_tls_key_material.nx_secure_tls_ecc_key_data[i].nx_secure_tls_ecdhe_named_curve)
{
continue;
}if (key_group != tls_session->nx_secure_tls_key_material.nx_secure_tls_ecc_key_data[i].nx_secure_tls_ecdhe_named_curve) { ... }
tls_session -> nx_secure_tls_key_material.nx_secure_tls_ecc_key_data_selected = i;
if (tls_session -> nx_secure_tls_client_state == NX_SECURE_TLS_CLIENT_STATE_HELLO_RETRY)
{
return(NX_SUCCESS);
}if (tls_session -> nx_secure_tls_client_state == NX_SECURE_TLS_CLIENT_STATE_HELLO_RETRY) { ... }
ecc_key_data = tls_session->nx_secure_tls_key_material.nx_secure_tls_ecc_key_data;
if (*extension_length < 4)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (*extension_length < 4) { ... }
key_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
if (offset + key_length > *extension_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (offset + key_length > *extension_length) { ... }
offset = (USHORT)(offset + 2);
/* ... */
legacy_form = packet_buffer[offset];
if(legacy_form != 0x4)
{
return(NX_SECURE_TLS_BAD_SERVERHELLO_KEYSHARE);
}if (legacy_form != 0x4) { ... }
pubkey = &packet_buffer[offset];
_nx_secure_tls_find_curve_method(tls_session, key_group, &curve_method, NX_NULL);
if (curve_method == NX_NULL)
{
return(NX_SECURE_TLS_MISSING_CRYPTO_ROUTINE);
}if (curve_method == NX_NULL) { ... }
ecdhe_method = &crypto_method_ecdhe;
if (ecdhe_method -> nx_crypto_operation == NX_NULL )
{
return(NX_SECURE_TLS_MISSING_CRYPTO_ROUTINE);
}if (ecdhe_method -> nx_crypto_operation == NX_NULL) { ... }
if (ecdhe_method -> nx_crypto_init != NX_NULL)
{
status = ecdhe_method -> nx_crypto_init(ecdhe_method,
NX_NULL,
0,
&handler,
tls_session -> nx_secure_public_cipher_metadata_area,
tls_session -> nx_secure_public_cipher_metadata_size);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
}if (ecdhe_method -> nx_crypto_init != NX_NULL) { ... }
status = ecdhe_method -> nx_crypto_operation(NX_CRYPTO_EC_CURVE_SET, handler,
ecdhe_method, NX_NULL, 0,
(UCHAR *)curve_method, sizeof(NX_CRYPTO_METHOD *), NX_NULL,
NX_NULL, 0,
tls_session -> nx_secure_public_cipher_metadata_area,
tls_session -> nx_secure_public_cipher_metadata_size,
NX_NULL, NX_NULL);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
private_key = &ecc_key_data[i].nx_secure_tls_ecdhe_private_key[0];
private_key_length = ecc_key_data[i].nx_secure_tls_ecdhe_private_key_length;
status = ecdhe_method -> nx_crypto_operation(NX_CRYPTO_DH_KEY_PAIR_IMPORT, handler,
(NX_CRYPTO_METHOD*)ecdhe_method,
private_key, private_key_length << 3,
NX_NULL, 0, NX_NULL,
NX_NULL,
0,
tls_session -> nx_secure_public_cipher_metadata_area,
tls_session -> nx_secure_public_cipher_metadata_size,
NX_NULL, NX_NULL);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
extended_output.nx_crypto_extended_output_data = tls_session -> nx_secure_tls_key_material.nx_secure_tls_pre_master_secret;
extended_output.nx_crypto_extended_output_length_in_byte = sizeof(tls_session -> nx_secure_tls_key_material.nx_secure_tls_pre_master_secret);
extended_output.nx_crypto_extended_output_actual_size = 0;
status = ecdhe_method -> nx_crypto_operation(NX_CRYPTO_DH_CALCULATE, handler,
ecdhe_method, NX_NULL, 0,
pubkey, key_length, NX_NULL,
(UCHAR *)&extended_output,
sizeof(extended_output),
tls_session -> nx_secure_public_cipher_metadata_area,
tls_session -> nx_secure_public_cipher_metadata_size,
NX_NULL, NX_NULL);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
tls_session -> nx_secure_tls_key_material.nx_secure_tls_pre_master_secret_size = extended_output.nx_crypto_extended_output_actual_size;
if (ecdhe_method -> nx_crypto_cleanup)
{
status = ecdhe_method -> nx_crypto_cleanup(tls_session -> nx_secure_public_cipher_metadata_area);
}if (ecdhe_method -> nx_crypto_cleanup) { ... }
return(status);
}for (i = 0; i < ecc_info -> nx_secure_tls_ecc_supported_groups_count; i++) { ... }
return(NX_SECURE_TLS_BAD_SERVERHELLO_KEYSHARE);
}_nx_secure_tls_proc_serverhello_keyshare_extension (NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, USHORT *extension_length, UINT message_length) { ... }
...
static UINT _nx_secure_tls_proc_serverhello_supported_versions_extension(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *supported_version,
USHORT *extension_length, UINT message_length)
{
ULONG offset;
NX_PARAMETER_NOT_USED(tls_session);
/* ... */
/* ... */
offset = 0;
*extension_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset = (USHORT)(offset + 2);
if (offset + *extension_length > message_length || *extension_length != 2)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}if (offset + *extension_length > message_length || *extension_length != 2) { ... }
*supported_version = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
if (*supported_version == NX_SECURE_TLS_VERSION_TLS_1_3)
{
return(NX_SUCCESS);
}if (*supported_version == NX_SECURE_TLS_VERSION_TLS_1_3) { ... }
return(NX_SECURE_TLS_UNKNOWN_TLS_VERSION);
}_nx_secure_tls_proc_serverhello_supported_versions_extension (NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, USHORT *supported_version, USHORT *extension_length, UINT message_length) { ... }
/* ... */#endif
/* ... */
#endif