forked from openssl/openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquic_wire_test.c
1641 lines (1287 loc) · 44.1 KB
/
quic_wire_test.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
/*
* Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include "internal/packet.h"
#include "internal/quic_wire.h"
#include "internal/quic_wire_pkt.h"
#include "testutil.h"
struct encode_test_case {
int (*serializer)(WPACKET *pkt);
const unsigned char *expect_buf;
size_t expect_buf_len;
/*
* fail: -1 if not truncated (function should test for success), else number
* of bytes to which the input has been truncated (function should test that
* decoding fails)
*/
int (*deserializer)(PACKET *pkt, ossl_ssize_t fail);
};
/* 1. PADDING */
static int encode_case_1_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_padding(pkt, 3), 1))
return 0;
return 1;
}
static int encode_case_1_dec(PACKET *pkt, ossl_ssize_t fail)
{
if (fail >= 0)
/* No failure modes for padding */
return 1;
if (!TEST_int_eq(ossl_quic_wire_decode_padding(pkt), 3))
return 0;
return 1;
}
static const unsigned char encode_case_1_expect[] = {
0, 0, 0
};
/* 2. PING */
static int encode_case_2_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_ping(pkt), 1))
return 0;
return 1;
}
static int encode_case_2_dec(PACKET *pkt, ossl_ssize_t fail)
{
if (!TEST_int_eq(ossl_quic_wire_decode_frame_ping(pkt), fail < 0))
return 0;
return 1;
}
static const unsigned char encode_case_2_expect[] = {
0x01
};
/* 3. ACK */
static const OSSL_QUIC_ACK_RANGE encode_case_3_ranges[] = {
{ 20, 30 },
{ 0, 10 }
};
static const OSSL_QUIC_FRAME_ACK encode_case_3_f = {
(OSSL_QUIC_ACK_RANGE *)encode_case_3_ranges,
OSSL_NELEM(encode_case_3_ranges),
{ OSSL_TIME_MS },
60, 70, 80, 1
};
static int encode_case_3_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_ack(pkt, 3, &encode_case_3_f), 1))
return 0;
return 1;
}
static int encode_case_3_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_ACK_RANGE ranges[4] = {0};
OSSL_QUIC_FRAME_ACK f = {0};
uint64_t total_ranges = 0, peek_total_ranges = 0;
int ret;
f.ack_ranges = ranges;
f.num_ack_ranges = OSSL_NELEM(ranges);
ret = ossl_quic_wire_peek_frame_ack_num_ranges(pkt, &peek_total_ranges);
if (fail < 0 && !TEST_int_eq(ret, 1))
return 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_ack(pkt, 3, &f, &total_ranges), fail < 0))
return 0;
if (ret == 1 && !TEST_uint64_t_eq(peek_total_ranges, 2))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(total_ranges, peek_total_ranges))
return 0;
if (!TEST_uint64_t_le(f.num_ack_ranges * sizeof(OSSL_QUIC_ACK_RANGE),
SIZE_MAX)
|| !TEST_uint64_t_le(encode_case_3_f.num_ack_ranges
* sizeof(OSSL_QUIC_ACK_RANGE),
SIZE_MAX))
return 0;
if (!TEST_mem_eq(f.ack_ranges,
(size_t)f.num_ack_ranges * sizeof(OSSL_QUIC_ACK_RANGE),
encode_case_3_f.ack_ranges,
(size_t)encode_case_3_f.num_ack_ranges * sizeof(OSSL_QUIC_ACK_RANGE)))
return 0;
if (!TEST_uint64_t_eq(ossl_time2ticks(f.delay_time),
ossl_time2ticks(encode_case_3_f.delay_time)))
return 0;
if (!TEST_true(f.ecn_present))
return 0;
if (!TEST_uint64_t_eq(f.ect0, encode_case_3_f.ect0))
return 0;
if (!TEST_uint64_t_eq(f.ect1, encode_case_3_f.ect1))
return 0;
if (!TEST_uint64_t_eq(f.ecnce, encode_case_3_f.ecnce))
return 0;
return 1;
}
static const unsigned char encode_case_3_expect[] = {
0x03, /* Type */
0x1E, /* Largest Acknowledged */
0x40, 0x7d, /* ACK Delay */
1, /* ACK Range Count */
10, /* First ACK Range */
8, /* Gap */
10, /* Length */
0x3c, /* ECT0 Count */
0x40, 0x46, /* ECT1 Count */
0x40, 0x50, /* ECNCE Count */
};
/* 4. RESET_STREAM */
static const OSSL_QUIC_FRAME_RESET_STREAM encode_case_4_f = {
0x1234, 0x9781, 0x11717
};
static int encode_case_4_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_reset_stream(pkt,
&encode_case_4_f), 1))
return 0;
return 1;
}
static int encode_case_4_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_RESET_STREAM f = {0};
if (!TEST_int_eq(ossl_quic_wire_decode_frame_reset_stream(pkt, &f), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_mem_eq(&f, sizeof(f), &encode_case_4_f, sizeof(encode_case_4_f)))
return 0;
return 1;
}
static const unsigned char encode_case_4_expect[] = {
0x04, /* Type */
0x52, 0x34, /* Stream ID */
0x80, 0x00, 0x97, 0x81, /* App Error Code */
0x80, 0x01, 0x17, 0x17, /* Final Size */
};
/* 5. STOP_SENDING */
static const OSSL_QUIC_FRAME_STOP_SENDING encode_case_5_f = {
0x1234, 0x9781
};
static int encode_case_5_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_stop_sending(pkt,
&encode_case_5_f), 1))
return 0;
return 1;
}
static int encode_case_5_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_STOP_SENDING f = {0};
if (!TEST_int_eq(ossl_quic_wire_decode_frame_stop_sending(pkt, &f), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_mem_eq(&f, sizeof(f), &encode_case_5_f, sizeof(encode_case_5_f)))
return 0;
return 1;
}
static const unsigned char encode_case_5_expect[] = {
0x05, /* Type */
0x52, 0x34, /* Stream ID */
0x80, 0x00, 0x97, 0x81 /* App Error Code */
};
/* 6. CRYPTO */
static const unsigned char encode_case_6_data[] = {
93, 18, 17, 102, 33
};
static const OSSL_QUIC_FRAME_CRYPTO encode_case_6_f = {
0x1234, sizeof(encode_case_6_data), encode_case_6_data
};
static int encode_case_6_enc(WPACKET *pkt)
{
if (!TEST_ptr(ossl_quic_wire_encode_frame_crypto(pkt,
&encode_case_6_f)))
return 0;
return 1;
}
static int encode_case_6_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_CRYPTO f = {0};
if (!TEST_int_eq(ossl_quic_wire_decode_frame_crypto(pkt, 0, &f), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(f.offset, 0x1234))
return 0;
if (!TEST_uint64_t_le(f.len, SIZE_MAX))
return 0;
if (!TEST_mem_eq(f.data, (size_t)f.len,
encode_case_6_data, sizeof(encode_case_6_data)))
return 0;
return 1;
}
static const unsigned char encode_case_6_expect[] = {
0x06, /* Type */
0x52, 0x34, /* Offset */
0x05, /* Length */
93, 18, 17, 102, 33 /* Data */
};
/* 7. NEW_TOKEN */
static const unsigned char encode_case_7_token[] = {
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71,
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
};
static int encode_case_7_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_new_token(pkt,
encode_case_7_token,
sizeof(encode_case_7_token)), 1))
return 0;
return 1;
}
static int encode_case_7_dec(PACKET *pkt, ossl_ssize_t fail)
{
const unsigned char *token = NULL;
size_t token_len = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_new_token(pkt,
&token,
&token_len), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_mem_eq(token, token_len,
encode_case_7_token, sizeof(encode_case_7_token)))
return 0;
return 1;
}
static const unsigned char encode_case_7_expect[] = {
0x07, /* Type */
0x10, /* Length */
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71, /* Token */
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
};
/* 8. STREAM (no length, no offset, no fin) */
static const unsigned char encode_case_8_data[] = {
0xde, 0x06, 0xcb, 0x76, 0x5d
};
static const OSSL_QUIC_FRAME_STREAM encode_case_8_f = {
0x1234, 0, 5, encode_case_8_data, 0, 0
};
static int encode_case_8_enc(WPACKET *pkt)
{
if (!TEST_ptr(ossl_quic_wire_encode_frame_stream(pkt,
&encode_case_8_f)))
return 0;
return 1;
}
static int encode_case_8_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_STREAM f = {0};
if (fail >= 3)
/*
* This case uses implicit length signalling so truncation will not
* cause it to fail unless the header (which is 3 bytes) is truncated.
*/
return 1;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_stream(pkt, 0, &f), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_le(f.len, SIZE_MAX))
return 0;
if (!TEST_mem_eq(f.data, (size_t)f.len,
encode_case_8_data, sizeof(encode_case_8_data)))
return 0;
if (!TEST_uint64_t_eq(f.stream_id, 0x1234))
return 0;
if (!TEST_uint64_t_eq(f.offset, 0))
return 0;
if (!TEST_int_eq(f.has_explicit_len, 0))
return 0;
if (!TEST_int_eq(f.is_fin, 0))
return 0;
return 1;
}
static const unsigned char encode_case_8_expect[] = {
0x08, /* Type (OFF=0, LEN=0, FIN=0) */
0x52, 0x34, /* Stream ID */
0xde, 0x06, 0xcb, 0x76, 0x5d /* Data */
};
/* 9. STREAM (length, offset, fin) */
static const unsigned char encode_case_9_data[] = {
0xde, 0x06, 0xcb, 0x76, 0x5d
};
static const OSSL_QUIC_FRAME_STREAM encode_case_9_f = {
0x1234, 0x39, 5, encode_case_9_data, 1, 1
};
static int encode_case_9_enc(WPACKET *pkt)
{
if (!TEST_ptr(ossl_quic_wire_encode_frame_stream(pkt,
&encode_case_9_f)))
return 0;
return 1;
}
static int encode_case_9_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_STREAM f = {0};
if (!TEST_int_eq(ossl_quic_wire_decode_frame_stream(pkt, 0, &f), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_le(f.len, SIZE_MAX))
return 0;
if (!TEST_mem_eq(f.data, (size_t)f.len,
encode_case_9_data, sizeof(encode_case_9_data)))
return 0;
if (!TEST_uint64_t_eq(f.stream_id, 0x1234))
return 0;
if (!TEST_uint64_t_eq(f.offset, 0x39))
return 0;
if (!TEST_int_eq(f.has_explicit_len, 1))
return 0;
if (!TEST_int_eq(f.is_fin, 1))
return 0;
return 1;
}
static const unsigned char encode_case_9_expect[] = {
0x0f, /* Type (OFF=1, LEN=1, FIN=1) */
0x52, 0x34, /* Stream ID */
0x39, /* Offset */
0x05, /* Length */
0xde, 0x06, 0xcb, 0x76, 0x5d /* Data */
};
/* 10. MAX_DATA */
static int encode_case_10_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_max_data(pkt, 0x1234), 1))
return 0;
return 1;
}
static int encode_case_10_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t max_data = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_max_data(pkt, &max_data), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(max_data, 0x1234))
return 0;
return 1;
}
static const unsigned char encode_case_10_expect[] = {
0x10, /* Type */
0x52, 0x34, /* Max Data */
};
/* 11. MAX_STREAM_DATA */
static int encode_case_11_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_max_stream_data(pkt,
0x1234,
0x9781), 1))
return 0;
return 1;
}
static int encode_case_11_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t stream_id = 0, max_data = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_max_stream_data(pkt,
&stream_id,
&max_data), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(stream_id, 0x1234))
return 0;
if (!TEST_uint64_t_eq(max_data, 0x9781))
return 0;
return 1;
}
static const unsigned char encode_case_11_expect[] = {
0x11, /* Type */
0x52, 0x34, /* Stream ID */
0x80, 0x00, 0x97, 0x81, /* Max Data */
};
/* 12. MAX_STREAMS */
static int encode_case_12_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_max_streams(pkt, 0, 0x1234), 1))
return 0;
if (!TEST_int_eq(ossl_quic_wire_encode_frame_max_streams(pkt, 1, 0x9781), 1))
return 0;
return 1;
}
static int encode_case_12_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t max_streams_1 = 0, max_streams_2 = 0,
frame_type_1 = 0, frame_type_2 = 0;
int is_minimal = 1, success_if;
success_if = (fail < 0 || fail >= 1);
if (!TEST_int_eq(ossl_quic_wire_peek_frame_header(pkt, &frame_type_1,
&is_minimal),
success_if))
return 0;
if (!TEST_true(!success_if || is_minimal))
return 0;
success_if = (fail < 0 || fail >= 3);
if (!TEST_int_eq(ossl_quic_wire_decode_frame_max_streams(pkt,
&max_streams_1),
success_if))
return 0;
success_if = (fail < 0 || fail >= 4);
if (!TEST_int_eq(ossl_quic_wire_peek_frame_header(pkt, &frame_type_2,
&is_minimal),
success_if))
return 0;
if (!TEST_true(!success_if || is_minimal))
return 0;
success_if = (fail < 0);
if (!TEST_int_eq(ossl_quic_wire_decode_frame_max_streams(pkt,
&max_streams_2),
success_if))
return 0;
if ((fail < 0 || fail >= 3)
&& !TEST_uint64_t_eq(frame_type_1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI))
return 0;
if ((fail < 0 || fail >= 3)
&& !TEST_uint64_t_eq(max_streams_1, 0x1234))
return 0;
if ((fail < 0 || fail >= 8)
&& !TEST_uint64_t_eq(frame_type_2, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI))
return 0;
if ((fail < 0 || fail >= 8)
&& !TEST_uint64_t_eq(max_streams_2, 0x9781))
return 0;
return 1;
}
static const unsigned char encode_case_12_expect[] = {
0x12, /* Type (MAX_STREAMS Bidirectional) */
0x52, 0x34, /* Max Streams */
0x13, /* Type (MAX_STREAMS Unidirectional) */
0x80, 0x00, 0x97, 0x81, /* Max Streams */
};
/* 13. DATA_BLOCKED */
static int encode_case_13_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_data_blocked(pkt, 0x1234), 1))
return 0;
return 1;
}
static int encode_case_13_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t max_data = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_data_blocked(pkt,
&max_data), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(max_data, 0x1234))
return 0;
return 1;
}
static const unsigned char encode_case_13_expect[] = {
0x14, /* Type */
0x52, 0x34, /* Max Data */
};
/* 14. STREAM_DATA_BLOCKED */
static int encode_case_14_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_stream_data_blocked(pkt,
0x1234,
0x9781), 1))
return 0;
return 1;
}
static int encode_case_14_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t stream_id = 0, max_data = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_stream_data_blocked(pkt,
&stream_id,
&max_data), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(stream_id, 0x1234))
return 0;
if (!TEST_uint64_t_eq(max_data, 0x9781))
return 0;
return 1;
}
static const unsigned char encode_case_14_expect[] = {
0x15, /* Type */
0x52, 0x34, /* Stream ID */
0x80, 0x00, 0x97, 0x81, /* Max Data */
};
/* 15. STREAMS_BLOCKED */
static int encode_case_15_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_streams_blocked(pkt, 0, 0x1234), 1))
return 0;
if (!TEST_int_eq(ossl_quic_wire_encode_frame_streams_blocked(pkt, 1, 0x9781), 1))
return 0;
return 1;
}
static int encode_case_15_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t max_streams_1 = 0, max_streams_2 = 0,
frame_type_1 = 0, frame_type_2 = 0;
int is_minimal = 1, success_if;
success_if = (fail < 0 || fail >= 1);
if (!TEST_int_eq(ossl_quic_wire_peek_frame_header(pkt, &frame_type_1,
&is_minimal),
success_if))
return 0;
if (!TEST_true(!success_if || is_minimal))
return 0;
success_if = (fail < 0 || fail >= 3);
if (!TEST_int_eq(ossl_quic_wire_decode_frame_streams_blocked(pkt,
&max_streams_1),
success_if))
return 0;
success_if = (fail < 0 || fail >= 4);
if (!TEST_int_eq(ossl_quic_wire_peek_frame_header(pkt, &frame_type_2,
&is_minimal),
success_if))
return 0;
if (!TEST_true(!success_if || is_minimal))
return 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_streams_blocked(pkt,
&max_streams_2),
fail < 0 || fail >= 8))
return 0;
if ((fail < 0 || fail >= 1)
&& !TEST_uint64_t_eq(frame_type_1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI))
return 0;
if ((fail < 0 || fail >= 3)
&& !TEST_uint64_t_eq(max_streams_1, 0x1234))
return 0;
if ((fail < 0 || fail >= 4)
&& !TEST_uint64_t_eq(frame_type_2, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI))
return 0;
if ((fail < 0 || fail >= 8)
&& !TEST_uint64_t_eq(max_streams_2, 0x9781))
return 0;
return 1;
}
static const unsigned char encode_case_15_expect[] = {
0x16, /* Type (STREAMS_BLOCKED Bidirectional) */
0x52, 0x34, /* Max Streams */
0x17, /* Type (STREAMS_BLOCKED Unidirectional) */
0x80, 0x00, 0x97, 0x81, /* Max Streams */
};
/* 16. NEW_CONNECTION_ID */
static const unsigned char encode_case_16_conn_id[] = {
0x33, 0x44, 0x55, 0x66
};
static const OSSL_QUIC_FRAME_NEW_CONN_ID encode_case_16_f = {
0x9781,
0x1234,
{
0x4,
{0x33, 0x44, 0x55, 0x66}
},
{
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71,
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
}
};
static int encode_case_16_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_new_conn_id(pkt,
&encode_case_16_f), 1))
return 0;
return 1;
}
static int encode_case_16_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_NEW_CONN_ID f = {0};
if (!TEST_int_eq(ossl_quic_wire_decode_frame_new_conn_id(pkt, &f), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(f.seq_num, 0x9781))
return 0;
if (!TEST_uint64_t_eq(f.retire_prior_to, 0x1234))
return 0;
if (!TEST_uint64_t_eq(f.conn_id.id_len, sizeof(encode_case_16_conn_id)))
return 0;
if (!TEST_mem_eq(f.conn_id.id, f.conn_id.id_len,
encode_case_16_conn_id, sizeof(encode_case_16_conn_id)))
return 0;
if (!TEST_mem_eq(f.stateless_reset_token,
sizeof(f.stateless_reset_token),
encode_case_16_f.stateless_reset_token,
sizeof(encode_case_16_f.stateless_reset_token)))
return 0;
return 1;
}
static const unsigned char encode_case_16_expect[] = {
0x18, /* Type */
0x80, 0x00, 0x97, 0x81, /* Sequence Number */
0x52, 0x34, /* Retire Prior To */
0x04, /* Connection ID Length */
0x33, 0x44, 0x55, 0x66, /* Connection ID */
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71, /* Stateless Reset Token */
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
};
/* 16b. NEW_CONNECTION_ID seq_num < retire_prior_to */
static const OSSL_QUIC_FRAME_NEW_CONN_ID encode_case_16b_f = {
0x1234,
0x9781,
{
0x4,
{0x33, 0x44, 0x55, 0x66}
},
{
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71,
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
}
};
static int encode_case_16b_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_new_conn_id(pkt,
&encode_case_16b_f), 1))
return 0;
return 1;
}
static int encode_case_16b_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_NEW_CONN_ID f = {0};
if (!TEST_int_eq(ossl_quic_wire_decode_frame_new_conn_id(pkt, &f), 0))
return 0;
if (!TEST_true(PACKET_forward(pkt, PACKET_remaining(pkt))))
return 0;
return 1;
}
static const unsigned char encode_case_16b_expect[] = {
0x18, /* Type */
0x52, 0x34, /* Sequence Number */
0x80, 0x00, 0x97, 0x81, /* Retire Prior To */
0x04, /* Connection ID Length */
0x33, 0x44, 0x55, 0x66, /* Connection ID */
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71, /* Stateless Reset Token */
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
};
/* 17. RETIRE_CONNECTION_ID */
static int encode_case_17_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_retire_conn_id(pkt, 0x1234), 1))
return 0;
return 1;
}
static int encode_case_17_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t seq_num = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_retire_conn_id(pkt, &seq_num), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(seq_num, 0x1234))
return 0;
return 1;
}
static const unsigned char encode_case_17_expect[] = {
0x19, /* Type */
0x52, 0x34, /* Seq Num */
};
/* 18. PATH_CHALLENGE */
static const uint64_t encode_case_18_data
= (((uint64_t)0x5f4b12)<<40) | (uint64_t)0x731834UL;
static int encode_case_18_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_path_challenge(pkt,
encode_case_18_data), 1))
return 0;
return 1;
}
static int encode_case_18_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t challenge = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_path_challenge(pkt, &challenge), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(challenge, encode_case_18_data))
return 0;
return 1;
}
static const unsigned char encode_case_18_expect[] = {
0x1A, /* Type */
0x5f, 0x4b, 0x12, 0x00, 0x00, 0x73, 0x18, 0x34, /* Data */
};
/* 19. PATH_RESPONSE */
static const uint64_t encode_case_19_data
= (((uint64_t)0x5f4b12)<<40) | (uint64_t)0x731834UL;
static int encode_case_19_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_path_response(pkt,
encode_case_19_data), 1))
return 0;
return 1;
}
static int encode_case_19_dec(PACKET *pkt, ossl_ssize_t fail)
{
uint64_t challenge = 0;
if (!TEST_int_eq(ossl_quic_wire_decode_frame_path_response(pkt, &challenge), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_uint64_t_eq(challenge, encode_case_19_data))
return 0;
return 1;
}
static const unsigned char encode_case_19_expect[] = {
0x1B, /* Type */
0x5f, 0x4b, 0x12, 0x00, 0x00, 0x73, 0x18, 0x34, /* Data */
};
/* 20. CONNECTION_CLOSE (transport) */
static const char encode_case_20_reason[] = {
/* "reason for closure" */
0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x20, 0x66, 0x6f,
0x72, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x75, 0x72, 0x65
};
static const OSSL_QUIC_FRAME_CONN_CLOSE encode_case_20_f = {
0,
0x1234,
0x9781,
(char *)encode_case_20_reason,
sizeof(encode_case_20_reason)
};
static int encode_case_20_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_conn_close(pkt,
&encode_case_20_f), 1))
return 0;
return 1;
}
static int encode_case_20_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_CONN_CLOSE f = {0};
if (!TEST_int_eq(ossl_quic_wire_decode_frame_conn_close(pkt, &f), fail < 0))
return 0;
if (fail >= 0)
return 1;
if (!TEST_int_eq(f.is_app, 0))
return 0;
if (!TEST_uint64_t_eq(f.error_code, 0x1234))
return 0;
if (!TEST_uint64_t_eq(f.frame_type, 0x9781))
return 0;
if (!TEST_size_t_eq(f.reason_len, 18))
return 0;
if (!TEST_mem_eq(f.reason, f.reason_len,
encode_case_20_f.reason, encode_case_20_f.reason_len))
return 0;
return 1;
}