Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_tls.h"
...
_nx_secure_tls_process_serverhello_extensions(NX_SECURE_TLS_SESSION *, UCHAR *, UINT, NX_SECURE_TLS_HELLO_EXTENSION *, UINT *)
...
...
...
...
...
...
_nx_secure_tls_proc_serverhello_sec_reneg_extension(NX_SECURE_TLS_SESSION *, UCHAR *, USHORT *, UINT)
...
...
Files
loading...
CodeScopeSTM32 Libraries and Samplesnetxduonx_secure/src/nx_secure_tls_process_serverhello_extensions.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
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
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Secure Component */ /** */ /** Transport Layer Security (TLS) */ /** */... /**************************************************************************/ /**************************************************************************/ #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 /* NX_SECURE_TLS_CLIENT_DISABLED */ ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_serverhello_extensions PORTABLE C */ /* 6.1.9 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function processes any extensions included in an incoming */ /* ServerHello message from a remote host. */ /* */ /* INPUT */ /* */ /* tls_session TLS control block */ /* packet_buffer Pointer to message data */ /* message_length Length of message data (bytes)*/ /* extensions Extensions for output */ /* num_extensions Number of extensions */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _nx_secure_tls_proc_serverhello_ecc_point_formats */ /* Process ServerHello ECC */ /* point formats extension */ /* _nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair */ /* Process ServerHello ECJPAKE */ /* key kp pair extension */ /* _nx_secure_tls_proc_serverhello_sec_reneg_extension */ /* Process ServerHello */ /* Renegotiation extension */ /* */ /* CALLED BY */ /* */ /* _nx_secure_tls_server_handshake Process ServerHello */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* fixed renegotiation bug, */ /* resulting in version 6.1 */ /* 10-15-2021 Timothy Stapko Modified comment(s), fixed */ /* TLS 1.3 compilation issue, */ /* resulting in version 6.1.9 */ /* */... /**************************************************************************/ 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; /* Process extensions until we run out. */ while (offset < message_length) { /* Make sure there are at least 4 bytes available so we can read extension_id and extension_length. *//* ... */ if (offset + 4 > message_length) { return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH); }if (offset + 4 > message_length) { ... } /* See what the extension is. */ extension_id = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]); /* Skip type id of extentions. */ offset += 2; /* Parse the extension. */ 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 /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ #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) { /* Process the TLS 1.3 key share extension. */ 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; /* Ignore if not TLS 1.3. */ break;/* ... */ #endifcase NX_SECURE_TLS_EXTENSION_KEY_SHARE: case NX_SECURE_TLS_EXTENSION_SUPPORTED_VERSIONS: if(tls_session->nx_secure_tls_1_3) { /* Process the TLS 1.3 supported_versions extension. */ 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; /* Ignore if not TLS 1.3. */ 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) { ... } /* Store the pointer of cookie. */ /* Note: Cookie data is stored in ServerHello packet buffer. This buffer should not be released or overwrote before Cookie is copied to ClientHello. *//* ... */ 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 /* ECJPAKE ciphersuite extensions. */ 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 /* NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE */ 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: /* These extensions require information to be passed to the application. Save off the extension data in our extensions array to pass along in the hello callback. *//* ... */ 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; /* Added another extension to the array. */ *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: /* Unknown extension, just ignore - TLS supports multiple extensions and the default behavior is to ignore any extensions that we don't know. Assume the next two octets are the length field so we can continue processing. *//* ... */ 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) { ... } /* Adjust our offset with the length of the extension we just parsed. */ offset += extension_length; }while (offset < message_length) { ... } #ifdef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE /* Make sure no ECJPAKE extensions are missing. */ 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 /* NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE */ #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) { /* Server negotiates a version of TLS prior to 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 /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ }if (tls_session -> nx_secure_tls_protocol_version_override == 0) { ... } else { /* Protocol version is overridden to TLS 1.3. */ 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) { /* Server negotiates TLS 1.3 must set the legacy version to 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 /* If Client TLS is disabled and we recieve a server key exchange, error! */ 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 /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_proc_serverhello_ecc_point_formats PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function parses the ec_point_formats extension when ECC */ /* ciphersuites are being used. */ /* */ /* INPUT */ /* */ /* tls_session TLS control block */ /* packet_buffer Outgoing TLS packet buffer */ /* extension_length Length of extension data */ /* message_length Length of message data (bytes)*/ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _nx_secure_tls_process_serverhello_extensions */ /* Process ServerHello extensions*/ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ #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) { ... } /* Skip the length field of this extension. */ 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 Extension. */ 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) { ... } /* Ignore the extension if we are not using ECJPAKE. */ if (tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECJPAKE) { /* Make sure uncompressed (0) format is supported. */ 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) { ... } /* Check for error. */ 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 ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function parses the ecjpake_key_kp_pair extension when ECC */ /* JPAKE ciphersuites are being used. */ /* */ /* INPUT */ /* */ /* tls_session TLS control block */ /* packet_buffer Outgoing TLS packet buffer */ /* extension_length Length of extension data */ /* message_length Length of message data (bytes)*/ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* [nx_crypto_operation] Crypto operation */ /* */ /* CALLED BY */ /* */ /* _nx_secure_tls_process_serverhello_extensions */ /* Process ServerHello extensions*/ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ #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) { ... } /* Ignore the extension if we are not using ECJPAKE. */ 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; /* ecjpake_key_kp_pair Extension. */ 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], /* Skip extension length. */ (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 ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_proc_serverhello_sec_reneg_extension PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function parses the Secure Renegotiation Indication extension */ /* from an incoming ServerHello record.See RFC 5746 for more */ /* information. */ /* */ /* INPUT */ /* */ /* tls_session TLS control block */ /* packet_buffer Outgoing TLS packet buffer */ /* extension_length Length of extension data */ /* message_length Length of message data (bytes)*/ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _nx_secure_tls_process_serverhello_extensions */ /* Process ServerHello extensions*/ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* fixed renegotiation bug, */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ #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; /* Secure Renegotiation Indication Extensions structure (for serverhello): * Initial ServerHello: * | 2 | 2 | 1 | * | Ext Type | Ext Len | Reneg Info Len | * | 0xff01 | 0x0001 | 0x00 | * * Renegotiating ServerHello: * | 2 | 2 | 1 | 12 | 12 | * | Ext Type | Ext Len | Reneg Info Len | client_verify_data | server_verify_data | * | 0xff01 | 0x0019 | 0x18 | | | *//* ... */ /* From RFC 5746: struct { opaque renegotiated_connection<0..255>; } RenegotiationInfo; The contents of this extension are specified as follows. - If this is the initial handshake for a connection, then the "renegotiated_connection" field is of zero length in both the ClientHello and the ServerHello. Thus, the entire encoding of the extension is ff 01 00 01 00. The first two octets represent the extension type, the third and fourth octets the length of the extension itself, and the final octet the zero length byte for the "renegotiated_connection" field. - For ClientHellos that are renegotiating, this field contains the "client_verify_data" specified in Section 3.1. - For ServerHellos that are renegotiating, this field contains the concatenation of client_verify_data and server_verify_data. For current versions of TLS, this will be a 24-byte value (for SSLv3, it will be a 72-byte value). *//* ... */ /* Get the extension length. */ 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) { ... } /* Get the "renegotiated_connection" field. */ 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) { ... } /* See if the client is attempting to renegotiate an established connection. */ if (renegotiated_connection_length) { /* The remote host is attempting a renegotiation - make sure our local session is active and renegotiation is OK. */ if (!tls_session -> nx_secure_tls_local_session_active || !tls_session -> nx_secure_tls_remote_session_active) { /* Remote host is attempting a renegotiation but the server is not currently in a session! */ 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) { ... } /* Check that the received verification data is the expected size. For ServerHello, the size is twice the finished verification hash size because it includes both client and server hashes. *//* ... */ if (renegotiated_connection_length != (2 * NX_SECURE_TLS_FINISHED_HASH_SIZE)) { /* Do not have the right amount of data for comparison. */ return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); }if (renegotiated_connection_length != (2 * NX_SECURE_TLS_FINISHED_HASH_SIZE)) { ... } /* Compare the received verify data to our locally-stored version - start with client (local) verify data. */ 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) { /* Session verify data did not match what we expect - error. */ return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); }if (compare_value) { ... } /* Now compare the remote verify data with what we just received. */ 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) { /* Session verify data did not match what we expect - error. */ return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); }if (compare_value) { ... } /* If we get here, the verification data is good! */ tls_session -> nx_secure_tls_secure_renegotiation_verified = NX_TRUE; }if (renegotiated_connection_length) { ... } else { /* Verify that the extension contains only the initial handshake data - this is a new connection. */ if ((parsed_length != 1) || (tls_session -> nx_secure_tls_local_session_active)) { /* Error - the provided extension length was not expected for an initial handshake. */ return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); }if ((parsed_length != 1) || (tls_session -> nx_secure_tls_local_session_active)) { ... } /* The remote host supports secure renegotiation. */ tls_session -> nx_secure_tls_secure_renegotiation = NX_TRUE; }else { ... } return(NX_SUCCESS); }{ ... } /* ... */#endif ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_proc_serverhello_keyshare_extension PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function parses the Key Share extension introduced in TLS 1.3. */ /* */ /* INPUT */ /* */ /* tls_session TLS control block */ /* packet_buffer Outgoing TLS packet buffer */ /* extension_length Length of extension data */ /* message_length Length of message data (bytes)*/ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _nx_secure_tls_process_serverhello_extensions */ /* Process ServerHello extensions*/ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), update */ /* ECC find curve method, */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ #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; /* Key Share Extension structure (for serverhello): * * ServerHello: * | 2 | 2 | <key len> | * | Key Group | Key Len | Key Exchange value | *//* ... */ offset = 0; /* Extract the extension length. */ *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) { ... } /* Get the key group. It must match one we sent in our ClientHello KeyShare extension. */ key_group = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]); offset = (USHORT)(offset + 2); /* Get our session ECC data. */ ecc_info = &(tls_session -> nx_secure_tls_ecc); /* Check the key group. */ key_group = (USHORT)((ULONG)key_group | NX_CRYPTO_EC_MASK); /* Loop through all supported ECC curves in this session. */ for (i = 0; i < ecc_info -> nx_secure_tls_ecc_supported_groups_count; i++) { /* Find the matchin group in the keys we generated and saved. */ 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) { ... } /* Store selected ECDHE key data index. */ 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) { /* A HelloRetryRequest is received. Done here. */ return(NX_SUCCESS); }if (tls_session -> nx_secure_tls_client_state == NX_SECURE_TLS_CLIENT_STATE_HELLO_RETRY) { ... } /* Got a matching key/curve combo, get a pointer to the selected key data. */ 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) { ... } /* Get the key length. */ 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); /* Extract the legacy form value. NOTE: the form must be included in the ECC calculations below so don't advance the offset! *//* ... */ legacy_form = packet_buffer[offset]; if(legacy_form != 0x4) { /* In TLS 1.3, the only valid form is 0x4. */ return(NX_SECURE_TLS_BAD_SERVERHELLO_KEYSHARE); }if (legacy_form != 0x4) { ... } /* Initialize the remote public key in our session. */ pubkey = &packet_buffer[offset]; /* Get the curve method to initialize the remote public key data. */ _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) { ... } /* Get the ECDHE method we are going to use. */ 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) { ... } /* Initialize the ECDHE method. */ 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) { ... } /* Set the curve we want to use. */ 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) { ... } /* Import the private key to the ECDH context. */ 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) { ... } //tls_session -> nx_secure_tls_key_material.nx_secure_tls_new_key_material_data[0] = (UCHAR)extended_output.nx_crypto_extended_output_actual_size; /* Calculate the final pre_master_secret - the "private key" here is the Pre-Master Secret. */ 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++) { ... } /* If we exhaust the list of ECC curves we sent, the server is doing something weird. */ 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) { ... } /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_proc_serverhello_supported_versions_extension */ /* PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function parses the supported versions extension introduced in */ /* TLS 1.3. */ /* */ /* INPUT */ /* */ /* tls_session TLS control block */ /* packet_buffer Outgoing TLS packet buffer */ /* supported_version Supported version */ /* extension_length Length of extension data */ /* message_length Length of message data (bytes)*/ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _nx_secure_tls_process_serverhello_extensions */ /* Process ServerHello extensions*/ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ 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); /* Supported Versions Extension structure (for serverhello): * * ServerHello: * | 2 | 2 | ... | * | Type | Length | Selected Version | *//* ... */ /* RFC 8446, section 4.2.1, page 39. * A server negotiates TLS 1.3 MUST respond with 0x0304 in supported_versions extension. *//* ... */ offset = 0; /* Extract the extension length. */ *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) { ... } /* Find the selected version 0x0304(TLS 1.3). */ *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 /* NX_SECURE_TLS_CLIENT_DISABLED */