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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC
#include <openssl/ssl.h>
#include "../crypto/test/test_util.h"
#include "ssl_common_test.h"
BSSL_NAMESPACE_BEGIN
struct HybridHandshakeTest {
// The curves rule string to apply to the client
const char *client_rule;
// TLS version that the client is configured with
uint16_t client_version;
// The curves rule string to apply to the server
const char *server_rule;
// TLS version that the server is configured with
uint16_t server_version;
// The group that is expected to be negotiated
uint16_t expected_group;
// Is a HelloRetryRequest expected?
bool is_hrr_expected;
};
static const HybridHandshakeTest kHybridHandshakeTests[] = {
// The corresponding hybrid group should be negotiated when client
// and server support only that group
{
"X25519Kyber768Draft00",
TLS1_3_VERSION,
"X25519Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_X25519_KYBER768_DRAFT00,
false,
},
{
"SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_KYBER768_DRAFT00,
false,
},
// The client's preferred hybrid group should be negotiated when also
// supported by the server, even if the server "prefers"/supports other
// groups.
{
"X25519Kyber768Draft00:x25519",
TLS1_3_VERSION,
"x25519:prime256v1:X25519Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_X25519_KYBER768_DRAFT00,
false,
},
{
"X25519Kyber768Draft00:x25519",
TLS1_3_VERSION,
"X25519Kyber768Draft00:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519_KYBER768_DRAFT00,
false,
},
{
"SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"X25519Kyber768Draft00:secp384r1:x25519:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_KYBER768_DRAFT00,
false,
},
// The client lists PQ/hybrid groups as both first and second preferences.
// The key share logic is implemented such that the client will always
// attempt to send one hybrid key share and one classical key share.
// Therefore, the client will send key shares [SecP256r1Kyber768Draft00,
// x25519],
// skipping X25519Kyber768Draft00, and the server will choose to negotiate
// x25519 since it is the only mutually supported group.
{
"SecP256r1Kyber768Draft00:X25519Kyber768Draft00:x25519",
TLS1_3_VERSION,
"secp384r1:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
// The client will send key shares [x25519, SecP256r1Kyber768Draft00].
// The server will negotiate SecP256r1Kyber768Draft00 since it is the only
// mutually supported group.
{
"x25519:secp384r1:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"SecP256r1Kyber768Draft00:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_KYBER768_DRAFT00,
false,
},
// The client will send key shares [x25519, SecP256r1Kyber768Draft00]. The
// server will negotiate x25519 since the client listed it as its first
// preference, even though it supports SecP256r1Kyber768Draft00.
{
"x25519:prime256v1:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"prime256v1:x25519:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
// The client will send key shares [SecP256r1Kyber768Draft00, x25519].
// The server will negotiate SecP256r1Kyber768Draft00 since the client
// listed
// it as its first preference.
{
"SecP256r1Kyber768Draft00:x25519:prime256v1",
TLS1_3_VERSION,
"prime256v1:x25519:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_KYBER768_DRAFT00,
false,
},
// In the supported_groups extension, the client will indicate its
// preferences, in order, as [SecP256r1Kyber768Draft00,
// X25519Kyber768Draft00,
// x25519, prime256v1]. From those groups, it will send key shares
// [SecP256r1Kyber768Draft00, x25519]. The server supports, and receives a
// key share for, x25519. However, when selecting a mutually supported group
// to negotiate, the server recognizes that the client prefers
// X25519Kyber768Draft00 over x25519. Since the server also supports
// X25519Kyber768Draft00, but did not receive a key share for it, it will
// select it and send an HRR. This ensures that the client's highest
// preference group will be negotiated, even at the expense of an additional
// round-trip.
//
// In our SSL implementation, this situation is unique to the case where the
// client supports both ECC and hybrid/PQ. When sending key shares, the
// client will send at most two key shares in one of the following ways:
// (a) one ECC key share - if the client supports only ECC;
// (b) one PQ key share - if the client supports only PQ;
// (c) one ECC and one PQ key share - if the client supports ECC and PQ.
//
// One of the above cases will be true irrespective of how many groups
// the client supports. If, say, the client supports four ECC groups
// and zero PQ groups, it will still only send a single ECC share. In cases
// (a) and (b), either the server supports that group and chooses to
// negotiate it, or it doesn't support it and sends an HRR. Case (c) is the
// only case where the server might receive a key share for a mutually
// supported group, but chooses to respect the client's preference order
// defined in the supported_groups extension at the expense of an additional
// round-trip.
{
"SecP256r1Kyber768Draft00:X25519Kyber768Draft00:x25519:prime256v1",
TLS1_3_VERSION,
"X25519Kyber768Draft00:prime256v1:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519_KYBER768_DRAFT00,
true,
},
// Like the previous case, but the client's prioritization of ECC and PQ
// is inverted.
{
"x25519:prime256v1:SecP256r1Kyber768Draft00:X25519Kyber768Draft00",
TLS1_3_VERSION,
"X25519Kyber768Draft00:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
true,
},
// The client will send key shares [SecP256r1Kyber768Draft00, x25519]. The
// server will negotiate X25519Kyber768Draft00 after an HRR.
{
"SecP256r1Kyber768Draft00:X25519Kyber768Draft00:x25519:prime256v1",
TLS1_3_VERSION,
"X25519Kyber768Draft00:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_X25519_KYBER768_DRAFT00,
true,
},
// EC should be negotiated when client prefers EC, or server does not
// support hybrid
{
"X25519Kyber768Draft00:x25519",
TLS1_3_VERSION,
"x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
{
"x25519:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
{
"prime256v1:X25519Kyber768Draft00",
TLS1_3_VERSION,
"X25519Kyber768Draft00:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
false,
},
{
"prime256v1:x25519:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"x25519:prime256v1:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
false,
},
// EC should be negotiated, after a HelloRetryRequest, if the server
// supports only curves for which it did not initially receive a key share
{
"X25519Kyber768Draft00:x25519:SecP256r1Kyber768Draft00:prime256v1",
TLS1_3_VERSION,
"prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
true,
},
{
"X25519Kyber768Draft00:SecP256r1Kyber768Draft00:prime256v1:x25519",
TLS1_3_VERSION,
"secp224r1:secp384r1:secp521r1:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
true,
},
// Hybrid should be negotiated, after a HelloRetryRequest, if the server
// supports only curves for which it did not initially receive a key share
{
"x25519:prime256v1:SecP256r1Kyber768Draft00:X25519Kyber768Draft00",
TLS1_3_VERSION,
"secp224r1:X25519Kyber768Draft00:secp521r1",
TLS1_3_VERSION,
SSL_GROUP_X25519_KYBER768_DRAFT00,
true,
},
{
"X25519Kyber768Draft00:x25519:prime256v1:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_KYBER768_DRAFT00,
true,
},
// If there is no overlap between client and server groups,
// the handshake should fail
{
"SecP256r1Kyber768Draft00:X25519Kyber768Draft00:secp384r1",
TLS1_3_VERSION,
"prime256v1:x25519",
TLS1_3_VERSION,
0,
false,
},
{
"secp384r1:SecP256r1Kyber768Draft00:X25519Kyber768Draft00",
TLS1_3_VERSION,
"prime256v1:x25519",
TLS1_3_VERSION,
0,
false,
},
{
"secp384r1:SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"prime256v1:x25519:X25519Kyber768Draft00",
TLS1_3_VERSION,
0,
false,
},
{
"SecP256r1Kyber768Draft00",
TLS1_3_VERSION,
"X25519Kyber768Draft00",
TLS1_3_VERSION,
0,
false,
},
// If the client supports hybrid TLS 1.3, but the server
// only supports TLS 1.2, then TLS 1.2 EC should be negotiated.
{
"SecP256r1Kyber768Draft00:prime256v1",
TLS1_3_VERSION,
"prime256v1:x25519",
TLS1_2_VERSION,
SSL_GROUP_SECP256R1,
false,
},
// Same as above, but server also has SecP256r1Kyber768Draft00 in it's
// supported list, but can't use it since TLS 1.3 is the minimum version
// that
// supports PQ.
{
"SecP256r1Kyber768Draft00:prime256v1",
TLS1_3_VERSION,
"SecP256r1Kyber768Draft00:prime256v1:x25519",
TLS1_2_VERSION,
SSL_GROUP_SECP256R1,
false,
},
// If the client configures the curve list to include a hybrid
// curve, then initiates a 1.2 handshake, it will not advertise
// hybrid groups because hybrid is not supported for 1.2. So
// a 1.2 EC handshake will be negotiated (even if the server
// supports 1.3 with corresponding hybrid group).
{
"SecP256r1Kyber768Draft00:x25519",
TLS1_2_VERSION,
"SecP256r1Kyber768Draft00:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
{
"SecP256r1Kyber768Draft00:prime256v1",
TLS1_2_VERSION,
"prime256v1:x25519",
TLS1_2_VERSION,
SSL_GROUP_SECP256R1,
false,
},
// The corresponding hybrid group should be negotiated when client
// and server support only that group
{
"X25519MLKEM768",
TLS1_3_VERSION,
"X25519MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_X25519_MLKEM768,
false,
},
{
"SecP256r1MLKEM768",
TLS1_3_VERSION,
"SecP256r1MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_MLKEM768,
false,
},
{
"SecP384r1MLKEM1024",
TLS1_3_VERSION,
"SecP384r1MLKEM1024",
TLS1_3_VERSION,
SSL_GROUP_SECP384R1_MLKEM1024,
false,
},
// Pure MLKEM at all key sizes
{
"MLKEM512",
TLS1_3_VERSION,
"MLKEM512",
TLS1_3_VERSION,
SSL_GROUP_MLKEM512,
false,
},
{
"MLKEM768",
TLS1_3_VERSION,
"MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_MLKEM768,
false,
},
{
"MLKEM1024",
TLS1_3_VERSION,
"MLKEM1024",
TLS1_3_VERSION,
SSL_GROUP_MLKEM1024,
false,
},
// The client's preferred hybrid group should be negotiated when also
// supported by the server, even if the server "prefers"/supports other
// groups.
{
"X25519MLKEM768:x25519",
TLS1_3_VERSION,
"x25519:prime256v1:X25519MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_X25519_MLKEM768,
false,
},
{
"X25519MLKEM768:x25519",
TLS1_3_VERSION,
"X25519MLKEM768:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519_MLKEM768,
false,
},
{
"SecP256r1MLKEM768",
TLS1_3_VERSION,
"X25519MLKEM768:secp384r1:x25519:SecP256r1MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_MLKEM768,
false,
},
{
"X25519MLKEM768:SecP256r1MLKEM768:SecP384r1MLKEM1024",
TLS1_3_VERSION,
"SecP384r1MLKEM1024:SecP256r1MLKEM768:X25519MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_X25519_MLKEM768,
false,
},
{
"SecP384r1MLKEM1024:SecP256r1MLKEM768:X25519MLKEM768",
TLS1_3_VERSION,
"X25519MLKEM768:SecP256r1MLKEM768:SecP384r1MLKEM1024",
TLS1_3_VERSION,
SSL_GROUP_SECP384R1_MLKEM1024,
false,
},
// The client lists PQ/hybrid groups as both first and second preferences.
// The key share logic is implemented such that the client will always
// attempt to send one hybrid key share and one classical key share.
// Therefore, the client will send key shares [SecP256r1MLKEM768, x25519],
// skipping X25519MLKEM768, and the server will choose to negotiate
// x25519 since it is the only mutually supported group.
{
"SecP256r1MLKEM768:X25519MLKEM768:x25519",
TLS1_3_VERSION,
"secp384r1:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
// The client will send key shares [x25519, SecP256r1MLKEM768].
// The server will negotiate SecP256r1MLKEM768 since it is the only
// mutually supported group.
{
"x25519:secp384r1:SecP256r1MLKEM768",
TLS1_3_VERSION,
"SecP256r1MLKEM768:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_MLKEM768,
false,
},
// The client will send key shares [x25519, SecP256r1MLKEM768]. The
// server will negotiate x25519 since the client listed it as its first
// preference, even though it supports SecP256r1MLKEM768.
{
"x25519:prime256v1:SecP256r1MLKEM768",
TLS1_3_VERSION,
"prime256v1:x25519:SecP256r1MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
// The client will send key shares [SecP256r1MLKEM768, x25519].
// The server will negotiate SecP256r1MLKEM768 since the client listed
// it as its first preference.
{
"SecP256r1MLKEM768:x25519:prime256v1",
TLS1_3_VERSION,
"prime256v1:x25519:SecP256r1MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_MLKEM768,
false,
},
// In the supported_groups extension, the client will indicate its
// preferences, in order, as [SecP256r1MLKEM768, X25519MLKEM768,
// x25519, prime256v1]. From those groups, it will send key shares
// [SecP256r1MLKEM768, x25519]. The server supports, and receives a
// key share for, x25519. However, when selecting a mutually supported group
// to negotiate, the server recognizes that the client prefers
// X25519MLKEM768 over x25519. Since the server also supports
// X25519MLKEM768, but did not receive a key share for it, it will
// select it and send an HRR. This ensures that the client's highest
// preference group will be negotiated, even at the expense of an additional
// round-trip.
//
// In our SSL implementation, this situation is unique to the case where the
// client supports both ECC and hybrid/PQ. When sending key shares, the
// client will send at most two key shares in one of the following ways:
// (a) one ECC key share - if the client supports only ECC;
// (b) one PQ key share - if the client supports only PQ;
// (c) one ECC and one PQ key share - if the client supports ECC and PQ.
//
// One of the above cases will be true irrespective of how many groups
// the client supports. If, say, the client supports four ECC groups
// and zero PQ groups, it will still only send a single ECC share. In cases
// (a) and (b), either the server supports that group and chooses to
// negotiate it, or it doesn't support it and sends an HRR. Case (c) is the
// only case where the server might receive a key share for a mutually
// supported group, but chooses to respect the client's preference order
// defined in the supported_groups extension at the expense of an additional
// round-trip.
{
"SecP256r1MLKEM768:X25519MLKEM768:x25519:prime256v1",
TLS1_3_VERSION,
"X25519MLKEM768:prime256v1:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519_MLKEM768,
true,
},
// Like the previous case, but the client's prioritization of ECC and PQ
// is inverted.
{
"x25519:prime256v1:SecP256r1MLKEM768:X25519MLKEM768",
TLS1_3_VERSION,
"X25519MLKEM768:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
true,
},
// The client will send key shares [SecP256r1MLKEM768, x25519]. The
// server will negotiate X25519MLKEM768 after an HRR.
{
"SecP256r1MLKEM768:X25519MLKEM768:x25519:prime256v1",
TLS1_3_VERSION,
"X25519MLKEM768:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_X25519_MLKEM768,
true,
},
// EC should be negotiated when client prefers EC, or server does not
// support hybrid
{
"X25519MLKEM768:x25519",
TLS1_3_VERSION,
"x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
{
"x25519:SecP256r1MLKEM768",
TLS1_3_VERSION,
"x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
{
"prime256v1:X25519MLKEM768",
TLS1_3_VERSION,
"X25519MLKEM768:prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
false,
},
{
"prime256v1:x25519:SecP256r1MLKEM768",
TLS1_3_VERSION,
"x25519:prime256v1:SecP256r1MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
false,
},
// EC should be negotiated, after a HelloRetryRequest, if the server
// supports only curves for which it did not initially receive a key share
{
"X25519MLKEM768:x25519:SecP256r1MLKEM768:prime256v1",
TLS1_3_VERSION,
"prime256v1",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1,
true,
},
{
"X25519MLKEM768:SecP256r1MLKEM768:prime256v1:x25519",
TLS1_3_VERSION,
"secp224r1:secp384r1:secp521r1:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
true,
},
// Hybrid should be negotiated, after a HelloRetryRequest, if the server
// supports only curves for which it did not initially receive a key share
{
"x25519:prime256v1:SecP256r1MLKEM768:X25519MLKEM768",
TLS1_3_VERSION,
"secp224r1:X25519MLKEM768:secp521r1",
TLS1_3_VERSION,
SSL_GROUP_X25519_MLKEM768,
true,
},
{
"X25519MLKEM768:x25519:prime256v1:SecP256r1MLKEM768",
TLS1_3_VERSION,
"SecP256r1MLKEM768",
TLS1_3_VERSION,
SSL_GROUP_SECP256R1_MLKEM768,
true,
},
// If there is no overlap between client and server groups,
// the handshake should fail
{
"SecP256r1MLKEM768:X25519MLKEM768:secp384r1",
TLS1_3_VERSION,
"prime256v1:x25519",
TLS1_3_VERSION,
0,
false,
},
{
"secp384r1:SecP256r1MLKEM768:X25519MLKEM768",
TLS1_3_VERSION,
"prime256v1:x25519",
TLS1_3_VERSION,
0,
false,
},
{
"secp384r1:SecP256r1MLKEM768",
TLS1_3_VERSION,
"prime256v1:x25519:X25519MLKEM768",
TLS1_3_VERSION,
0,
false,
},
{
"SecP256r1MLKEM768",
TLS1_3_VERSION,
"X25519MLKEM768",
TLS1_3_VERSION,
0,
false,
},
// If the client supports hybrid TLS 1.3, but the server
// only supports TLS 1.2, then TLS 1.2 EC should be negotiated.
{
"SecP256r1MLKEM768:prime256v1",
TLS1_3_VERSION,
"prime256v1:x25519",
TLS1_2_VERSION,
SSL_GROUP_SECP256R1,
false,
},
// Same as above, but server also has SecP256r1MLKEM768 in it's
// supported list, but can't use it since TLS 1.3 is the minimum version
// that
// supports PQ.
{
"SecP256r1MLKEM768:prime256v1",
TLS1_3_VERSION,
"SecP256r1MLKEM768:prime256v1:x25519",
TLS1_2_VERSION,
SSL_GROUP_SECP256R1,
false,
},
// If the client configures the curve list to include a hybrid
// curve, then initiates a 1.2 handshake, it will not advertise
// hybrid groups because hybrid is not supported for 1.2. So
// a 1.2 EC handshake will be negotiated (even if the server
// supports 1.3 with corresponding hybrid group).
{
"SecP256r1MLKEM768:x25519",
TLS1_2_VERSION,
"SecP256r1MLKEM768:x25519",
TLS1_3_VERSION,
SSL_GROUP_X25519,
false,
},
{
"SecP256r1MLKEM768:prime256v1",
TLS1_2_VERSION,
"prime256v1:x25519",
TLS1_2_VERSION,
SSL_GROUP_SECP256R1,
false,
},
};
class PerformHybridHandshakeTest
: public testing::TestWithParam<HybridHandshakeTest> {};
INSTANTIATE_TEST_SUITE_P(PerformHybridHandshakeTests,
PerformHybridHandshakeTest,
testing::ValuesIn(kHybridHandshakeTests));
// This test runs through an overall handshake flow for all of the cases
// defined in kHybridHandshakeTests. This test runs through both positive and
// negative cases; refer to the comments inline in kHybridHandshakeTests for
// specifics about each test case.
TEST_P(PerformHybridHandshakeTest, PerformHybridHandshake) {
HybridHandshakeTest t = GetParam();
// Set up client and server with test case parameters
bssl::UniquePtr<SSL_CTX> client_ctx(SSL_CTX_new(TLS_method()));
ASSERT_TRUE(client_ctx);
ASSERT_TRUE(SSL_CTX_set1_curves_list(client_ctx.get(), t.client_rule));
ASSERT_TRUE(
SSL_CTX_set_max_proto_version(client_ctx.get(), t.client_version));
bssl::UniquePtr<SSL_CTX> server_ctx =
CreateContextWithTestCertificate(TLS_method());
ASSERT_TRUE(server_ctx);
ASSERT_TRUE(SSL_CTX_set1_curves_list(server_ctx.get(), t.server_rule));
ASSERT_TRUE(
SSL_CTX_set_max_proto_version(server_ctx.get(), t.server_version));
bssl::UniquePtr<SSL> client, server;
ASSERT_TRUE(CreateClientAndServer(&client, &server, client_ctx.get(),
server_ctx.get()));
if (t.expected_group != 0) {
// In this case, assert that the handshake completes as expected.
ASSERT_TRUE(CompleteHandshakes(client.get(), server.get()));
SSL_SESSION *client_session = SSL_get_session(client.get());
ASSERT_TRUE(client_session);
EXPECT_EQ(t.expected_group, client_session->group_id);
EXPECT_EQ(t.is_hrr_expected, SSL_used_hello_retry_request(client.get()));
EXPECT_EQ(std::min(t.client_version, t.server_version),
client_session->ssl_version);
SSL_SESSION *server_session = SSL_get_session(server.get());
ASSERT_TRUE(server_session);
EXPECT_EQ(t.expected_group, server_session->group_id);
EXPECT_EQ(t.is_hrr_expected, SSL_used_hello_retry_request(server.get()));
EXPECT_EQ(std::min(t.client_version, t.server_version),
server_session->ssl_version);
} else {
// In this case, we expect the handshake to fail because client and
// server configurations are not compatible.
ASSERT_FALSE(CompleteHandshakes(client.get(), server.get()));
ASSERT_FALSE(client.get()->s3->initial_handshake_complete);
EXPECT_EQ(t.is_hrr_expected, SSL_used_hello_retry_request(client.get()));
ASSERT_FALSE(server.get()->s3->initial_handshake_complete);
EXPECT_EQ(t.is_hrr_expected, SSL_used_hello_retry_request(server.get()));
}
}
BSSL_NAMESPACE_END